Sha256: bdb1f872ad8444b4dc2dc88456edf151dc330efd93794f23c480158b22edec87

Contents?: true

Size: 1.55 KB

Versions: 5

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

module LedgerSync
  module Adaptors
    module QuickBooksOnline
      class Searcher < Adaptors::Searcher
        include Mixins::OffsetAndLimitPaginationSearcherMixin

        def query_string
          ''
        end

        def resources
          resource_class = self.class.inferred_resource_class

          response = adaptor.query(
            limit: limit,
            offset: offset,
            query: query_string,
            resource_class: resource_class
          )
          return [] if response.body.blank?

          (response.body.dig(
            'QueryResponse',
            adaptor.class.ledger_resource_type_for(
              resource_class: resource_class
            ).classify
          ) || []).map do |c|
            self.class.inferred_ledger_serializer_class.new(
              resource: resource_class.new
            ).deserialize(
              hash: c
            )
          end
        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 default_offset
          1
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ledger_sync-1.3.5 lib/ledger_sync/adaptors/quickbooks_online/searcher.rb
ledger_sync-1.3.4 lib/ledger_sync/adaptors/quickbooks_online/searcher.rb
ledger_sync-1.3.3 lib/ledger_sync/adaptors/quickbooks_online/searcher.rb
ledger_sync-1.3.2 lib/ledger_sync/adaptors/quickbooks_online/searcher.rb
ledger_sync-1.3.1 lib/ledger_sync/adaptors/quickbooks_online/searcher.rb