Sha256: b480f6cd71524d635d3343c52242e7f1d8c3b9d1c5cca73a576ad8db2f14ae55
Contents?: true
Size: 1.7 KB
Versions: 5
Compression:
Stored size: 1.7 KB
Contents
module LedgerSync module Adaptors module QuickBooksOnline module Customer class Searcher < LedgerSync::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 resources @resources ||= begin adaptor .query( resource: 'customer', query: "DisplayName LIKE '%#{query}%'", limit: limit, offset: offset ) .map do |c| LedgerSync::Customer.new( ledger_id: c.fetch('Id'), name: c.dig('FullyQualifiedName'), # active: c.dig('Active') ) end 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 limit pagination.fetch(:limit, 10).to_i end def offset pagination.fetch(:offset, 1).to_i end end end end end end
Version data entries
5 entries across 5 versions & 1 rubygems