Sha256: f9b78d5d14e2e0c0666843535985218cf063de1582e3aa6bdb9edfcc31c7c5c5

Contents?: true

Size: 822 Bytes

Versions: 14

Compression:

Stored size: 822 Bytes

Contents

# frozen_string_literal: true

module Dato
  class Paginator
    def initialize(client, base_endpoint, filters)
      @client = client
      @base_endpoint = base_endpoint
      @filters = 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

14 entries across 14 versions & 1 rubygems

Version Path
dato-0.7.5 lib/dato/paginator.rb
dato-0.7.4 lib/dato/paginator.rb
dato-0.7.3 lib/dato/paginator.rb
dato-0.7.2 lib/dato/paginator.rb
dato-0.7.1 lib/dato/paginator.rb
dato-0.7.0 lib/dato/paginator.rb
dato-0.6.18 lib/dato/paginator.rb
dato-0.6.17 lib/dato/paginator.rb
dato-0.6.16 lib/dato/paginator.rb
dato-0.6.15 lib/dato/paginator.rb
dato-0.6.14 lib/dato/paginator.rb
dato-0.6.12 lib/dato/paginator.rb
dato-0.6.11 lib/dato/paginator.rb
dato-0.6.10 lib/dato/paginator.rb