class Intercom::BaseCollectionProxy
Attributes
resource_class[R]
resource_name[R]
url[R]
Public Class Methods
new(resource_name, resource_class, details: {}, client:, method: 'get')
click to toggle source
# File lib/intercom/base_collection_proxy.rb, line 9 def initialize(resource_name, resource_class, details: {}, client:, method: 'get') @resource_name = resource_name @resource_class = resource_class @url = (details[:url] || "/#{@resource_name}") @params = (details[:params] || {}) @client = client @method = method end
Public Instance Methods
[](target_index)
click to toggle source
# File lib/intercom/base_collection_proxy.rb, line 29 def [](target_index) each_with_index do |item, index| return item if index == target_index end nil end
each(&block)
click to toggle source
# File lib/intercom/base_collection_proxy.rb, line 18 def each(&block) loop do response_hash = @client.public_send(@method, @url, payload) raise Intercom::HttpError, 'Http Error - No response entity returned' unless response_hash deserialize_response_hash(response_hash, block) break unless has_next_link?(response_hash) end self end
Private Instance Methods
deserialize_response_hash(response_hash, block)
click to toggle source
# File lib/intercom/base_collection_proxy.rb, line 40 def deserialize_response_hash(response_hash, block) top_level_type = response_hash.delete('type') top_level_entity_key = if resource_name == 'subscriptions' 'items' else Utils.entity_key_from_type(top_level_type) end response_hash[top_level_entity_key].each do |object_json| if top_level_type == 'event.summary' block.call Lib::TypedJsonDeserializer.new(object_json, @client, top_level_type).deserialize else block.call Lib::TypedJsonDeserializer.new(object_json, @client).deserialize end end end
has_next_link?(response_hash)
click to toggle source
# File lib/intercom/base_collection_proxy.rb, line 56 def has_next_link?(response_hash) paging_info = response_hash.delete('pages') return false unless paging_info paging_next = paging_info['next'] if paging_next @params[:starting_after] = paging_next['starting_after'] return true else @params[:starting_after] = nil return false end end
payload()
click to toggle source
# File lib/intercom/base_collection_proxy.rb, line 70 def payload @params.keep_if { |k, v| !v.nil? }.to_h end