Class: Crowd::Client::Group
- Inherits:
-
Object
- Object
- Crowd::Client::Group
- Defined in:
- lib/crowd-client/group.rb
Instance Attribute Summary collapse
-
#groupname ⇒ Object
Returns the value of attribute groupname.
Instance Method Summary collapse
- #add_user(user) ⇒ Object
-
#initialize(groupname) ⇒ Group
constructor
A new instance of Group.
- #remove_user(user) ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(groupname) ⇒ Group
Returns a new instance of Group.
6 7 8 |
# File 'lib/crowd-client/group.rb', line 6 def initialize(groupname) self.groupname = groupname end |
Instance Attribute Details
#groupname ⇒ Object
Returns the value of attribute groupname.
4 5 6 |
# File 'lib/crowd-client/group.rb', line 4 def groupname @groupname end |
Instance Method Details
#add_user(user) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/crowd-client/group.rb', line 20 def add_user(user) response = connection.post('group/user/direct', :name => user.username) do |request| request.params[:groupname] = groupname end raise ::Crowd::Client::Exception::NotFound.new("Group '#{groupname}' was not found") if response.status == 404 raise ::Crowd::Client::Exception::NotFound.new("User '#{user.username}' was not found") if response.status == 400 raise ::Crowd::Client::Exception::UnknownError.new(response.body.to_s) if response.status != 201 end |
#remove_user(user) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/crowd-client/group.rb', line 29 def remove_user(user) response = connection.delete("group/user/direct") do |request| request.params[:groupname] = groupname request.params[:username] = user.username end raise ::Crowd::Client::Exception::NotFound.new("User '#{user.username}' was not found") if response.status == 404 raise ::Crowd::Client::Exception::UnknownError.new(response.body.to_s) if response.status != 204 end |
#users ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/crowd-client/group.rb', line 10 def users response = connection.get('group/user/nested') do |request| request.params[:groupname] = groupname end raise ::Crowd::Client::Exception::NotFound.new("Group '#{groupname}' was not found") if response.status == 404 response.body['users'].collect do |user| ::Crowd::Client::User.new(user['name']) end end |