Module: Pastis

Defined in:
lib/pastis.rb,
lib/pastis/paste.rb,
lib/pastis/collection.rb

Overview

Pastis is a simple ruby interface to Pastie (pastie.caboo.se)

Usage

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"

Defined Under Namespace

Classes: Collection, EmptyPasteError, Error, PaginationError, Paste, PasteNotCreatedError

Constant Summary collapse

Version =
[ 0, 1, 0 ].freeze

Class Method Summary collapse

Class Method Details

.create(body, options = {}) ⇒ Object Also known as: paste

Creates a paste, returns the created Paste object. The options are :

  • :language: The language used in the paste (defaults to Ruby)

  • :private: true if the paste is private (default to false)

Raises:



57
58
59
60
61
62
63
64
65
66
# 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

.list(page = 1) ⇒ Object Also known as: all

Lists all pastes. Returns a Collection object



79
80
81
82
83
# File 'lib/pastis.rb', line 79

def list(page = 1)
  Collection.new(page) do |page|
    all_url(page)
  end
end

.search(expression, page = 1) ⇒ Object

Searches some expression on Pastie. Returns a Collection object



71
72
73
74
75
# File 'lib/pastis.rb', line 71

def search(expression, page = 1)
  Collection.new(page) do |page|
    search_url(expression, page)
  end
end

.urlObject

:nodoc:



48
49
50
# File 'lib/pastis.rb', line 48

def url #:nodoc:
  "http://pastie.caboo.se"
end