multiwoven-integrations 0.1.37 → 0.1.39
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/multiwoven/integrations/destination/salesforce_consumer_goods_cloud/client.rb +117 -0
- data/lib/multiwoven/integrations/destination/salesforce_consumer_goods_cloud/config/catalog.json +2042 -0
- data/lib/multiwoven/integrations/destination/salesforce_consumer_goods_cloud/config/meta.json +16 -0
- data/lib/multiwoven/integrations/destination/salesforce_consumer_goods_cloud/config/spec.json +43 -0
- data/lib/multiwoven/integrations/destination/salesforce_consumer_goods_cloud/icon.svg +16 -0
- data/lib/multiwoven/integrations/rollout.rb +3 -1
- data/lib/multiwoven/integrations/source/salesforce_consumer_goods_cloud/client.rb +211 -0
- data/lib/multiwoven/integrations/source/salesforce_consumer_goods_cloud/config/catalog.json +6 -0
- data/lib/multiwoven/integrations/source/salesforce_consumer_goods_cloud/config/meta.json +17 -0
- data/lib/multiwoven/integrations/source/salesforce_consumer_goods_cloud/config/spec.json +49 -0
- data/lib/multiwoven/integrations/source/salesforce_consumer_goods_cloud/icon.svg +16 -0
- data/lib/multiwoven/integrations.rb +2 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3123a99f29451e56f8a1e29734986e05912dde86c00bd4b5acce1b2cf00e6ba
|
4
|
+
data.tar.gz: 1490775563ce10d3c4054e481f5827317028a3da65b2c84aaaafe7f6122f02cc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c0d4b213125850a7ee7d421cb8dcd0af7bfbaf9ebb5a18adbf3ba2e3140b91ebbda4b27c2d8f5d8a90a16c5a0291e06ee4e0b1318ccd45be3f4a5f22c8af228
|
7
|
+
data.tar.gz: 87cb23b0dad389a43688edafa6cda3f367ad59aeb1682d8c78f1d46a8969081742c860ffc2eb713454bd0b3479189ed83b918d9c86f597e85e29ca1516f2bc25
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "stringio"
|
4
|
+
|
5
|
+
module Multiwoven
|
6
|
+
module Integrations
|
7
|
+
module Destination
|
8
|
+
module SalesforceConsumerGoodsCloud
|
9
|
+
include Multiwoven::Integrations::Core
|
10
|
+
|
11
|
+
API_VERSION = "59.0"
|
12
|
+
|
13
|
+
class Client < DestinationConnector
|
14
|
+
prepend Multiwoven::Integrations::Core::RateLimiter
|
15
|
+
def check_connection(connection_config)
|
16
|
+
connection_config = connection_config.with_indifferent_access
|
17
|
+
initialize_client(connection_config)
|
18
|
+
authenticate_client
|
19
|
+
success_status
|
20
|
+
rescue StandardError => e
|
21
|
+
failure_status(e)
|
22
|
+
end
|
23
|
+
|
24
|
+
def discover(_connection_config = nil)
|
25
|
+
catalog = build_catalog(load_catalog)
|
26
|
+
catalog.to_multiwoven_message
|
27
|
+
rescue StandardError => e
|
28
|
+
handle_exception("SALESFORCE:CONSUMER:GOODS:ClOUD:DISCOVER:EXCEPTION", "error", e)
|
29
|
+
end
|
30
|
+
|
31
|
+
def write(sync_config, records, action = "create")
|
32
|
+
@action = sync_config.stream.action || action
|
33
|
+
initialize_client(sync_config.destination.connection_specification)
|
34
|
+
process_records(records, sync_config.stream)
|
35
|
+
rescue StandardError => e
|
36
|
+
handle_exception("SALESFORCE:CONSUMER:GOODS:ClOUD:WRITE:EXCEPTION", "error", e)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def initialize_client(config)
|
42
|
+
config = config.with_indifferent_access
|
43
|
+
@client = Restforce.new(oauth_token: config[:access_token],
|
44
|
+
refresh_token: config[:refresh_token],
|
45
|
+
instance_url: config[:instance_url],
|
46
|
+
client_id: config[:client_id],
|
47
|
+
client_secret: config[:client_secret],
|
48
|
+
authentication_callback: proc { |x| log_debug(x.to_s) },
|
49
|
+
api_version: API_VERSION)
|
50
|
+
end
|
51
|
+
|
52
|
+
def process_records(records, stream)
|
53
|
+
write_success = 0
|
54
|
+
write_failure = 0
|
55
|
+
properties = stream.json_schema[:properties]
|
56
|
+
records.each do |record_object|
|
57
|
+
record = extract_data(record_object, properties)
|
58
|
+
process_record(stream, record)
|
59
|
+
write_success += 1
|
60
|
+
rescue StandardError => e
|
61
|
+
handle_exception("SALESFORCE:CONSUMER:GOODS:ClOUD:WRITE:EXCEPTION", "error", e)
|
62
|
+
write_failure += 1
|
63
|
+
end
|
64
|
+
tracking_message(write_success, write_failure)
|
65
|
+
end
|
66
|
+
|
67
|
+
def process_record(stream, record)
|
68
|
+
send_data_to_salesforce(stream.name, record)
|
69
|
+
end
|
70
|
+
|
71
|
+
def send_data_to_salesforce(stream_name, record = {})
|
72
|
+
method_name = "#{@action}!"
|
73
|
+
args = build_args(@action, stream_name, record)
|
74
|
+
@client.send(method_name, *args)
|
75
|
+
end
|
76
|
+
|
77
|
+
def build_args(action, stream_name, record)
|
78
|
+
case action
|
79
|
+
when :upsert
|
80
|
+
[stream_name, record[:external_key], record]
|
81
|
+
when :destroy
|
82
|
+
[stream_name, record[:id]]
|
83
|
+
else
|
84
|
+
[stream_name, record]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def authenticate_client
|
89
|
+
@client.authenticate!
|
90
|
+
end
|
91
|
+
|
92
|
+
def success_status
|
93
|
+
ConnectionStatus.new(status: ConnectionStatusType["succeeded"]).to_multiwoven_message
|
94
|
+
end
|
95
|
+
|
96
|
+
def failure_status(error)
|
97
|
+
ConnectionStatus.new(status: ConnectionStatusType["failed"], message: error.message).to_multiwoven_message
|
98
|
+
end
|
99
|
+
|
100
|
+
def load_catalog
|
101
|
+
read_json(CATALOG_SPEC_PATH)
|
102
|
+
end
|
103
|
+
|
104
|
+
def tracking_message(success, failure)
|
105
|
+
Multiwoven::Integrations::Protocol::TrackingMessage.new(
|
106
|
+
success: success, failed: failure
|
107
|
+
).to_multiwoven_message
|
108
|
+
end
|
109
|
+
|
110
|
+
def log_debug(message)
|
111
|
+
Multiwoven::Integrations::Service.logger.debug(message)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|