Class: GlipSdk::REST::Groups

Inherits:
Object
  • Object
show all
Defined in:
lib/glip_sdk/rest/groups.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rc_sdk) ⇒ Groups

Returns a new instance of Groups.



7
8
9
# File 'lib/glip_sdk/rest/groups.rb', line 7

def initialize(rc_sdk)
  @api = rc_sdk
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



4
5
6
# File 'lib/glip_sdk/rest/groups.rb', line 4

def cache
  @cache
end

#subscriptionObject

Returns the value of attribute subscription.



5
6
7
# File 'lib/glip_sdk/rest/groups.rb', line 5

def subscription
  @subscription
end

Instance Method Details

#all_groups(params = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/glip_sdk/rest/groups.rb', line 24

def all_groups(params = {})
  groups = []
  get_next = true
  while get_next
    res = get params
    groups.concat(res.body['records']) if res.body['records'].length > 0

    if res.body.key?('navigation') && res.body['navigation'].key?('prevPageToken')
      params['pageToken'] = res.body['navigation']['prevPageToken']
      @api.config.logger.info "PrevPageToken [#{res.body['navigation']['prevPageToken']}]"
    else
      get_next = false
    end
  end
  groups
end

#get(opts = {}) ⇒ Object



11
12
13
14
15
16
# File 'lib/glip_sdk/rest/groups.rb', line 11

def get(opts = {})
  if opts.key? :groupId
    return @api.http.get "glip/groups/#{opts[:groupId]}"
  end
  @api.http.get 'glip/groups', opts
end

#observe(observer) ⇒ Object



18
19
20
21
22
# File 'lib/glip_sdk/rest/groups.rb', line 18

def observe(observer)
  @subscription = @api.create_subscription
  @subscription.subscribe ['/restapi/v1.0/account/~/extension/~/glip/groups']
  @subscription.add_observer observer
end