Module: Hinoki::Stashes

Defined in:
lib/hinoki/stashes.rb

Class Method Summary collapse

Class Method Details

.all(limit = nil, offset = nil) ⇒ Object

Lists all stashes



10
11
12
13
14
15
16
# File 'lib/hinoki/stashes.rb', line 10

def self.all(limit=nil, offset=nil)
  url = "/stashes"
  if limit  then url.append("?limit=#{limit}") end
  if offset then url.append("&offset=#{offset}") end
  
  return Hinoki.conn.get(url)
end

.by_name(stash) ⇒ Object

Get information about a specific stash



30
31
32
# File 'lib/hinoki/stashes.rb', line 30

def self.by_name(stash)
  return Hinoki.conn.get("/stashes/#{stash}")
end

.create(path, content, expiration = nil) ⇒ Object

Add a new stash (JSON formatted)



19
20
21
22
23
24
25
26
27
# File 'lib/hinoki/stashes.rb', line 19

def self.create(path, content, expiration=nil)
  hash = {path: path, content: content}
  if expiration then hash.merge!({expire: expiration.to_i}) end

  post = Net::HTTP::Post.new('/stashes')
  post.body=JSON.generate(hash)

  return Hinoki.conn.request(post)
end

.delete(stash) ⇒ Object

Remove a stash



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

def self.delete(stash)
  return Hinoki.conn.delete("/stashes/#{stash}")
end