lib/intercom/scroll_collection_proxy.rb in intercom-4.1.1 vs lib/intercom/scroll_collection_proxy.rb in intercom-4.1.2

- old
+ new

@@ -24,11 +24,11 @@ @client.get(@scroll_url, scroll_param: scroll_parameter) end raise Intercom::HttpError, 'Http Error - No response entity returned' unless response_hash @scroll_param = extract_scroll_param(response_hash) - top_level_entity_key = deserialize_response_hash(response_hash) + top_level_entity_key = entity_key_from_response(response_hash) response_hash[top_level_entity_key] = response_hash[top_level_entity_key].map do |object_json| Lib::TypedJsonDeserializer.new(object_json, @client).deserialize end @records = response_hash[@resource_name] self @@ -42,31 +42,32 @@ else @client.get(@scroll_url, scroll_param: scroll_param) end raise Intercom::HttpError, 'Http Error - No response entity returned' unless response_hash - response_hash[deserialize_response_hash(response_hash)].each do |object_json| + top_level_entity_key = entity_key_from_response(response_hash) + response_hash[top_level_entity_key].each do |object_json| block.call Lib::TypedJsonDeserializer.new(object_json, @client).deserialize end scroll_param = extract_scroll_param(response_hash) break unless records_present?(response_hash) end self end private - def deserialize_response_hash(response_hash) - top_level_type = response_hash.delete('type') + def entity_key_from_response(response_hash) + top_level_type = response_hash['type'] if resource_name == 'subscriptions' 'items' else Utils.entity_key_from_type(top_level_type) end end def records_present?(response_hash) - !response_hash[@resource_name].empty? + !response_hash[entity_key_from_response(response_hash)].empty? end def extract_scroll_param(response_hash) return nil unless records_present?(response_hash)