Class: Outhad::Integrations::Source::SalesforceConsumerGoodsCloud::Client

Inherits:
SourceConnector
  • Object
show all
Includes:
Core::RateLimiter
Defined in:
lib/outhad/integrations/source/salesforce_consumer_goods_cloud/client.rb

Instance Method Summary collapse

Methods included from Core::RateLimiter

#write

Instance Method Details

#check_connection(connection_config) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/outhad/integrations/source/salesforce_consumer_goods_cloud/client.rb', line 17

def check_connection(connection_config)
  connection_config = connection_config.with_indifferent_access
  initialize_client(connection_config)
  authenticate_client
  success_status
rescue StandardError => e
  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
43
# File 'lib/outhad/integrations/source/salesforce_consumer_goods_cloud/client.rb', line 26

def discover(connection_config)
  connection_config = connection_config.with_indifferent_access
  initialize_client(connection_config)
  catalog = build_catalog(load_catalog.with_indifferent_access)
  streams = catalog[:streams]
  SALESFORCE_OBJECTS.each do |object|
    object_description = @client.describe(object)
    streams << JSON.parse(SchemaHelper.create_json_schema_for_object(object_description).to_json)
  rescue StandardError
    next
  end
  catalog.to_outhad_message
rescue StandardError => e
  handle_exception(e, {
                     context: "SALESFORCE:CONSUMER:GOODS:ClOUD:DISCOVER:EXCEPTION",
                     type: "error"
                   })
end

#read(sync_config) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/outhad/integrations/source/salesforce_consumer_goods_cloud/client.rb', line 45

def read(sync_config)
  connection_config = sync_config.source.connection_specification.with_indifferent_access
  initialize_client(connection_config)
  query = sync_config.model.query
  query = "#{query} LIMIT #{sync_config.limit}" unless sync_config.limit.nil?
  queried_data = @client.query(query)
  results = queried_data.map do |record|
    flatten_nested_hash(record)
  end
  results.map do |row|
    RecordMessage.new(data: row, emitted_at: Time.now.to_i).to_outhad_message
  end
rescue StandardError => e
  handle_exception(e, {
                     context: "SALESFORCE:CONSUMER:GOODS:ClOUD:WRITE:EXCEPTION",
                     type: "error",
                     sync_id: sync_config.sync_id,
                     sync_run_id: sync_config.sync_run_id
                   })
end