Class: Grendel::LinkManager

Inherits:
Object
  • Object
show all
Defined in:
lib/grendel/link_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ LinkManager

Returns a new instance of LinkManager.



4
5
6
7
# File 'lib/grendel/link_manager.rb', line 4

def initialize(document)
   @document = document
   @base_uri = @document.uri + "/links"
end

Instance Method Details

#add(user_id) ⇒ Object

add a link to a user and return a Link object



18
19
20
21
22
# File 'lib/grendel/link_manager.rb', line 18

def add(user_id)
  # REVIEW: 2010-02-23 <[email protected]> -- what does Grendel return if the link already exists?
  @document.user.put(@base_uri + "/" + user_id)
  Link.new(@document, User.new(@document.user.client, :id => user_id))
end

#listObject

return links to this document



10
11
12
13
14
15
# File 'lib/grendel/link_manager.rb', line 10

def list
  response = @document.user.get(@base_uri)
  response["links"].map do |link| 
    Link.new(@document, User.new(@document.user.client, link["user"]), :uri => link["uri"])
  end
end

#remove(user_id) ⇒ Object

remove a link to a user



25
26
27
28
# File 'lib/grendel/link_manager.rb', line 25

def remove(user_id)
  # REVIEW: 2010-02-23 <[email protected]> -- what does Grendel return if the link didn't exist?
  @document.user.delete(@base_uri + "/" + user_id)
end