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)

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"

Methods

create   list   search  

Classes and Modules

Class Pastis::Collection
Class Pastis::EmptyPasteError
Class Pastis::Error
Class Pastis::PaginationError
Class Pastis::Paste
Class Pastis::PasteNotCreatedError

Constants

Version = [ 0, 1, 0 ].freeze unless defined?(Version)

External Aliases

create -> paste
list -> all

Public Class methods

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)

[Source]

# 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

[Source]

# 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

[Source]

# File lib/pastis.rb, line 71
    def search(expression, page = 1)
      Collection.new(page) do |page|
        search_url(expression, page)
      end
    end

[Validate]