Class: Etl::Integrations::Destination::Klaviyo::Client
- Inherits:
-
DestinationConnector
- Object
- DestinationConnector
- Etl::Integrations::Destination::Klaviyo::Client
- Includes:
- Core::RateLimiter
- Defined in:
- lib/etl/integrations/destination/klaviyo/client.rb
Instance Method Summary collapse
- #check_connection(connection_config) ⇒ Object
- #discover(_connection_config = nil) ⇒ Object
- #write(sync_config, records, _action = "insert") ⇒ Object
Instance Method Details
#check_connection(connection_config) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/etl/integrations/destination/klaviyo/client.rb', line 8 def check_connection(connection_config) connection_config = connection_config.with_indifferent_access api_key = connection_config[:private_api_key] response = Etl::Integrations::Core::HttpClient.request( KLAVIYO_AUTH_ENDPOINT, HTTP_POST, payload: KLAVIYO_AUTH_PAYLOAD, headers: auth_headers(api_key) ) parse_response(response) end |
#discover(_connection_config = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/etl/integrations/destination/klaviyo/client.rb', line 21 def discover(_connection_config = nil) catalog_json = read_json(CATALOG_SPEC_PATH) catalog = build_catalog(catalog_json) catalog. rescue StandardError => e handle_exception( "KLAVIYO:DISCOVER:EXCEPTION", "error", e ) end |
#write(sync_config, records, _action = "insert") ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 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 |
# File 'lib/etl/integrations/destination/klaviyo/client.rb', line 35 def write(sync_config, records, _action = "insert") connection_config = sync_config.destination.connection_specification.with_indifferent_access connection_config = connection_config.with_indifferent_access url = sync_config.stream.url request_method = sync_config.stream.request_method write_success = 0 write_failure = 0 records.each do |record| # pre process payload # Add hardcode values into payload record["data"] ||= {} record["data"]["type"] = sync_config.stream.name response = Etl::Integrations::Core::HttpClient.request( url, request_method, payload: record, headers: auth_headers(connection_config["private_api_key"]) ) if success?(response) write_success += 1 else write_failure += 1 end rescue StandardError => e logger.error( "KLAVIYO:RECORD:WRITE:FAILURE: #{e.}" ) write_failure += 1 end tracker = Etl::Integrations::Protocol::TrackingMessage.new( success: write_success, failed: write_failure ) tracker. rescue StandardError => e # TODO: Handle rate limiting seperately handle_exception( "KLAVIYO:WRITE:EXCEPTION", "error", e ) end |