multiwoven-integrations 0.1.18 → 0.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33bd471327290a3ea7196e558ad47a4a41c5295f7535ca7e01ba5e3c920edf8f
4
- data.tar.gz: 1b4c17cd7dcc6b7ea0e1a5208e71fba57d2c790863fee0fda5fcd24220bddf4f
3
+ metadata.gz: 429328f071eab809197f11563a5c87a91ca1d83db1f89f67edc001b2d8aa0d08
4
+ data.tar.gz: fdbe36a9021b0eae79cff29ec7002859f03993e354d61a45e01024b293ea5835
5
5
  SHA512:
6
- metadata.gz: 68017d5b0a0548fb3944248838fe5938377e477d2ce32c34421b32f92eba9bc487564d99583dad8f7f61aa0bba358f35570a2a6b20e3045c42da009b9dd46d87
7
- data.tar.gz: da0889bd2c8865111319eab6d7ec3923edf34fb91b38bb885395e7aa2006080cddd17a73b924ab88154f5d38bc749fb00a2d53760c1c1d2a1ff032d48288f6e8
6
+ metadata.gz: 3b17d88517b0b196bef171d72abb99f8ae9faa8e1b8e62c4e9296e86d821025544c742e35a526b5cd1a35a31e8f1959183648a24dcb8ac0269ec34dca5de87e0
7
+ data.tar.gz: 96d942afc5d2a4015534b57d72b2f8f35fdb91bec1004e5d180ecf451d46a5cc980fdfca406335de9d7ef522e041c49dcba459d56f297ead36223e701f389ac3
@@ -3,7 +3,8 @@
3
3
  module Multiwoven::Integrations::Destination
4
4
  module FacebookCustomAudience
5
5
  include Multiwoven::Integrations::Core
6
- class Client < DestinationConnector # rubocop:disable Metrics/ClassLength
6
+ class Client < DestinationConnector # rubocop:disable Metrics/ClassLength
7
+ MAX_CHUNK_SIZE = 10_000
7
8
  def check_connection(connection_config)
8
9
  connection_config = connection_config.with_indifferent_access
9
10
  access_token = connection_config[:access_token]
@@ -54,8 +55,8 @@ module Multiwoven::Integrations::Destination
54
55
  url = generate_url(sync_config, connection_config)
55
56
  write_success = 0
56
57
  write_failure = 0
57
- records.each do |record|
58
- payload = create_payload(record.with_indifferent_access, sync_config.stream.json_schema.with_indifferent_access)
58
+ records.each_slice(MAX_CHUNK_SIZE) do |chunk|
59
+ payload = create_payload(chunk, sync_config.stream.json_schema.with_indifferent_access)
59
60
  response = Multiwoven::Integrations::Core::HttpClient.request(
60
61
  url,
61
62
  sync_config.stream.request_method,
@@ -63,28 +64,22 @@ module Multiwoven::Integrations::Destination
63
64
  headers: auth_headers(access_token)
64
65
  )
65
66
  if success?(response)
66
- write_success += 1
67
+ write_success += chunk.size
67
68
  else
68
- write_failure += 1
69
+ write_failure += chunk.size
69
70
  end
70
71
  rescue StandardError => e
71
- logger.error(
72
- "FACEBOOK:RECORD:WRITE:FAILURE: #{e.message}"
73
- )
74
- write_failure += 1
72
+ handle_exception("FACEBOOK:RECORD:WRITE:EXCEPTION", "error", e)
73
+ write_failure += chunk.size
75
74
  end
75
+
76
76
  tracker = Multiwoven::Integrations::Protocol::TrackingMessage.new(
77
77
  success: write_success,
78
78
  failed: write_failure
79
79
  )
80
80
  tracker.to_multiwoven_message
81
81
  rescue StandardError => e
82
- # TODO: Handle rate limiting seperately
83
- handle_exception(
84
- "FACEBOOK:WRITE:EXCEPTION",
85
- "error",
86
- e
87
- )
82
+ handle_exception("FACEBOOK:WRITE:EXCEPTION", "error", e)
88
83
  end
89
84
 
90
85
  private
@@ -93,28 +88,30 @@ module Multiwoven::Integrations::Destination
93
88
  sync_config.stream.url.gsub("{audience_id}", connection_config[:audience_id])
94
89
  end
95
90
 
96
- def create_payload(record_data, json_schema)
97
- schema, data = extract_schema_and_data(record_data, json_schema)
91
+ def create_payload(records, json_schema)
92
+ schema, data = extract_schema_and_data(records, json_schema)
98
93
  {
99
94
  "payload" => {
100
95
  "schema" => schema,
101
- "data" => [data]
96
+ "data" => data
102
97
  }
103
98
  }
104
99
  end
105
100
 
106
- def extract_schema_and_data(data, json_schema)
101
+ def extract_schema_and_data(records, json_schema)
107
102
  schema_properties = json_schema[:properties]
108
- schema = data.keys.map(&:upcase)
109
- encrypted_data_array = []
110
-
111
- data.each do |key, value|
112
- schema_key = key.upcase
113
- encrypted_value = schema_properties[schema_key] && schema_properties[schema_key]["x-hashRequired"] ? Digest::SHA256.hexdigest(value.to_s) : value
114
- encrypted_data_array << encrypted_value
103
+ schema = records.first.keys.map(&:to_s).map(&:upcase)
104
+ data = []
105
+ records.each do |record|
106
+ encrypted_data_array = []
107
+ record.with_indifferent_access.each do |key, value|
108
+ schema_key = key.upcase
109
+ encrypted_value = schema_properties[schema_key] && schema_properties[schema_key]["x-hashRequired"] ? Digest::SHA256.hexdigest(value.to_s) : value
110
+ encrypted_data_array << encrypted_value
111
+ end
112
+ data << encrypted_data_array
115
113
  end
116
-
117
- [schema, encrypted_data_array]
114
+ [schema, data]
118
115
  end
119
116
 
120
117
  def auth_headers(access_token)
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Multiwoven
4
4
  module Integrations
5
- VERSION = "0.1.18"
5
+ VERSION = "0.1.19"
6
6
 
7
7
  ENABLED_SOURCES = %w[
8
8
  Snowflake
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multiwoven-integrations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Subin T P
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-09 00:00:00.000000000 Z
11
+ date: 2024-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -362,7 +362,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
362
362
  - !ruby/object:Gem::Version
363
363
  version: '0'
364
364
  requirements: []
365
- rubygems_version: 3.5.3
365
+ rubygems_version: 3.4.1
366
366
  signing_key:
367
367
  specification_version: 4
368
368
  summary: Integration suite for open source reverse ETL platform