Class: Outhad::Integrations::Source::IntuitQuickBooks::Client

Inherits:
SourceConnector
  • Object
show all
Defined in:
lib/outhad/integrations/source/intuit_quick_books/client.rb

Instance Method Summary collapse

Instance Method Details

#check_connection(connection_config) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/outhad/integrations/source/intuit_quick_books/client.rb', line 11

def check_connection(connection_config)
  connection_config = connection_config.with_indifferent_access
  access_token = create_connection(connection_config)
  query = "SELECT * FROM Customer STARTPOSITION 1 MAXRESULTS 1"
  response = query_quickbooks(access_token, query)
  if success?(response)
    success_status
  else
    failure_status(nil)
  end
rescue StandardError => e
  handle_exception(e, { context: "INTUIT_QUICKBOOKS:CHECK_CONNECTION:EXCEPTION", type: "error" })
  failure_status(e)
end

#discover(connection_config) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/outhad/integrations/source/intuit_quick_books/client.rb', line 26

def discover(connection_config)
  connection_config = connection_config.with_indifferent_access
  access_token = create_connection(connection_config)
  catalog = build_catalog(load_catalog.with_indifferent_access)
  streams = catalog[:streams]
  QUICKBOOKS_OBJECTS.each do |object|
    query = "SELECT * FROM #{object}"
    response = query_quickbooks(access_token, query)
    streams << create_streams(JSON.parse(response.body)["QueryResponse"])[0]
  rescue StandardError => e
    handle_exception(e, { context: "INTUIT_QUICKBOOKS:DISCOVER:LOOP_EXCEPTION", type: "error" })
    next
  end
  catalog.to_outhad_message
rescue StandardError => e
  handle_exception(e, { context: "INTUIT_QUICKBOOKS:DISCOVER:EXCEPTION", type: "error" })
end

#read(sync_config) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/outhad/integrations/source/intuit_quick_books/client.rb', line 44

def read(sync_config)
  connection_config = sync_config.source.connection_specification
  connection_config = connection_config.with_indifferent_access
  @connector_instance = sync_config&.source&.connector_instance
  query = sync_config.model.query
  query = batched_query(query, sync_config.limit, sync_config.offset) unless sync_config.limit.nil? && sync_config.offset.nil?
  access_token = create_connection(connection_config)
  query(access_token, query)
rescue StandardError => e
  handle_exception(e, {
                     context: "INTUIT_QUICKBOOKS:READ:EXCEPTION",
                     type: "error",
                     sync_id: sync_config.sync_id,
                     sync_run_id: sync_config.sync_run_id
                   })
end