Class: Grouper::Rest::Client::Resource::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/grouper-rest-client/resource.rb

Overview

TODO DRY w/ “Subject” + “Stem”

Instance Method Summary collapse

Constructor Details

#initialize(resource, json) ⇒ Group

Returns a new instance of Group.



145
146
147
148
# File 'lib/grouper-rest-client/resource.rb', line 145

def initialize(resource, json)
  @resource = resource
  @json     = json
end

Instance Method Details

#[](key) ⇒ Object

Return attribute value for key or nil.



151
152
153
154
# File 'lib/grouper-rest-client/resource.rb', line 151

def [](key)
  return @json[key] if @json && @json.key?(key)
  return nil
end

#membersObject

Get member(s) of group. Returns list of Grouper::Rest::Client::Resource::Subject objects OR JSON error response.

Raises:

  • (ArgumentError)


158
159
160
161
162
163
164
165
166
# File 'lib/grouper-rest-client/resource.rb', line 158

def members
  raise ArgumentError if self['name'].nil? || self['name'].empty?
  k1, k2  = 'WsGetMembersLiteResult', 'wsSubjects'
  result  = @resource.call("groups/#{ URI.escape( self['name'].rstrip ) }/members") # TODO Seems like a hack
  if result.key?(k1) && result[k1].key?(k2)
    return result[k1][k2].collect { |m| Grouper::Rest::Client::Resource::Subject.new(@source, m) }
  end
  return []
end

#to_sObject



168
169
170
171
# File 'lib/grouper-rest-client/resource.rb', line 168

def to_s
  return "#{ self.class.name}: #{ @json.keys.sort.collect { |k| "#{ k }=#{ @json[k] }" }.join(', ') }" if @json
  super
end