Module: RPaste::PasteBin

Defined in:
lib/rpaste/pastebin/paste.rb,
lib/rpaste/pastebin/recent.rb,
lib/rpaste/pastebin/metadata.rb,
lib/rpaste/pastebin/pastebin.rb

Defined Under Namespace

Classes: Metadata, Paste, Recent

Constant Summary collapse

POST_URL =

The PasteBin post URL

'http://pastebin.com/pastebin.php'

Class Method Summary collapse

Class Method Details

.post(options = {}, &block) ⇒ Object

Submits a new paste to PasteBin with the given options. If a block is given, then it will be passed the Paste object before it is submitted to PasteBin.

options may contain the following keys:

:author

The author of the paste.

:syntax

The syntax of the paste.

:retained

Indicates when the paste should expire, which can be either :day, :month or :year.

:text

The text to paste.

PasteBin.post(:author => 'xyz') do |paste|
  paste.description = 'test'
  paste.text = %{
    <?xml version="1.0" ?>
    <test>
      <x>1</x>
      <y>0</y>
    </test>
  }
end


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/rpaste/pastebin/pastebin.rb', line 43

def PasteBin.post(options={},&block)
  author = options[:author]
  syntax = options[:syntax]
  retained = options[:retained]
  text = options[:text]

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

  agent = RPaste.web_agent
  page = agent.get(POST_URL)
  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

.recent(options = {}, &block) ⇒ Object

Returns the list of all recent pastes on PasteBin. See Recent.get.



15
16
17
# File 'lib/rpaste/pastebin/pastebin.rb', line 15

def PasteBin.recent(options={},&block)
  Recent.get(options,&block)
end