Class: Intercom::ClientCollectionProxy
- Inherits:
-
Object
- Object
- Intercom::ClientCollectionProxy
- Includes:
- Enumerable
- Defined in:
- lib/intercom/client_collection_proxy.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#finder_url ⇒ Object
readonly
Returns the value of attribute finder_url.
-
#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, finder_details: {}, client:) ⇒ ClientCollectionProxy
constructor
A new instance of ClientCollectionProxy.
Constructor Details
#initialize(resource_name, finder_details: {}, client:) ⇒ ClientCollectionProxy
Returns a new instance of ClientCollectionProxy.
8 9 10 11 12 13 14 |
# File 'lib/intercom/client_collection_proxy.rb', line 8 def initialize(resource_name, finder_details: {}, client:) @resource_name = resource_name @resource_class = Utils.constantize_resource_name(resource_name) @finder_url = (finder_details[:url] || "/#{@resource_name}") @finder_params = (finder_details[:params] || {}) @client = client end |
Instance Attribute Details
#finder_url ⇒ Object (readonly)
Returns the value of attribute finder_url.
6 7 8 |
# File 'lib/intercom/client_collection_proxy.rb', line 6 def finder_url @finder_url end |
#resource_class ⇒ Object (readonly)
Returns the value of attribute resource_class.
6 7 8 |
# File 'lib/intercom/client_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/client_collection_proxy.rb', line 6 def resource_name @resource_name end |
Instance Method Details
#[](target_index) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/intercom/client_collection_proxy.rb', line 34 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 25 26 27 28 29 30 31 32 |
# File 'lib/intercom/client_collection_proxy.rb', line 16 def each(&block) next_page = nil current_page = nil loop do if next_page response_hash = @client.get(next_page, {}) else response_hash = @client.get(@finder_url, @finder_params) end raise Intercom::HttpError.new('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? or (@finder_params[:page] and (current_page >= @finder_params[:page])) end self end |