Sha256: f69c9b4027efda563164402fed46f43174766f0a5096c2846fb32411d44ef4d7

Contents?: true

Size: 780 Bytes

Versions: 10

Compression:

Stored size: 780 Bytes

Contents

module Dato
  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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dato-0.6.9 lib/dato/paginator.rb
dato-0.6.8 lib/dato/paginator.rb
dato-0.6.7 lib/dato/paginator.rb
dato-0.6.6 lib/dato/paginator.rb
dato-0.6.5 lib/dato/paginator.rb
dato-0.6.3 lib/dato/paginator.rb
dato-0.6.3.beta lib/dato/paginator.rb
dato-0.6.2 lib/dato/paginator.rb
dato-0.6.1 lib/dato/paginator.rb
dato-0.6.0 lib/dato/paginator.rb