Class: Multiwoven::Integrations::Destination::Http::Client
- Inherits:
-
DestinationConnector
- Object
- DestinationConnector
- Multiwoven::Integrations::Destination::Http::Client
- Includes:
- Core::OauthClientCredentials
- Defined in:
- lib/multiwoven/integrations/destination/http/client.rb
Constant Summary collapse
- MAX_CHUNK_SIZE =
10
Constants included from Core::OauthClientCredentials
Core::OauthClientCredentials::AUTH_TYPE_OAUTH_CLIENT_CREDENTIALS, Core::OauthClientCredentials::TOKEN_EXPIRY_BUFFER_SECONDS
Instance Method Summary collapse
- #check_connection(connection_config) ⇒ Object
- #discover(_connection_config = nil) ⇒ Object
- #write(sync_config, records, _action = "create", _identifier_key = nil) ⇒ Object
Methods included from Core::OauthClientCredentials
#build_headers, #ensure_oauth_token
Instance Method Details
#check_connection(connection_config) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/multiwoven/integrations/destination/http/client.rb', line 13 def check_connection(connection_config) connection_config = connection_config.with_indifferent_access destination_url = connection_config[:destination_url] request = Multiwoven::Integrations::Core::HttpClient.request( destination_url, HTTP_POST, payload: {}, headers: build_headers(connection_config) ) if success?(request) success_status else failure_status(nil) end rescue StandardError => e handle_exception(e, { context: "HTTP:CHECK_CONNECTION:EXCEPTION", type: "error" }) failure_status(e) end |
#discover(_connection_config = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/multiwoven/integrations/destination/http/client.rb', line 35 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: "HTTP:DISCOVER:EXCEPTION", type: "error" }) end |
#write(sync_config, records, _action = "create", _identifier_key = nil) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/multiwoven/integrations/destination/http/client.rb', line 46 def write(sync_config, records, _action = "create", _identifier_key = nil) connection_config = sync_config.destination.connection_specification.with_indifferent_access @connector_instance = sync_config&.destination&.connector_instance url = connection_config[:destination_url] headers = build_headers(connection_config) = [] write_success = 0 write_failure = 0 records.each_slice(MAX_CHUNK_SIZE) do |chunk| payload = create_payload(chunk) args = [sync_config.stream.request_method, url, payload] response = Multiwoven::Integrations::Core::HttpClient.request( url, sync_config.stream.request_method, payload: payload, headers: headers ) if success?(response) write_success += chunk.size else write_failure += chunk.size end << log_request_response("info", args, response) rescue StandardError => e handle_exception(e, { context: "HTTP:RECORD:WRITE:EXCEPTION", type: "error", sync_id: sync_config.sync_id, sync_run_id: sync_config.sync_run_id }) write_failure += chunk.size << log_request_response("error", args, e.) end (write_success, write_failure, ) rescue StandardError => e handle_exception(e, { context: "HTTP:RECORD:WRITE:EXCEPTION", type: "error", sync_id: sync_config.sync_id, sync_run_id: sync_config.sync_run_id }) end |