soapy_cake 2.2.7 → 2.3.0
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/.circleci/config.yml +0 -2
- data/Gemfile +0 -1
- data/lib/soapy_cake.rb +1 -1
- data/lib/soapy_cake/admin_addedit.rb +1 -0
- data/lib/soapy_cake/client.rb +5 -3
- data/lib/soapy_cake/modification_type.rb +4 -1
- data/lib/soapy_cake/response.rb +2 -0
- data/lib/soapy_cake/response_value.rb +1 -0
- data/lib/soapy_cake/time_converter.rb +1 -16
- data/lib/soapy_cake/version.rb +1 -1
- data/soapy_cake.gemspec +1 -1
- data/spec/integration/soapy_cake/admin_spec.rb +8 -6
- data/spec/lib/soapy_cake/admin_addedit_spec.rb +58 -46
- data/spec/lib/soapy_cake/time_converter_spec.rb +0 -13
- 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: e1a10b55da67455d7850300f6b1da3a3b4321a008df2986bf2de8dc53d05b5e2
|
4
|
+
data.tar.gz: f74e861ce703df28b9ac771fa6fcaac96b8d6f2c1be2a725c0425f2fe9d240c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fc9818fcecb399918332e5624b753cd7bf74030d4f460b1939f7e8c7859ed2fdd55c2d4d0e18448153f4b284e0c770f22a94feb73def6ab0c8afd487f319afb
|
7
|
+
data.tar.gz: b6e3e18834d04dfd7548aa86837a2e322d519237635998077aa12f699454d0a0db5e5bf1deb2fbff6fe50246d57eb0c47b53c018e65a9275574b1e510cb79ee3
|
data/.circleci/config.yml
CHANGED
data/Gemfile
CHANGED
data/lib/soapy_cake.rb
CHANGED
@@ -28,6 +28,6 @@ require 'soapy_cake/modification_type'
|
|
28
28
|
require 'soapy_cake/campaigns'
|
29
29
|
|
30
30
|
module SoapyCake
|
31
|
-
API_CONFIG = YAML.safe_load(File.read(File.expand_path('
|
31
|
+
API_CONFIG = YAML.safe_load(File.read(File.expand_path('../api.yml', __dir__)))
|
32
32
|
NET_TIMEOUT = 600
|
33
33
|
end
|
data/lib/soapy_cake/client.rb
CHANGED
@@ -12,7 +12,7 @@ module SoapyCake
|
|
12
12
|
@api_key = fetch_opt(:api_key) || raise(Error, 'Cake API key missing')
|
13
13
|
@retry_count = fetch_opt(:retry_count, 4)
|
14
14
|
@write_enabled = ['yes', true].include?(fetch_opt(:write_enabled))
|
15
|
-
@time_converter = TimeConverter.new(fetch_opt(:time_zone)
|
15
|
+
@time_converter = TimeConverter.new(fetch_opt(:time_zone))
|
16
16
|
end
|
17
17
|
|
18
18
|
def xml_response?
|
@@ -53,6 +53,7 @@ module SoapyCake
|
|
53
53
|
|
54
54
|
def check_write_enabled!(request)
|
55
55
|
return if request.read_only? || write_enabled
|
56
|
+
|
56
57
|
raise Error, 'Writes not enabled (pass write_enabled: true or set CAKE_WRITE_ENABLED=yes)'
|
57
58
|
end
|
58
59
|
|
@@ -80,13 +81,14 @@ module SoapyCake
|
|
80
81
|
end
|
81
82
|
|
82
83
|
def http_response(request)
|
83
|
-
logger&.info("soapy_cake:request #{request}")
|
84
|
-
|
85
84
|
log_curl_command(request) if fetch_opt(:log_curl)
|
86
85
|
|
87
86
|
http_request = Net::HTTP::Post.new(request.path, HEADERS)
|
88
87
|
http_request.body = request.xml
|
88
|
+
t0 = Time.now
|
89
89
|
response = perform_http_request(http_request)
|
90
|
+
response_time = Time.now - t0
|
91
|
+
logger&.info("soapy_cake:request #{request} took: #{response_time.round(2)} s")
|
90
92
|
|
91
93
|
unless response.is_a?(Net::HTTPSuccess)
|
92
94
|
raise RequestFailed.new(
|
@@ -37,8 +37,11 @@ module SoapyCake
|
|
37
37
|
|
38
38
|
def validate_input(input_opts)
|
39
39
|
return unless input_opts[key].nil? && input_opts[modification_type_key] == CHANGE
|
40
|
-
|
40
|
+
|
41
|
+
raise(
|
42
|
+
InvalidInput,
|
41
43
|
"`#{modification_type_key}` was '#{CHANGE}', but no `#{key}` was provided to change it to"
|
44
|
+
)
|
42
45
|
end
|
43
46
|
|
44
47
|
InvalidInput = Class.new(StandardError)
|
data/lib/soapy_cake/response.rb
CHANGED
@@ -59,6 +59,7 @@ module SoapyCake
|
|
59
59
|
|
60
60
|
error_check_fault!
|
61
61
|
return if error_check_special_case?
|
62
|
+
|
62
63
|
error_check_success!
|
63
64
|
end
|
64
65
|
|
@@ -70,6 +71,7 @@ module SoapyCake
|
|
70
71
|
def error_check_success!
|
71
72
|
return if sax.for_tag(:success).first == 'true'
|
72
73
|
raise RateLimitError if error_message == 'Restricted'
|
74
|
+
|
73
75
|
raise RequestFailed, error_message
|
74
76
|
end
|
75
77
|
|
@@ -2,15 +2,7 @@
|
|
2
2
|
|
3
3
|
module SoapyCake
|
4
4
|
class TimeConverter
|
5
|
-
def initialize(time_zone
|
6
|
-
if time_offset
|
7
|
-
self.class.print_deprecation_warning
|
8
|
-
|
9
|
-
# Etc/GMT time zones have their sign reversed
|
10
|
-
time_zone = format('Etc/GMT%+d', -time_offset.to_i)
|
11
|
-
end
|
12
|
-
|
13
|
-
raise Error, 'Cake time zone missing' if time_zone.blank?
|
5
|
+
def initialize(time_zone)
|
14
6
|
@zone = ActiveSupport::TimeZone[time_zone]
|
15
7
|
end
|
16
8
|
|
@@ -23,13 +15,6 @@ module SoapyCake
|
|
23
15
|
zone.parse(value).utc
|
24
16
|
end
|
25
17
|
|
26
|
-
def self.print_deprecation_warning
|
27
|
-
return if @deprecation_warning_printed
|
28
|
-
@deprecation_warning_printed = true
|
29
|
-
|
30
|
-
STDERR.puts 'SoapyCake - DEPRECATED: Please use time_zone instead of time_offset.'
|
31
|
-
end
|
32
|
-
|
33
18
|
private
|
34
19
|
|
35
20
|
attr_reader :zone
|
data/lib/soapy_cake/version.rb
CHANGED
data/soapy_cake.gemspec
CHANGED
@@ -3,17 +3,19 @@
|
|
3
3
|
RSpec.describe SoapyCake::Admin do
|
4
4
|
around { |example| Timecop.freeze(Time.utc(2015, 6, 15, 12), &example) }
|
5
5
|
|
6
|
-
let(:logger) {
|
7
|
-
|
8
|
-
before { allow(logger).to receive(:info) }
|
6
|
+
let(:logger) { instance_spy(Logger) }
|
9
7
|
|
10
8
|
subject(:admin) { described_class.new(logger: logger) }
|
11
9
|
|
12
10
|
it 'returns an affiliate with correct data types', :vcr do
|
13
|
-
expect(logger).to receive(:info)
|
14
|
-
.with('soapy_cake:request admin:export:affiliates:5 {"affiliate_id":16027}')
|
15
|
-
|
16
11
|
result = admin.affiliates(affiliate_id: 16027)
|
12
|
+
|
13
|
+
expect(logger).to have_received(:info).with(
|
14
|
+
a_string_matching(
|
15
|
+
/soapy_cake:request admin:export:affiliates:5 {"affiliate_id":16027} took: \d+.\d+ s/
|
16
|
+
)
|
17
|
+
)
|
18
|
+
|
17
19
|
expect(result.count).to eq(1)
|
18
20
|
expect(result.first).to include(
|
19
21
|
affiliate_id: 16027,
|
@@ -26,17 +26,23 @@ RSpec.describe SoapyCake::AdminAddedit do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'keeps existing tags' do
|
29
|
-
expect(SoapyCake::Request).to receive(:new)
|
30
|
-
|
31
|
-
|
29
|
+
expect(SoapyCake::Request).to receive(:new).with(
|
30
|
+
:admin,
|
31
|
+
:addedit,
|
32
|
+
:offer,
|
33
|
+
hash_including(tags: 'new-tag', tags_modification_type: 'add')
|
34
|
+
)
|
32
35
|
|
33
36
|
admin_addedit.edit_offer(offer_params)
|
34
37
|
end
|
35
38
|
|
36
39
|
it 'allows replacing tags' do
|
37
|
-
expect(SoapyCake::Request).to receive(:new)
|
38
|
-
|
39
|
-
|
40
|
+
expect(SoapyCake::Request).to receive(:new).with(
|
41
|
+
:admin,
|
42
|
+
:addedit,
|
43
|
+
:offer,
|
44
|
+
hash_including(tags: 'new-tag', tags_modification_type: 'replace')
|
45
|
+
)
|
40
46
|
|
41
47
|
admin_addedit.edit_offer(offer_params.merge(tags_replace: true))
|
42
48
|
end
|
@@ -78,9 +84,12 @@ RSpec.describe SoapyCake::AdminAddedit do
|
|
78
84
|
end
|
79
85
|
|
80
86
|
it 'always adds on creation' do
|
81
|
-
expect(SoapyCake::Request).to receive(:new)
|
82
|
-
|
83
|
-
|
87
|
+
expect(SoapyCake::Request).to receive(:new).with(
|
88
|
+
:admin,
|
89
|
+
:addedit,
|
90
|
+
:offer,
|
91
|
+
hash_including(tags: 'tag', tags_modification_type: 'add')
|
92
|
+
)
|
84
93
|
|
85
94
|
admin_addedit.add_offer(offer_params.merge(tags: 'tag', tags_replace: true))
|
86
95
|
end
|
@@ -96,17 +105,23 @@ RSpec.describe SoapyCake::AdminAddedit do
|
|
96
105
|
end
|
97
106
|
|
98
107
|
it 'replaces the existing config by default' do
|
99
|
-
expect(SoapyCake::Request).to receive(:new)
|
100
|
-
|
101
|
-
|
108
|
+
expect(SoapyCake::Request).to receive(:new).with(
|
109
|
+
:admin,
|
110
|
+
:addedit,
|
111
|
+
:geo_targets,
|
112
|
+
hash_including(add_edit_option: 'replace')
|
113
|
+
)
|
102
114
|
|
103
115
|
admin_addedit.edit_geo_targets(base_opts)
|
104
116
|
end
|
105
117
|
|
106
118
|
it 'allows to override the add_edit_option' do
|
107
|
-
expect(SoapyCake::Request).to receive(:new)
|
108
|
-
|
109
|
-
|
119
|
+
expect(SoapyCake::Request).to receive(:new).with(
|
120
|
+
:admin,
|
121
|
+
:addedit,
|
122
|
+
:geo_targets,
|
123
|
+
hash_including(add_edit_option: 'add')
|
124
|
+
)
|
110
125
|
|
111
126
|
admin_addedit.edit_geo_targets(base_opts.merge(add_edit_option: 'add'))
|
112
127
|
end
|
@@ -130,9 +145,12 @@ RSpec.describe SoapyCake::AdminAddedit do
|
|
130
145
|
end
|
131
146
|
|
132
147
|
it 'adds geo targets' do
|
133
|
-
expect(SoapyCake::Request).to receive(:new)
|
134
|
-
|
135
|
-
|
148
|
+
expect(SoapyCake::Request).to receive(:new).with(
|
149
|
+
:admin,
|
150
|
+
:addedit,
|
151
|
+
:geo_targets,
|
152
|
+
hash_including(add_edit_option: 'add')
|
153
|
+
)
|
136
154
|
|
137
155
|
admin_addedit.add_geo_targets(base_opts)
|
138
156
|
end
|
@@ -157,34 +175,28 @@ RSpec.describe SoapyCake::AdminAddedit do
|
|
157
175
|
|
158
176
|
context 'when given the right parameters' do
|
159
177
|
it 'creates a creative and adds a file to it' do
|
160
|
-
expect(SoapyCake::Request)
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
.
|
180
|
-
|
181
|
-
|
182
|
-
:addedit,
|
183
|
-
:creative_files,
|
184
|
-
creative_file_import_url: 'http://www.example.org/image.png',
|
185
|
-
creative_id: nil
|
186
|
-
)
|
187
|
-
.and_call_original
|
178
|
+
expect(SoapyCake::Request).to receive(:new).with(
|
179
|
+
:admin,
|
180
|
+
:addedit,
|
181
|
+
:creative,
|
182
|
+
creative_name: 'creative_name',
|
183
|
+
creative_status_id: 1,
|
184
|
+
creative_type_id: 3,
|
185
|
+
height: 0,
|
186
|
+
notes: '',
|
187
|
+
offer_link: '',
|
188
|
+
third_party_name: '',
|
189
|
+
width: 0,
|
190
|
+
offer_id: 10
|
191
|
+
).and_call_original
|
192
|
+
|
193
|
+
expect(SoapyCake::Request).to receive(:new).with(
|
194
|
+
:admin,
|
195
|
+
:addedit,
|
196
|
+
:creative_files,
|
197
|
+
creative_file_import_url: 'http://www.example.org/image.png',
|
198
|
+
creative_id: nil
|
199
|
+
).and_call_original
|
188
200
|
|
189
201
|
admin_addedit.create_creative(
|
190
202
|
offer_id: 10,
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# rubocop:disable Style/DateTime
|
4
3
|
RSpec.describe SoapyCake::TimeConverter do
|
5
4
|
subject(:time_converter) { described_class.new('Europe/Berlin') }
|
6
5
|
|
@@ -26,16 +25,4 @@ RSpec.describe SoapyCake::TimeConverter do
|
|
26
25
|
.to eq(Time.utc(2015, 6, 11, 12, 53, 40))
|
27
26
|
end
|
28
27
|
end
|
29
|
-
|
30
|
-
context 'legacy mode / CAKE_TIME_OFFSET' do
|
31
|
-
subject(:time_converter) { described_class.new('Europe/Berlin', 5) }
|
32
|
-
|
33
|
-
it 'works as before (broken, without DST)' do
|
34
|
-
expect(STDERR).to receive(:puts).with(/Please use time_zone/)
|
35
|
-
|
36
|
-
expect(time_converter.to_cake(DateTime.new(2015, 1, 2, 12, 30))).to eq('2015-01-02T17:30:00')
|
37
|
-
expect(time_converter.to_cake(DateTime.new(2015, 6, 2, 12, 30))).to eq('2015-06-02T17:30:00')
|
38
|
-
end
|
39
|
-
end
|
40
28
|
end
|
41
|
-
# rubocop:enable Style/DateTime
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soapy_cake
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ad2games GmbH
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|