Class: Outhad::Integrations::Destination::MicrosoftDynamics::Client
- Inherits:
-
DestinationConnector
- Object
- DestinationConnector
- Outhad::Integrations::Destination::MicrosoftDynamics::Client
- Defined in:
- lib/outhad/integrations/destination/microsoft_dynamics/client.rb
Instance Method Summary collapse
- #check_connection(connection_config) ⇒ Object
- #discover(_connection_config = nil) ⇒ Object
- #write(sync_config, records, _action = "upsert") ⇒ Object
Instance Method Details
#check_connection(connection_config) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/outhad/integrations/destination/microsoft_dynamics/client.rb', line 8 def check_connection(connection_config) connection_config = connection_config.with_indifferent_access initialize_client(connection_config) token_response = create_access_token uri = URI.parse(format(MS_DYNAMICS_WHOAMI_API, instance_url: @instance_url, api_version: API_VERSION)) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == "https") request = Net::HTTP::Get.new(uri) auth_headers(token_response["access_token"]).each { |key, value| request[key] = value } response = http.request(request) response_body = JSON.parse(response.body) if success?(response) && response_body.key?("UserId") success_status else failure_status(nil) end rescue StandardError => e handle_exception(e, { context: "MICROSOFT:DYNAMICS:CHECK_CONNECTION:EXCEPTION", type: "error" }) failure_status(e) end |
#discover(_connection_config = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/outhad/integrations/destination/microsoft_dynamics/client.rb', line 33 def discover(_connection_config = nil) catalog_json = read_json(CATALOG_SPEC_PATH) catalog = build_catalog(catalog_json) catalog. rescue StandardError => e handle_exception(e, { context: "MICROSOFT:DYNAMICS:DISCOVER:EXCEPTION", type: "error" }) end |
#write(sync_config, records, _action = "upsert") ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/outhad/integrations/destination/microsoft_dynamics/client.rb', line 44 def write(sync_config, records, _action = "upsert") @sync_config = sync_config stream = @sync_config.stream connection_config = @sync_config.destination.connection_specification.with_indifferent_access create_connection(connection_config) build_url(stream) process_records(records, stream) rescue StandardError => e handle_exception(e, { context: "MICROSOFT:DYNAMICS:WRITE:EXCEPTION", type: "error", sync_id: @sync_config.sync_id, sync_run_id: @sync_config.sync_run_id }) end |