Class: SnipplrEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/model/snipplr_entry.rb

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ SnipplrEntry

Returns a new instance of SnipplrEntry.

Raises:

  • (Exception)


8
9
10
11
# File 'lib/model/snipplr_entry.rb', line 8

def initialize(key)
  raise Exception.new('nil isn\'t a legal key value!') if !key
  @key=key
end

Instance Method Details

#delete(id) ⇒ Object



27
28
29
30
31
# File 'lib/model/snipplr_entry.rb', line 27

def delete(id)
  Server.open_session(@key) do |server|
    server.call("snippet.delete", @key, id)
  end
end

#find_all_entriesObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/model/snipplr_entry.rb', line 33

def find_all_entries
  entries=[]
  Server.open_session(@key) do |server|
    hashes = server.call("snippet.list", @key)
    hashes.each do |row| 
      row[:eid]=row['id']# we must use eid since id collides with Object.id
      entries << OpenStruct.new(row) 
    end
  end
  return entries
end

#get_content(id) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/model/snipplr_entry.rb', line 13

def get_content(id)
  Server.open_session(@key) do |server|
    entry=OpenStruct.new(server.call("snippet.get", id))
    entry.source=CGI::unescapeHTML(entry.source)
    return entry
  end    
end

#post_entry(info) ⇒ Object



21
22
23
24
25
# File 'lib/model/snipplr_entry.rb', line 21

def post_entry(info)
  Server.open_session(@key) do |server|
    server.call("snippet.post", @key, info[:title], info[:content], info[:tags],info[:language])
  end
end