Sha256: 0e5a8930c0c79ff17ea89f553c8cd0ab21284faf2c79f7fa0b12b5e4cdc0272a

Contents?: true

Size: 850 Bytes

Versions: 7

Compression:

Stored size: 850 Bytes

Contents

module Dato
  module Site
    class Paginator
      def initialize(client, base_endpoint, filters)
        @client, @base_endpoint, @filters = client, base_endpoint, filters
      end

      def response
        items_per_page = 100

        base_response = @client.request(
          :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.request(
            :get,
            @base_endpoint,
            @filters.dup.merge(
              'page[offset]' => items_per_page * (page + 1),
              'page[limit]' => items_per_page
            )
          )[:data]
        end

        base_response
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dato-0.5.1 lib/dato/site/paginator.rb
dato-0.5.0 lib/dato/site/paginator.rb
dato-0.4.3 lib/dato/site/paginator.rb
dato-0.4.2 lib/dato/site/paginator.rb
dato-0.4.1 lib/dato/site/paginator.rb
dato-0.4.0 lib/dato/site/paginator.rb
dato-0.3.31 lib/dato/site/paginator.rb