| Module | Pastis |
| In: |
lib/pastis/collection.rb
lib/pastis/paste.rb lib/pastis.rb |
Pastis is a simple ruby interface to Pastie (pastie.caboo.se)
paste = Pastis.paste "var some = 'private js code';", :language => :javascript, :private => true paste.url # => "http://pastie.caboo.se/private/lbejcc0royyyyozwl8jbg" paste.raw_url # => "http://pastie.caboo.se/private/lbejcc0royyyyozwl8jbg.txt" paste.body # => "var some = 'private js code';" pages = Pastis.search [a search expression] pages.next_page.last.url # => "http://pastie.caboo.se/pastes/43577"
| Version | = | [ 0, 1, 0 ].freeze unless defined?(Version) |
| create | -> | paste |
| list | -> | all |
Creates a paste, returns the created Paste object. The options are :
# File lib/pastis.rb, line 57 def create(body, options = {}) raise EmptyPasteError, "Empty paste, not submitted..." unless body =~ /\w/ response = post_paste(body, options); raise PasteNotCreatedError, "Error occured : #{response.code}" unless response.code =~ /[23]0\d/ raise PasteNotCreatedError, "Paste not created" unless response['location'] return Paste.new(:body => body, :url => response['location'], :time => Time.now) end
Lists all pastes. Returns a Collection object
# File lib/pastis.rb, line 79 def list(page = 1) Collection.new(page) do |page| all_url(page) end end
Searches some expression on Pastie. Returns a Collection object
# File lib/pastis.rb, line 71 def search(expression, page = 1) Collection.new(page) do |page| search_url(expression, page) end end