multiwoven-integrations 0.1.47 → 0.1.48

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3717ab4d5a6874c8d994fe634fbc8a03d3670f34f421da9a929a4c5c0140fdf
4
- data.tar.gz: 4894017bad2a8bdd663a6c70826f02bc64b88e371166c4c2a7076b11f27d442e
3
+ metadata.gz: f070f9727eba1e360878e33850045dfe4b508f351d91cb6fa3e6ae46edda8ad7
4
+ data.tar.gz: 425485c695c2803835c98549695d343d63db2c5d388328dc983759a50fdd63ee
5
5
  SHA512:
6
- metadata.gz: d50f3ef6a5ec4a4ff6fafc63009327eeea97b7d58bd3ea29337979f7529843a21d1e1b1c9f58d02b844d36c63b8fffd545bbc4bad288ac0dd2df5f9ec022c535
7
- data.tar.gz: 83d37be362a7bc1e413455b5ae1684fa8349ee470ed0bad2009e163355b7583a1662560f8cf64112351335889e052c4f96c7b44b36b8bfcb340bb1a813fe17c8
6
+ metadata.gz: ae737e08dbae12d4cea2c51082684f5dcfa1d50d75100252bcaaf3171922d185072ad5894a9546f695a22b3b8112b176fb8f6a1d9caa3a8614240243188373a8
7
+ data.tar.gz: 7d1adab5630abc8fb506391f49476b285f6753f79f8b779bf87db87ffb918c5e794dba28ee419b19629ea6f87ed93040bd81af787e92fc02f2cebef6d058dfd1
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "stringio"
4
+ require_relative "schema_helper"
4
5
 
5
6
  module Multiwoven
6
7
  module Integrations
@@ -9,6 +10,7 @@ module Multiwoven
9
10
  include Multiwoven::Integrations::Core
10
11
 
11
12
  API_VERSION = "59.0"
13
+ SALESFORCE_OBJECTS = %w[Account User Visit RetailStore RecordType].freeze
12
14
 
13
15
  class Client < DestinationConnector
14
16
  prepend Multiwoven::Integrations::Core::RateLimiter
@@ -21,8 +23,15 @@ module Multiwoven
21
23
  failure_status(e)
22
24
  end
23
25
 
24
- def discover(_connection_config = nil)
25
- catalog = build_catalog(load_catalog)
26
+ def discover(connection_config)
27
+ connection_config = connection_config.with_indifferent_access
28
+ initialize_client(connection_config)
29
+ catalog = build_catalog(load_catalog.with_indifferent_access)
30
+ streams = catalog[:streams]
31
+ SALESFORCE_OBJECTS.each do |object|
32
+ object_description = @client.describe(object)
33
+ streams << JSON.parse(SchemaHelper.create_json_schema_for_object(object_description).to_json)
34
+ end
26
35
  catalog.to_multiwoven_message
27
36
  rescue StandardError => e
28
37
  handle_exception("SALESFORCE:CONSUMER:GOODS:ClOUD:DISCOVER:EXCEPTION", "error", e)
@@ -40,12 +49,11 @@ module Multiwoven
40
49
 
41
50
  def initialize_client(config)
42
51
  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],
52
+ @client = Restforce.new(username: config[:username],
53
+ password: config[:password] + config[:security_token],
54
+ host: config[:host],
46
55
  client_id: config[:client_id],
47
56
  client_secret: config[:client_secret],
48
- authentication_callback: proc { |x| log_debug(x.to_s) },
49
57
  api_version: API_VERSION)
50
58
  end
51
59
 
@@ -69,22 +77,11 @@ module Multiwoven
69
77
  end
70
78
 
71
79
  def send_data_to_salesforce(stream_name, record = {})
72
- method_name = "#{@action}!"
73
- args = build_args(@action, stream_name, record)
80
+ method_name = "upsert!"
81
+ args = [stream_name, "Id", record]
74
82
  @client.send(method_name, *args)
75
83
  end
76
84
 
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
85
  def authenticate_client
89
86
  @client.authenticate!
90
87
  end