Class: Intercom::SearchCollectionProxy

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/intercom/search_collection_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_name, search_details: {}, client:) ⇒ SearchCollectionProxy

Returns a new instance of SearchCollectionProxy.



8
9
10
11
12
13
14
# File 'lib/intercom/search_collection_proxy.rb', line 8

def initialize(resource_name, search_details: {}, client:)
  @resource_name = resource_name
  @resource_class = Utils.constantize_resource_name(resource_name)
  @search_url = search_details[:url]
  @search_params = search_details[:params]
  @client = client
end

Instance Attribute Details

#resource_classObject (readonly)

Returns the value of attribute resource_class.



6
7
8
# File 'lib/intercom/search_collection_proxy.rb', line 6

def resource_class
  @resource_class
end

#resource_nameObject (readonly)

Returns the value of attribute resource_name.



6
7
8
# File 'lib/intercom/search_collection_proxy.rb', line 6

def resource_name
  @resource_name
end

Instance Method Details

#[](target_index) ⇒ Object



26
27
28
29
30
31
# File 'lib/intercom/search_collection_proxy.rb', line 26

def [](target_index)
  self.each_with_index do |item, index|
    return item if index == target_index
  end
  nil
end

#each(&block) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/intercom/search_collection_proxy.rb', line 16

def each(&block)
  loop do
    response_hash = @client.post(@search_url, payload)
    raise Intercom::HttpError.new('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