Sha256: 644574fe046f98c3ef65f8c77aa7edbe19a562c86b93188264e3fc515c77aa7b

Contents?: true

Size: 1.6 KB

Versions: 1

Compression:

Stored size: 1.6 KB

Contents

require 'rpaste/nopaste/recent'
require 'rpaste/nopaste/paste'
require 'rpaste/rpaste'

require 'hpricot'

module RPaste
  module NoPaste
    #
    # Returns the list of all recent pastes on NoPaste. See Recent.get.
    #
    def NoPaste.recent(opts={},&block)
      Recent.get(opts,&block)
    end

    #
    # Retrieves the NoPaste Paste object associated with the specified
    # _name_. See Paste.paste.
    #
    def NoPaste.paste(name,opts={})
      Paste.paste(name,opts)
    end

    #
    # Submits a new paste to NoPaste. If a _block_ is given, then it will be
    # passed the Paste object before it is submitted to NoPaste.
    #
    #   NoPaste.post(:author => 'briefcase man') do |paste|
    #     paste.description = 'todays key'
    #     paste.text = 'is brought to you by the letter S, for symmetric'
    #   end
    #
    def NoPaste.post(opts={},&block)
      author = opts[:author]
      syntax = opts[:syntax]
      description = opts[:description]
      text = opts[:text]

      paste = Paste.new(nil,author,nil,syntax,description,text,&block)

      agent = RPaste.http_agent(opts)
      page = agent.get('http://rafb.net/paste/index.html')
      form = page.forms.first

      form.lang = paste.syntax if paste.syntax
      form.nick = paste.author if paste.author
      form.desc = paste.description if paste.description

      if opts[:convert_tabs]
        form.cvt_tabs = opts[:convert_tabs]
      end

      form.text = paste.text
      page = agent.submit(form)

      paste.name = page.search('//tr[3]/td/small').inner_text.gsub(/^URL: .*\//,'').gsub(/\.html$/,'')
      return paste
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rpaste-0.0.9 lib/rpaste/nopaste/nopaste.rb