Sha256: 03f3c926f71924c1b58629637254ac10f613c1732b35223bc2772c0e6396fe10

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module ErpIntegration
  module Fulfil
    module PaginationMethods
      DEFAULT_OFFSET = 0
      MAX_LIMIT = 500 # Max limit set by FF

      attr_accessor :offset_value, :limit_value

      # The {#offset} method allows navigating through the returned resources from
      # Fulfil's API endpoints just as with a regular database.
      #
      # @param value [Integer] The offset for the number of resources.
      # @return [ErpIntegration::Fulfil::ApiResource]
      def offset(value)
        clone.offset!(value)
      end

      def offset!(value)
        self.offset_value = value
        self
      end

      # By default, Fulfil returns the first 500 records for every query to their
      # API endpoints. With the {#limit} method, it's possible to modify the number
      # of records to return.
      #
      # NOTE: The maximum limit is 500 per dictation of Fulfil.
      #
      # @param value [Integer] The number of resources to return.
      # @return [ErpIntegration::Fulfil::ApiResource]
      def limit(value)
        clone.limit!(value)
      end

      def limit!(value)
        self.limit_value = [value, MAX_LIMIT].min
        self
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
erp_integration-0.20.0 lib/erp_integration/fulfil/pagination_methods.rb