Class: Intercom::ClientCollectionProxy

Inherits:
BaseCollectionProxy show all
Defined in:
lib/intercom/client_collection_proxy.rb

Instance Attribute Summary

Attributes inherited from BaseCollectionProxy

#resource_class, #resource_name, #url

Instance Method Summary collapse

Methods inherited from BaseCollectionProxy

#[], #initialize

Constructor Details

This class inherits a constructor from Intercom::BaseCollectionProxy

Instance Method Details

#each(&block) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/intercom/client_collection_proxy.rb', line 8

def each(&block)
  next_page = nil
  current_page = nil
  loop do
    response_hash = fetch(next_page)
    raise Intercom::HttpError, 'Http Error - No response entity returned' unless response_hash

    current_page = extract_current_page(response_hash)
    deserialize_response_hash(response_hash, block)
    next_page = extract_next_link(response_hash)
    break if next_page.nil? || (@params[:page] && (current_page >= @params[:page]))
  end
  self
end

#fetch(next_page) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/intercom/client_collection_proxy.rb', line 23

def fetch(next_page)
  if next_page
    @client.get(next_page, {})
  else
    @client.get(@url, @params)
  end
end