Class: Dato::Paginator
- Inherits:
-
Object
- Object
- Dato::Paginator
- Defined in:
- lib/dato/paginator.rb
Instance Method Summary collapse
-
#initialize(client, base_endpoint, filters) ⇒ Paginator
constructor
A new instance of Paginator.
- #response ⇒ Object
Constructor Details
#initialize(client, base_endpoint, filters) ⇒ Paginator
Returns a new instance of Paginator.
5 6 7 8 9 |
# File 'lib/dato/paginator.rb', line 5 def initialize(client, base_endpoint, filters) @client = client @base_endpoint = base_endpoint @filters = filters end |
Instance Method Details
#response ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dato/paginator.rb', line 11 def response items_per_page = 100 base_response = @client.get( @base_endpoint, @filters.dup.merge("page[limit]" => items_per_page) ) extra_pages = ( base_response[:meta][:total_count] / items_per_page.to_f ).ceil - 1 extra_pages.times do |page| base_response[:data] += @client.get( @base_endpoint, @filters.dup.merge( "page[offset]" => items_per_page * (page + 1), "page[limit]" => items_per_page, ), )[:data] end base_response end |