Class: Grendel::UserManager

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ UserManager

Returns a new instance of UserManager.



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

def initialize(client)
  @client = client
end

Instance Method Details

#create(id, password) ⇒ Object

create a new user



23
24
25
26
27
28
# File 'lib/grendel/user_manager.rb', line 23

def create(id, password)
  params = {:id => id, :password => password}
  response = @client.post("/users", params)
  # TODO: strip protocol and host from uri
  User.new(@client, params.merge(:uri => response.headers['location'].first))
end

#find(id, password = nil) ⇒ Object

retrieve a user, optionally setting the password



15
16
17
18
19
20
# File 'lib/grendel/user_manager.rb', line 15

def find(id, password = nil)
  response = @client.get("/users/#{id}") # need to escape this
  user = User.new(@client, response)
  user.password = password
  return user
end

#listObject

return all Grendel users as Grendel::User objects



9
10
11
12
# File 'lib/grendel/user_manager.rb', line 9

def list
  response = @client.get("/users")
  response["users"].map {|u| User.new(@client, u) }
end