Class: Grouper::Rest::Client::Resource::Subject

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

Overview

TODO DRY w/ “Group” + “Stem”

Instance Method Summary collapse

Constructor Details

#initialize(resource, json) ⇒ Subject

Returns a new instance of Subject.



201
202
203
204
# File 'lib/grouper-rest-client/resource.rb', line 201

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

Instance Method Details

#[](key) ⇒ Object

Return attribute value for key or nil.



207
208
209
210
# File 'lib/grouper-rest-client/resource.rb', line 207

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

#groups(stem_filter = nil) ⇒ Object

Get memberships for this subject. Returns list of hashes of group memberships OR JSON error response. Params:

stem_filter

Limit groups to those within this stem prefix. (optional)



216
217
218
219
220
221
222
223
224
225
# File 'lib/grouper-rest-client/resource.rb', line 216

def groups(stem_filter=nil)
  k1, k2 = 'WsGetGroupsLiteResult', 'wsGroups'
  result  = @resource.call("subjects/#{ @json['id'] }/groups")
  if result.key?(k1) && result[k1].key?(k2)
    groups  = result[k1][k2]
    groups  = groups.select { |group| group['name'] =~ /^#{stem_filter}/ } if stem_filter
    return groups.collect { |g| Grouper::Rest::Client::Resource::Group.new(@resource, g) }
  end
  return result
end

#to_sObject



227
228
229
230
# File 'lib/grouper-rest-client/resource.rb', line 227

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