Sha256: d716116b9a326df1dc0b9ff371e89e281e2b9e7b9aa253b2d936e6b23e70f875

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

module GlipSdk
  module REST
    class Groups
      attr_accessor :cache
      attr_accessor :subscription

      def initialize(rc_sdk)
        @api = rc_sdk
      end

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

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

      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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
glip_sdk-0.0.5 lib/glip_sdk/rest/groups.rb
glip_sdk-0.0.4 lib/glip_sdk/rest/groups.rb