Class: LedgerSync::Adaptors::QuickBooksOnline::Vendor::Searcher

Inherits:
Searcher
  • Object
show all
Defined in:
lib/ledger_sync/adaptors/quickbooks_online/vendor/searcher.rb

Instance Attribute Summary

Attributes inherited from Searcher

#adaptor, #pagination, #query

Instance Method Summary collapse

Methods inherited from Searcher

#initialize

Constructor Details

This class inherits a constructor from LedgerSync::Adaptors::Searcher

Instance Method Details

#next_searcherObject



6
7
8
# File 'lib/ledger_sync/adaptors/quickbooks_online/vendor/searcher.rb', line 6

def next_searcher
  paginate(limit: limit, offset: offset + limit)
end

#previous_searcherObject



10
11
12
13
14
# File 'lib/ledger_sync/adaptors/quickbooks_online/vendor/searcher.rb', line 10

def previous_searcher
  return nil if offset <= 1

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

#resourcesObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ledger_sync/adaptors/quickbooks_online/vendor/searcher.rb', line 16

def resources
  @resources ||= begin
    adaptor
      .query(
        resource: 'vendor',
        query: "DisplayName LIKE '%#{query}%'",
        limit: limit,
        offset: offset
      )
      .map do |c|
        LedgerSync::Vendor.new(
          ledger_id: c.fetch('Id'),
          display_name: c.fetch('DisplayName'),
          first_name: c.dig('GivenName'),
          last_name: c.dig('FamilyName')
        )
      end
  end
end

#searchObject



36
37
38
39
40
41
# File 'lib/ledger_sync/adaptors/quickbooks_online/vendor/searcher.rb', line 36

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