Sha256: 0489dcb65ffee0d717f594394ceec74d1f5a65dbe1bdcae217f586943fd0bb5d

Contents?: true

Size: 781 Bytes

Versions: 4

Compression:

Stored size: 781 Bytes

Contents

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

4 entries across 4 versions & 1 rubygems

Version Path
agave-client-0.1.3 lib/agave/paginator.rb
agave-client-0.1.2 lib/agave/paginator.rb
agave-client-0.1.1 lib/agave/paginator.rb
agave-client-0.1.0 lib/agave/paginator.rb