promoted-ruby-client 4.0.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/dev.md +1 -1
- data/lib/promoted/ruby/client/pager.rb +25 -16
- data/lib/promoted/ruby/client/validator.rb +5 -1
- data/lib/promoted/ruby/client/version.rb +1 -1
- data/lib/promoted/ruby/client.rb +11 -11
- 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: 3b71559ca253efcd620dbbc41ccd95dc17f479a4d9efe3241565038edee43acb
|
4
|
+
data.tar.gz: cfb8da8803830124ea5c6147d83150c05d14068518b0d45285528096925a62a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20717e1151bb52bb1917456ee22a8e73382b7e8ca0fb33d1aad73f2150e3533837b5ce0c20464a65d1988398be27218af2884eb16227a1a8660a47c600f4d220
|
7
|
+
data.tar.gz: 8d4dff6877a2d28dca45c17116292ef6a2c78e2f6e78b4a255b52c1f3c1aab5fb7daaa62d80655f2e6c90527eff44840f27fe85aef04ac85938710f7ef9a738d
|
data/Gemfile.lock
CHANGED
data/dev.md
CHANGED
@@ -11,4 +11,4 @@ bundle exec rspec
|
|
11
11
|
3. Modify `promoted-ruby-client.gemspec`'s push block.
|
12
12
|
4. Run `gem build promoted-ruby-client.gemspec` to generate `gem`.
|
13
13
|
5. Run `bundle exec rspec`. This updates `Gemfile.lock`.
|
14
|
-
6. Run (using new output) `gem push promoted-ruby-client-
|
14
|
+
6. Run (using new output) `gem push promoted-ruby-client-5.0.0.gem`
|
@@ -13,24 +13,28 @@ module Promoted
|
|
13
13
|
class Pager
|
14
14
|
def validate_paging(insertions, retrieval_insertion_offset, paging)
|
15
15
|
if paging && paging[:offset]
|
16
|
-
offset =
|
17
|
-
|
18
|
-
raise InvalidPagingError.new("Invalid page offset (insertion size #{insertions.length}, offset #{offset})", [])
|
19
|
-
end
|
20
|
-
if offset < retrieval_insertion_offset
|
21
|
-
raise InvalidPagingError.new("Invalid page offset (retrieval_insertion_offset #{retrieval_insertion_offset}, offset #{offset})", [])
|
22
|
-
end
|
16
|
+
offset, retrieval_insertion_offset, index = _sanitize_offsets(retrieval_insertion_offset, paging)
|
17
|
+
_validate_paging(insertions, retrieval_insertion_offset, offset, index)
|
23
18
|
end
|
24
19
|
end
|
25
20
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
21
|
+
def _sanitize_offsets(retrieval_insertion_offset, paging)
|
22
|
+
offset = [0, paging[:offset]].max
|
23
|
+
retrieval_insertion_offset = [0, retrieval_insertion_offset].max
|
24
|
+
index = [0, offset - retrieval_insertion_offset].max
|
25
|
+
return [offset, retrieval_insertion_offset, index]
|
26
|
+
end
|
27
|
+
|
28
|
+
def _validate_paging(insertions, retrieval_insertion_offset, offset, index)
|
29
|
+
if offset < retrieval_insertion_offset
|
30
|
+
raise InvalidPagingError.new("Invalid page offset (retrieval_insertion_offset #{retrieval_insertion_offset}, offset #{offset})", [])
|
31
|
+
end
|
32
|
+
if index >= insertions.length
|
33
|
+
raise InvalidPagingError.new("Invalid page offset (insertion size #{insertions.length}, index #{index})", [])
|
32
34
|
end
|
35
|
+
end
|
33
36
|
|
37
|
+
def apply_paging(insertions, retrieval_insertion_offset, paging = nil)
|
34
38
|
if !paging
|
35
39
|
paging = {
|
36
40
|
:offset => 0,
|
@@ -38,9 +42,14 @@ module Promoted
|
|
38
42
|
}
|
39
43
|
end
|
40
44
|
|
41
|
-
offset =
|
42
|
-
|
43
|
-
|
45
|
+
offset, retrieval_insertion_offset, index = _sanitize_offsets(retrieval_insertion_offset, paging)
|
46
|
+
|
47
|
+
begin
|
48
|
+
_validate_paging(insertions, retrieval_insertion_offset, offset, index)
|
49
|
+
rescue InvalidPagingError => err
|
50
|
+
# This is invalid input, stop it before it goes to the server.
|
51
|
+
return err.default_insertions_page
|
52
|
+
end
|
44
53
|
|
45
54
|
size = paging[:size]
|
46
55
|
if size <= 0
|
@@ -135,7 +135,7 @@ module Promoted
|
|
135
135
|
end
|
136
136
|
|
137
137
|
# TODO - delete?
|
138
|
-
def
|
138
|
+
def validate_delivery_args!(metrics_req)
|
139
139
|
validate_fields!(
|
140
140
|
metrics_req,
|
141
141
|
"metrics request",
|
@@ -143,6 +143,10 @@ module Promoted
|
|
143
143
|
{
|
144
144
|
:name => :request,
|
145
145
|
:required => true
|
146
|
+
},
|
147
|
+
{
|
148
|
+
:name => :retrieval_insertion_offset,
|
149
|
+
:type => Integer
|
146
150
|
}
|
147
151
|
]
|
148
152
|
)
|
data/lib/promoted/ruby/client.rb
CHANGED
@@ -54,7 +54,6 @@ module Promoted
|
|
54
54
|
|
55
55
|
@sampler = Sampler.new
|
56
56
|
@pager = Pager.new
|
57
|
-
@retrieval_insertion_offset = params[:retrieval_insertion_offset] || 0
|
58
57
|
|
59
58
|
# HTTP Client creation
|
60
59
|
@delivery_endpoint = params[:delivery_endpoint] || DEFAULT_DELIVERY_ENDPOINT
|
@@ -116,11 +115,12 @@ module Promoted
|
|
116
115
|
# Make a delivery request. If @perform_checks is set, input validation will occur and possibly raise errors.
|
117
116
|
def deliver args, headers={}
|
118
117
|
args = Promoted::Ruby::Client::Util.translate_hash(args)
|
118
|
+
retrieval_insertion_offset = args[:retrieval_insertion_offset] || 0
|
119
119
|
|
120
120
|
# Respect the enabled state
|
121
121
|
if !@enabled
|
122
122
|
return {
|
123
|
-
insertion: @pager.apply_paging(args[:request][:insertion],
|
123
|
+
insertion: @pager.apply_paging(args[:request][:insertion], retrieval_insertion_offset, args[:request][:paging])
|
124
124
|
# No log request returned when disabled
|
125
125
|
}
|
126
126
|
end
|
@@ -152,7 +152,7 @@ module Promoted
|
|
152
152
|
end
|
153
153
|
|
154
154
|
begin
|
155
|
-
@pager.validate_paging(delivery_request_builder.insertion,
|
155
|
+
@pager.validate_paging(delivery_request_builder.insertion, retrieval_insertion_offset, delivery_request_builder.request[:paging])
|
156
156
|
rescue InvalidPagingError => err
|
157
157
|
# Invalid input, log and do SDK-side delivery.
|
158
158
|
@logger.warn(err) if @logger
|
@@ -194,7 +194,7 @@ module Promoted
|
|
194
194
|
end
|
195
195
|
|
196
196
|
if !insertions_from_delivery then
|
197
|
-
response_insertions = build_sdk_response_insertions(delivery_request_builder)
|
197
|
+
response_insertions = build_sdk_response_insertions(delivery_request_builder, retrieval_insertion_offset)
|
198
198
|
end
|
199
199
|
|
200
200
|
log_req = nil
|
@@ -239,8 +239,8 @@ module Promoted
|
|
239
239
|
|
240
240
|
##
|
241
241
|
# Creates response insertions for SDK-side delivery, when we don't get response insertions from Delivery API.
|
242
|
-
def build_sdk_response_insertions delivery_request_builder
|
243
|
-
response_insertions = @pager.apply_paging(delivery_request_builder.insertion,
|
242
|
+
def build_sdk_response_insertions delivery_request_builder, retrieval_insertion_offset
|
243
|
+
response_insertions = @pager.apply_paging(delivery_request_builder.insertion, retrieval_insertion_offset, delivery_request_builder.request[:paging])
|
244
244
|
delivery_request_builder.add_missing_insertion_ids! response_insertions
|
245
245
|
return response_insertions
|
246
246
|
end
|
@@ -317,7 +317,7 @@ module Promoted
|
|
317
317
|
delivery_request_params[:client_info][:traffic_type] = Promoted::Ruby::Client::TRAFFIC_TYPE['SHADOW']
|
318
318
|
|
319
319
|
begin
|
320
|
-
@pager.validate_paging(delivery_request_builder.insertion,
|
320
|
+
@pager.validate_paging(delivery_request_builder.insertion, args[:retrieval_insertion_offset], delivery_request_builder.request[:paging])
|
321
321
|
rescue InvalidPagingError => err
|
322
322
|
# Invalid input, log and skip.
|
323
323
|
@logger.warn("Shadow traffic call failed with invalid paging #{err}") if @logger
|
@@ -344,11 +344,11 @@ module Promoted
|
|
344
344
|
end
|
345
345
|
end
|
346
346
|
|
347
|
-
def perform_common_checks!(
|
347
|
+
def perform_common_checks!(delivery_args)
|
348
348
|
begin
|
349
|
-
@validator.check_that_log_ids_not_set!(
|
350
|
-
@validator.
|
351
|
-
@validator.check_that_content_ids_are_set!(
|
349
|
+
@validator.check_that_log_ids_not_set!(delivery_args)
|
350
|
+
@validator.validate_delivery_args!(delivery_args)
|
351
|
+
@validator.check_that_content_ids_are_set!(delivery_args)
|
352
352
|
rescue StandardError => err
|
353
353
|
@logger.error(err) if @logger
|
354
354
|
raise
|
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:
|
4
|
+
version: 5.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- scottmcmaster
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-09-
|
11
|
+
date: 2023-09-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|