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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dd16c8da8348a5df3c47886020f1193f106f316cfe258d46bfa3b2eaf9a3517c
4
- data.tar.gz: adda4a48b4e65b76f6ffa4c33b310838e06b784cf3b7bbf967ce6f11bc9e61c2
3
+ metadata.gz: e1a10b55da67455d7850300f6b1da3a3b4321a008df2986bf2de8dc53d05b5e2
4
+ data.tar.gz: f74e861ce703df28b9ac771fa6fcaac96b8d6f2c1be2a725c0425f2fe9d240c9
5
5
  SHA512:
6
- metadata.gz: d147c287a7cc8a4a0476d2c0414229f5e3ffde35b8c6e2aed3bab018323a2d18c4f983cb265cbe800a823d29d77f0c23bdbc5b6c2cf344082299bcd229566113
7
- data.tar.gz: b496919bea856baa8b6ce2749a4c36b94542fabfcc77fc895f6b05f1d0bfd70b83c266ac56aa636965e338f09fe2994ab39ef86da2b3f7faed4796f706b16b15
6
+ metadata.gz: 9fc9818fcecb399918332e5624b753cd7bf74030d4f460b1939f7e8c7859ed2fdd55c2d4d0e18448153f4b284e0c770f22a94feb73def6ab0c8afd487f319afb
7
+ data.tar.gz: b6e3e18834d04dfd7548aa86837a2e322d519237635998077aa12f699454d0a0db5e5bf1deb2fbff6fe50246d57eb0c47b53c018e65a9275574b1e510cb79ee3
@@ -46,8 +46,6 @@ jobs:
46
46
  --out /tmp/test-results/rspec.xml \
47
47
  --format progress
48
48
 
49
- - run: bundle exec codeclimate-test-reporter
50
-
51
49
  - store_test_results:
52
50
  path: /tmp/test-results
53
51
 
data/Gemfile CHANGED
@@ -5,7 +5,6 @@ source 'https://rubygems.org'
5
5
  gemspec
6
6
 
7
7
  group :development, :test do
8
- gem 'codeclimate-test-reporter', require: false
9
8
  gem 'rspec_junit_formatter'
10
9
  gem 'rubocop-ci', git: 'https://github.com/ComboStrikeHQ/rubocop-ci'
11
10
  gem 'simplecov'
@@ -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('../../api.yml', __FILE__)))
31
+ API_CONFIG = YAML.safe_load(File.read(File.expand_path('../api.yml', __dir__)))
32
32
  NET_TIMEOUT = 600
33
33
  end
@@ -239,6 +239,7 @@ module SoapyCake
239
239
 
240
240
  def apply_tag_opts(opts)
241
241
  return opts unless opts[:tags]
242
+
242
243
  opts = apply_tag_modification_type(opts)
243
244
  opts[:tags] = Array(opts[:tags]).join(',')
244
245
  opts
@@ -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), fetch_opt(:time_offset))
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
- raise InvalidInput,
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)
@@ -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
 
@@ -55,6 +55,7 @@ module SoapyCake
55
55
  unless value.nil? || numeric?
56
56
  raise Error, "'#{key}' contains non-digit chars but was to be parsed as an integer id"
57
57
  end
58
+
58
59
  value.to_i
59
60
  end
60
61
  end
@@ -2,15 +2,7 @@
2
2
 
3
3
  module SoapyCake
4
4
  class TimeConverter
5
- def initialize(time_zone, time_offset = nil)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SoapyCake
4
- VERSION = '2.2.7'
4
+ VERSION = '2.3.0'
5
5
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'soapy_cake/version'
6
6
 
@@ -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) { instance_double(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
- .with(:admin, :addedit, :offer,
31
- hash_including(tags: 'new-tag', tags_modification_type: 'add'))
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
- .with(:admin, :addedit, :offer,
39
- hash_including(tags: 'new-tag', tags_modification_type: 'replace'))
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
- .with(:admin, :addedit, :offer,
83
- hash_including(tags: 'tag', tags_modification_type: 'add'))
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
- .with(:admin, :addedit, :geo_targets,
101
- hash_including(add_edit_option: 'replace'))
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
- .with(:admin, :addedit, :geo_targets,
109
- hash_including(add_edit_option: 'add'))
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
- .with(:admin, :addedit, :geo_targets,
135
- hash_including(add_edit_option: 'add'))
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
- .to receive(:new)
162
- .with(
163
- :admin,
164
- :addedit,
165
- :creative,
166
- creative_name: 'creative_name',
167
- creative_status_id: 1,
168
- creative_type_id: 3,
169
- height: 0,
170
- notes: '',
171
- offer_link: '',
172
- third_party_name: '',
173
- width: 0,
174
- offer_id: 10
175
- )
176
- .and_call_original
177
-
178
- expect(SoapyCake::Request)
179
- .to receive(:new)
180
- .with(
181
- :admin,
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.2.7
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-01-20 00:00:00.000000000 Z
11
+ date: 2020-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport