Class: Refheap::Paste

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/rubyheap/rubyheap.rb

Instance Method Summary collapse

Constructor Details

#initialize(username = nil, token = nil) ⇒ Paste

Set some default_params based on the username and token (or lack thereof).



14
15
16
17
18
19
20
# File 'lib/rubyheap/rubyheap.rb', line 14

def initialize(username = nil, token = nil)
  if username && token
    @base_params = {:username => username, :token => token}
  else
    @base_params = {}
  end
end

Instance Method Details

#create(contents, params = {:language => "Plain Text", :private => false}) ⇒ Object

Create a new paste. If language isn’t provided, it defaults to “Plain Text”. If private isn’t provided, it defaults to false.



29
30
31
32
# File 'lib/rubyheap/rubyheap.rb', line 29

def create(contents, params = {:language => "Plain Text", :private => false})
  params = params.merge({:contents => contents}.merge(@base_params))
  self.class.post("/paste", :body => params).parsed_response
end

#delete(id) ⇒ Object

Delete a paste.



35
36
37
# File 'lib/rubyheap/rubyheap.rb', line 35

def delete(id)
  self.class.delete("/paste/#{id}", :query => @base_params).parsed_response.nil?
end

#edit(id, params = {}) ⇒ Object

Edit a paste. Optional params are any of:

  • :private

  • :language

  • :contents

All of these are optional. If any of them aren’t provided in the edit, they will remain the same.



45
46
47
# File 'lib/rubyheap/rubyheap.rb', line 45

def edit(id, params = {})
  self.class.post("/paste/#{id}", :body => params.merge(@base_params)).parsed_response
end

#fork(id) ⇒ Object

Fork a paste.



50
51
52
# File 'lib/rubyheap/rubyheap.rb', line 50

def fork(id)
  self.class.post("/paste/#{id}/fork", :body => @base_params).parsed_response
end

#get(id) ⇒ Object

Get a paste from RefHeap by ID.



23
24
25
# File 'lib/rubyheap/rubyheap.rb', line 23

def get(id)
  self.class.get("/paste/#{id}").parsed_response
end