Class: Multiwoven::Integrations::Source::SalesforceConsumerGoodsCloud::Client

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

Overview

rubocop:disable Metrics/ClassLength

Instance Method Summary collapse

Methods included from Core::RateLimiter

#write

Instance Method Details

#check_connection(connection_config) ⇒ Object



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

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



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/multiwoven/integrations/source/salesforce_consumer_goods_cloud/client.rb', line 25

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(create_json_schema_for_object(object_description).to_json)
  end
  catalog.to_multiwoven_message
rescue StandardError => e
  handle_exception("SALESFORCE:CRM:DISCOVER:EXCEPTION", "error", e)
end

#read(sync_config) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/multiwoven/integrations/source/salesforce_consumer_goods_cloud/client.rb', line 39

def read(sync_config)
  connection_config = sync_config.source.connection_specification.with_indifferent_access
  initialize_client(connection_config)
  query = sync_config.model.query
  query = batched_query(query, sync_config.limit, sync_config.offset) unless sync_config.limit.nil? && sync_config.offset.nil?
  exclude_keys = ["attributes"]
  queried_data = @client.query(query)
  results = queried_data.map do |record|
    record.reject { |key, _| exclude_keys.include?(key) }
  end
  results.map do |row|
    RecordMessage.new(data: row, emitted_at: Time.now.to_i).to_multiwoven_message
  end
rescue StandardError => e
  handle_exception("SALESFORCE:CRM:WRITE:EXCEPTION", "error", e)
end