Class: RTX::API::CollectionV2
- Inherits:
-
Object
- Object
- RTX::API::CollectionV2
- Defined in:
- lib/rtx/api/collection_v2.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#options ⇒ Object
Returns the value of attribute options.
-
#resource_name ⇒ Object
Returns the value of attribute resource_name.
-
#response ⇒ Object
Returns the value of attribute response.
Instance Method Summary collapse
-
#all_pages(&block) ⇒ Object
Allows you to loop through all of the pages and retrieve the records.
-
#all_resources(&block) ⇒ Object
Allows you to loop through all of the resources within the pages specified and retrieve the records.
-
#data ⇒ Object
Returns all data associated with the existing response.
-
#has_next? ⇒ Boolean
Responds true if the collection has another page ahead of it.
-
#has_previous? ⇒ Boolean
Responds true if the collection has a previous one.
-
#initialize(client, resource_name, attrs = {}) ⇒ CollectionV2
constructor
A new instance of CollectionV2.
-
#next ⇒ Object
For moving forward one page with the collection.
-
#paging ⇒ Object
Returns the paging information about the current response.
-
#per_page(num) ⇒ Object
Chainable method that allows you to set the per page number of the collection for your request.
-
#prev ⇒ Object
For moving backward one page with the collection.
Constructor Details
#initialize(client, resource_name, attrs = {}) ⇒ CollectionV2
Returns a new instance of CollectionV2.
6 7 8 9 10 11 |
# File 'lib/rtx/api/collection_v2.rb', line 6 def initialize(client, resource_name, attrs = {}) @client = client @resource_name = resource_name.to_sym @options = symbolize_hash(attrs) @response = {} end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
4 5 6 |
# File 'lib/rtx/api/collection_v2.rb', line 4 def client @client end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/rtx/api/collection_v2.rb', line 4 def @options end |
#resource_name ⇒ Object
Returns the value of attribute resource_name.
4 5 6 |
# File 'lib/rtx/api/collection_v2.rb', line 4 def resource_name @resource_name end |
#response ⇒ Object
Returns the value of attribute response.
4 5 6 |
# File 'lib/rtx/api/collection_v2.rb', line 4 def response @response end |
Instance Method Details
#all_pages(&block) ⇒ Object
Allows you to loop through all of the pages and retrieve the records
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rtx/api/collection_v2.rb', line 61 def all_pages(&block) loop do # Return first page block.call(data) # No need to continue if all data is retrieved break unless has_next? # Navigate to the next page self.next end end |
#all_resources(&block) ⇒ Object
Allows you to loop through all of the resources within the pages specified and retrieve the records
75 76 77 78 79 80 81 |
# File 'lib/rtx/api/collection_v2.rb', line 75 def all_resources(&block) all_pages do |page| page.each do |resource| block.call(resource) end end end |
#data ⇒ Object
Returns all data associated with the existing response
21 22 23 24 25 |
# File 'lib/rtx/api/collection_v2.rb', line 21 def data client.authenticate if !client.authenticated? collection if !has_response? response[:data] end |
#has_next? ⇒ Boolean
Responds true if the collection has another page ahead of it
51 52 53 |
# File 'lib/rtx/api/collection_v2.rb', line 51 def has_next? !after_token.nil? end |
#has_previous? ⇒ Boolean
Responds true if the collection has a previous one
56 57 58 |
# File 'lib/rtx/api/collection_v2.rb', line 56 def has_previous? !before_token.nil? end |
#next ⇒ Object
For moving forward one page with the collection
35 36 37 38 39 40 |
# File 'lib/rtx/api/collection_v2.rb', line 35 def next if has_next? next_page(after_token) end self end |
#paging ⇒ Object
Returns the paging information about the current response
28 29 30 31 32 |
# File 'lib/rtx/api/collection_v2.rb', line 28 def paging client.authenticate if !client.authenticated? collection if !has_response? response[:paging] end |
#per_page(num) ⇒ Object
Chainable method that allows you to set the per page number of the collection for your request
14 15 16 17 18 |
# File 'lib/rtx/api/collection_v2.rb', line 14 def per_page(num) clear if !num.nil? @options[:per_page] = num self end |
#prev ⇒ Object
For moving backward one page with the collection
43 44 45 46 47 48 |
# File 'lib/rtx/api/collection_v2.rb', line 43 def prev if has_previous? previous_page(before_token) end self end |