Sha256: dbd393a94d0ff45e830cf631fe86b14d93818b63f972902b02bd5946ecce295d

Contents?: true

Size: 696 Bytes

Versions: 4

Compression:

Stored size: 696 Bytes

Contents

# frozen_string_literal: true

module Easyship
  module Pagination
    # Represents a pagination object
    class Cursor
      attr_reader :client, :path, :params, :key, :per_page

      def initialize(client, path, params)
        @client = client
        @path = path
        @params = params
        @per_page = params[:per_page] || Easyship.configuration.per_page
      end

      def all
        page = 1

        loop do
          body = client.get(path, params.merge(page: page, per_page: per_page))

          break if body.nil? || body.empty?

          yield body

          break if body.dig(:meta, :pagination, :next).nil?

          page += 1
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
easyship-0.1.4 lib/easyship/pagination/cursor.rb
easyship-0.1.3 lib/easyship/pagination/cursor.rb
easyship-0.1.2 lib/easyship/pagination/cursor.rb
easyship-0.1.1 lib/easyship/pagination/cursor.rb