Class: Grouper::Rest::Client::Resource::Group
- Inherits:
-
Object
- Object
- Grouper::Rest::Client::Resource::Group
- Defined in:
- lib/grouper-rest-client/resource.rb
Overview
TODO DRY w/ “Subject” + “Stem”
Instance Method Summary collapse
-
#[](key) ⇒ Object
Return attribute value for
key
or nil. -
#initialize(resource, json) ⇒ Group
constructor
A new instance of Group.
-
#members ⇒ Object
Get member(s) of group.
- #to_s ⇒ Object
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 |
#members ⇒ Object
Get member(s) of group. Returns list of Grouper::Rest::Client::Resource::Subject objects OR JSON error response.
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_s ⇒ Object
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 |