promoted-ruby-client 0.1.16 → 0.1.17
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +6 -5
- data/dev.md +1 -1
- data/lib/promoted/ruby/client.rb +7 -9
- data/lib/promoted/ruby/client/faraday_http_client.rb +2 -1
- data/lib/promoted/ruby/client/request_builder.rb +31 -13
- data/lib/promoted/ruby/client/util.rb +26 -3
- data/lib/promoted/ruby/client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2cabc9fa3074e1eed3fd795eaa180a0e47ee18b8eceacb8c3516a347670a5d7
|
4
|
+
data.tar.gz: 8c32e19fe9227fe327ec3995e384477e087ed7d5b4ed48bb5dd0b6a78fdf7ac2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daa95d7fa296498252bd833106fddd6f08c21c1ce3fcc3aa8afa2e79d30d04e914bdc978cafa13d436b5364d91d9467f568d210d86d5d948a0500be3de7b2c8a
|
7
|
+
data.tar.gz: 757d9829c35ab58512093f0940f1f5d02aef11b23f94523a09878eeb82b717f047e83936b867aa60f34fa8ce9da2aca45d1be8ecf8bb9cad6b4c8de5b047b723
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -219,12 +219,13 @@ metrics_request = {
|
|
219
219
|
}
|
220
220
|
|
221
221
|
# OPTIONAL: You can pass a custom function to "compact" insertions before metrics logging.
|
222
|
-
# Note that the PromotedClient has a class method helper,
|
223
|
-
|
224
|
-
|
225
|
-
|
222
|
+
# Note that the PromotedClient has a class method helper, remove_all_properties, that does
|
223
|
+
# an implementation of this, returning nil to remove ALL properties.
|
224
|
+
to_compact_metrics_properties_func = Proc.new do |properties|
|
225
|
+
properties[:struct].delete(:active)
|
226
|
+
properties
|
226
227
|
end
|
227
|
-
# metrics_request[:
|
228
|
+
# metrics_request[:to_compact_metrics_properties_func] = to_compact_metrics_properties_func
|
228
229
|
|
229
230
|
# Create a client
|
230
231
|
client = Promoted::Ruby::Client::PromotedClient.new
|
data/dev.md
CHANGED
@@ -4,5 +4,5 @@
|
|
4
4
|
2. Get credentials for deployment from 1password.
|
5
5
|
3. Modify `promoted-ruby-client.gemspec`'s push block.
|
6
6
|
4. Run `gem build promoted-ruby-client.gemspec` to generate `gem`.
|
7
|
-
5. Run (using new output) `gem push promoted-ruby-client-0.1.
|
7
|
+
5. Run (using new output) `gem push promoted-ruby-client-0.1.17.gem`
|
8
8
|
6. Update README with new version.
|
data/lib/promoted/ruby/client.rb
CHANGED
@@ -30,12 +30,10 @@ module Promoted
|
|
30
30
|
end
|
31
31
|
|
32
32
|
##
|
33
|
-
# A common compact method implementation.
|
34
|
-
def self.
|
35
|
-
Proc.new do |
|
36
|
-
|
37
|
-
insertion.delete(:properties)
|
38
|
-
insertion
|
33
|
+
# A common compact properties method implementation.
|
34
|
+
def self.remove_all_properties
|
35
|
+
Proc.new do |properties|
|
36
|
+
nil
|
39
37
|
end
|
40
38
|
end
|
41
39
|
|
@@ -115,7 +113,7 @@ module Promoted
|
|
115
113
|
##
|
116
114
|
# Make a delivery request. If @perform_checks is set, input validation will occur and possibly raise errors.
|
117
115
|
def deliver args, headers={}
|
118
|
-
args = Promoted::Ruby::Client::Util.
|
116
|
+
args = Promoted::Ruby::Client::Util.translate_hash(args)
|
119
117
|
|
120
118
|
# Respect the enabled state
|
121
119
|
if !@enabled
|
@@ -221,7 +219,7 @@ module Promoted
|
|
221
219
|
# Generate a log request for a subsequent call to send_log_request
|
222
220
|
# or for logging via alternative means.
|
223
221
|
def prepare_for_logging args, headers={}
|
224
|
-
args = Promoted::Ruby::Client::Util.
|
222
|
+
args = Promoted::Ruby::Client::Util.translate_hash(args)
|
225
223
|
|
226
224
|
if !@enabled
|
227
225
|
return {
|
@@ -334,7 +332,7 @@ module Promoted
|
|
334
332
|
delivery_request_builder = RequestBuilder.new
|
335
333
|
delivery_request_builder.set_request_params args
|
336
334
|
|
337
|
-
delivery_request_params = delivery_request_builder.delivery_request_params
|
335
|
+
delivery_request_params = delivery_request_builder.delivery_request_params
|
338
336
|
delivery_request_params[:client_info][:traffic_type] = Promoted::Ruby::Client::TRAFFIC_TYPE['SHADOW']
|
339
337
|
|
340
338
|
# Call Delivery API and log/ignore errors.
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'faraday'
|
2
2
|
require 'faraday_middleware'
|
3
|
+
require 'promoted/ruby/client/util'
|
3
4
|
|
4
5
|
module Promoted
|
5
6
|
module Ruby
|
@@ -28,7 +29,7 @@ module Promoted
|
|
28
29
|
|
29
30
|
norm_headers = response.headers.transform_keys(&:downcase)
|
30
31
|
if norm_headers["content-type"] != nil && norm_headers["content-type"].start_with?("application/json")
|
31
|
-
JSON.parse(response.body
|
32
|
+
Promoted::Ruby::Client::Util.translate_hash(JSON.parse(response.body))
|
32
33
|
else
|
33
34
|
response.body
|
34
35
|
end
|
@@ -3,8 +3,8 @@ module Promoted
|
|
3
3
|
module Client
|
4
4
|
class RequestBuilder
|
5
5
|
attr_reader :session_id, :only_log, :experiment, :client_info,
|
6
|
-
:view_id, :insertion, :
|
7
|
-
:request_id, :full_insertion, :use_case, :request, :
|
6
|
+
:view_id, :insertion, :to_compact_delivery_properties_func,
|
7
|
+
:request_id, :full_insertion, :use_case, :request, :to_compact_metrics_properties_func
|
8
8
|
|
9
9
|
attr_accessor :timing, :user_info, :platform_id
|
10
10
|
|
@@ -29,8 +29,8 @@ module Promoted
|
|
29
29
|
@full_insertion = args[:full_insertion]
|
30
30
|
@user_info = request[:user_info] || { :user_id => nil, :log_user_id => nil}
|
31
31
|
@timing = request[:timing] || { :client_log_timestamp => Time.now.to_i }
|
32
|
-
@
|
33
|
-
@
|
32
|
+
@to_compact_metrics_properties_func = args[:to_compact_metrics_properties_func]
|
33
|
+
@to_compact_delivery_properties_func = args[:to_compact_delivery_properties_func]
|
34
34
|
|
35
35
|
# If the user didn't create a client request id, we do it for them.
|
36
36
|
request[:client_request_id] = request[:client_request_id] || @id_generator.newID
|
@@ -52,7 +52,7 @@ module Promoted
|
|
52
52
|
end
|
53
53
|
|
54
54
|
# Only used in delivery
|
55
|
-
def delivery_request_params
|
55
|
+
def delivery_request_params
|
56
56
|
params = {
|
57
57
|
user_info: user_info,
|
58
58
|
timing: timing,
|
@@ -66,7 +66,7 @@ module Promoted
|
|
66
66
|
paging: request[:paging],
|
67
67
|
client_request_id: request[:client_request_id]
|
68
68
|
}
|
69
|
-
params[:insertion] =
|
69
|
+
params[:insertion] = insertions_with_compact_props(@to_compact_delivery_properties_func)
|
70
70
|
|
71
71
|
params.clean!
|
72
72
|
end
|
@@ -80,7 +80,10 @@ module Promoted
|
|
80
80
|
end
|
81
81
|
|
82
82
|
props = @full_insertion.each_with_object({}) do |insertion, hash|
|
83
|
-
|
83
|
+
if insertion.has_key?(:properties)
|
84
|
+
# Don't add nil properties to response insertions.
|
85
|
+
hash[insertion[:content_id]] = insertion[:properties]
|
86
|
+
end
|
84
87
|
end
|
85
88
|
|
86
89
|
filled_in_copy = []
|
@@ -113,18 +116,33 @@ module Promoted
|
|
113
116
|
end
|
114
117
|
|
115
118
|
if include_insertions
|
116
|
-
params[:insertion] =
|
119
|
+
params[:insertion] = compact_metrics_properties if include_insertions
|
117
120
|
add_missing_ids_on_insertions! request, params[:insertion]
|
118
121
|
end
|
119
122
|
|
120
123
|
params.clean!
|
121
124
|
end
|
122
125
|
|
123
|
-
def
|
124
|
-
if
|
126
|
+
def compact_one_insertion(insertion, compact_func)
|
127
|
+
return insertion if (!compact_func || !insertion[:properties])
|
128
|
+
|
129
|
+
# Only need a copy if there are properties to compact.
|
130
|
+
compact_insertion = insertion.dup
|
131
|
+
compact_insertion[:properties] = compact_func.call(insertion[:properties])
|
132
|
+
compact_insertion.clean!
|
133
|
+
return compact_insertion
|
134
|
+
end
|
135
|
+
|
136
|
+
def insertions_with_compact_props(compact_func)
|
137
|
+
if !compact_func
|
138
|
+
# Nothing to do, avoid copying the whole array.
|
125
139
|
full_insertion
|
126
140
|
else
|
127
|
-
|
141
|
+
compact_insertions = Array.new(full_insertion.length)
|
142
|
+
full_insertion.each_with_index {|insertion, index|
|
143
|
+
compact_insertions[index] = compact_one_insertion(insertion, compact_func)
|
144
|
+
}
|
145
|
+
compact_insertions
|
128
146
|
end
|
129
147
|
end
|
130
148
|
|
@@ -135,7 +153,7 @@ module Promoted
|
|
135
153
|
end
|
136
154
|
|
137
155
|
# TODO: This looks overly complicated.
|
138
|
-
def
|
156
|
+
def compact_metrics_properties
|
139
157
|
@insertion = [] # insertion should be set according to the compact insertion
|
140
158
|
paging = request[:paging] || {}
|
141
159
|
size = paging[:size] ? paging[:size].to_i : 0
|
@@ -155,7 +173,7 @@ module Promoted
|
|
155
173
|
insertion_obj[:insertion_id] = @id_generator.newID
|
156
174
|
insertion_obj[:request_id] = request_id
|
157
175
|
insertion_obj[:position] = offset + index
|
158
|
-
insertion_obj =
|
176
|
+
insertion_obj = compact_one_insertion(insertion_obj, @to_compact_metrics_properties_func)
|
159
177
|
@insertion << insertion_obj.clean!
|
160
178
|
end
|
161
179
|
@insertion
|
@@ -2,16 +2,39 @@ module Promoted
|
|
2
2
|
module Ruby
|
3
3
|
module Client
|
4
4
|
module Util
|
5
|
-
def self.
|
5
|
+
def self.translate_array(arr)
|
6
|
+
sym_arr = Array.new(arr.length)
|
7
|
+
arr.each_with_index do |v, i|
|
8
|
+
new_v = v
|
9
|
+
case v
|
10
|
+
when Hash
|
11
|
+
new_v = translate_hash(v)
|
12
|
+
when Array
|
13
|
+
new_v = translate_array(v)
|
14
|
+
end
|
15
|
+
sym_arr[i] = new_v
|
16
|
+
end
|
17
|
+
sym_arr
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.translate_hash(args)
|
6
21
|
sym_hash = {}
|
7
22
|
args.each do |k, v|
|
8
|
-
|
23
|
+
new_key = k.to_s.to_underscore.to_sym
|
24
|
+
case v
|
25
|
+
when Hash
|
26
|
+
sym_hash[new_key] = translate_hash(v)
|
27
|
+
when Array
|
28
|
+
sym_hash[new_key] = translate_array(v)
|
29
|
+
else
|
30
|
+
sym_hash[new_key] = v
|
31
|
+
end
|
9
32
|
end
|
10
33
|
sym_hash
|
11
34
|
rescue => e
|
12
35
|
raise 'Unable to parse args. Please pass correct arguments. Must be JSON'
|
13
36
|
end
|
14
|
-
|
37
|
+
end
|
15
38
|
end
|
16
39
|
end
|
17
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: promoted-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- scottmcmaster
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|