Sha256: 60b046b37b08d53b8106663d37b14097b94e7b21505f3c2a59049e8ff3bd4f5c

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require 'rpaste/pastebin/recent'
require 'rpaste/pastebin/paste'
require 'rpaste/rpaste'

require 'hpricot'

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

    #
    # Submits a new paste to PasteBin. If a _block_ is given, then it will be
    # passed the Paste object before it is submitted to PasteBin.
    #
    #   PasteBin.post(:author => 'xyz') do |paste|
    #     paste.description = 'test'
    #     paste.text = %{
    #       <?xml version="1.0" ?>
    #       <test>
    #         <x>1</x>
    #         <y>0</y>
    #       </test>
    #     }
    #   end
    #
    def PasteBin.post(opts={},&block)
      paste = Paste.new(opts,&block)

      agent = RPaste.http_agent(opts)
      page = agent.get('http://pastebin.com/pastebin.php')
      form = page.forms.first

      form.format = paste.syntax if paste.syntax
      form.code2 = paste.text
      form.poster = paste.author if paste.author

      case paste.retained
      when :day then
        form.expire = 'd'
      when :month
        form.expire = 'm'
      when :forever
        form.expire = 'f'
      end

      agent.submit(form)
      return true
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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