Class: Intercom::BaseCollectionProxy
- Inherits:
-
Object
- Object
- Intercom::BaseCollectionProxy
- Includes:
- Enumerable
- Defined in:
- lib/intercom/base_collection_proxy.rb
Direct Known Subclasses
ClientCollectionProxy, ScrollCollectionProxy, SearchCollectionProxy
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.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #[](target_index) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(resource_name, resource_class, details: {}, client:, method: 'get') ⇒ BaseCollectionProxy
constructor
A new instance of BaseCollectionProxy.
Constructor Details
#initialize(resource_name, resource_class, details: {}, client:, method: 'get') ⇒ BaseCollectionProxy
Returns a new instance of BaseCollectionProxy.
9 10 11 12 13 14 15 16 |
# 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 |
Instance Attribute Details
#resource_class ⇒ Object (readonly)
Returns the value of attribute resource_class.
7 8 9 |
# File 'lib/intercom/base_collection_proxy.rb', line 7 def resource_class @resource_class end |
#resource_name ⇒ Object (readonly)
Returns the value of attribute resource_name.
7 8 9 |
# File 'lib/intercom/base_collection_proxy.rb', line 7 def resource_name @resource_name end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
7 8 9 |
# File 'lib/intercom/base_collection_proxy.rb', line 7 def url @url end |
Instance Method Details
#[](target_index) ⇒ Object
29 30 31 32 33 34 |
# 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) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# 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 |