Class: Intercom::SearchCollectionProxy
- Inherits:
-
Object
- Object
- Intercom::SearchCollectionProxy
- Includes:
- Enumerable
- Defined in:
- lib/intercom/search_collection_proxy.rb
Instance Attribute Summary collapse
-
#resource_class ⇒ Object
readonly
Returns the value of attribute resource_class.
-
#resource_name ⇒ Object
readonly
Returns the value of attribute resource_name.
Instance Method Summary collapse
- #[](target_index) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(resource_name, search_details: {}, client:) ⇒ SearchCollectionProxy
constructor
A new instance of SearchCollectionProxy.
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_class ⇒ Object (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_name ⇒ Object (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 |