Class: SamcartAPI::Paginator
- Inherits:
-
Object
- Object
- SamcartAPI::Paginator
- Defined in:
- lib/samcart_api/paginator.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #each_page ⇒ Object
-
#initialize(client, path, params) ⇒ Paginator
constructor
A new instance of Paginator.
- #next_page ⇒ Object
- #next_page? ⇒ Boolean
Constructor Details
#initialize(client, path, params) ⇒ Paginator
Returns a new instance of Paginator.
5 6 7 8 9 |
# File 'lib/samcart_api/paginator.rb', line 5 def initialize(client, path, params) @client = client @next_url = "#{path}?#{params.to_query}" @retry_attempts = 3 end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
27 28 29 |
# File 'lib/samcart_api/paginator.rb', line 27 def client @client end |
Instance Method Details
#each_page ⇒ Object
23 24 25 |
# File 'lib/samcart_api/paginator.rb', line 23 def each_page yield next_page while next_page? end |
#next_page ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/samcart_api/paginator.rb', line 15 def next_page return unless next_page? response = client.get(@next_url) @next_url = response.dig('pagination', 'next') response['data'] end |
#next_page? ⇒ Boolean
11 12 13 |
# File 'lib/samcart_api/paginator.rb', line 11 def next_page? !@next_url.nil? end |