Sha256: 374a4a7a0738e45db9a8f13577dc5bf8907fb179110e5e9254387a06742429fc

Contents?: true

Size: 1.07 KB

Versions: 3

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module LedgerSync
  module Adaptors
    module QuickBooksOnline
      class Searcher < Adaptors::Searcher
        def next_searcher
          paginate(limit: limit, offset: offset + limit)
        end

        def previous_searcher
          return nil if offset <= 1

          paginate(limit: limit, offset: offset - limit)
        end

        def search
          super
        rescue OAuth2::Error => e
          @response = e # TODO: Better catch/raise errors as LedgerSync::Error
          failure
        end

        private

        # Pagination uses notation of limit and offset
        # limit: number of results per page
        #
        # offset: position of first result in a list.
        # starts from 1, not 0
        #
        # More here:
        # https://developer.intuit.com/app/developer/qbo/docs/develop/explore-the-quickbooks-online-api/data-queries#pagination

        def limit
          pagination.fetch(:limit, 10).to_i
        end

        def offset
          pagination.fetch(:offset, 1).to_i
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ledger_sync-1.1.3 lib/ledger_sync/adaptors/quickbooks_online/searcher.rb
ledger_sync-1.1.2 lib/ledger_sync/adaptors/quickbooks_online/searcher.rb
ledger_sync-1.1.1 lib/ledger_sync/adaptors/quickbooks_online/searcher.rb