soapy_cake 1.11.5 → 1.11.6

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
  SHA1:
3
- metadata.gz: 90aab26ebb422cf0e5e2acbd44948a2314b0a90d
4
- data.tar.gz: 3875d9128e5cabcbfd05e3087ca54f074d6cc05d
3
+ metadata.gz: 7a5f8f5255750b90410b9dcbc2e66248a6545a30
4
+ data.tar.gz: ad7db8d775664b4d4ed965e94f6fed2e44f6f1ac
5
5
  SHA512:
6
- metadata.gz: 4a0ec1a818f34a0e3687b03e9ee2b38c94ede2de97dff7e3354da284a49bd1246ed95e9e4c36ffe9a8730cc58e17a5f3741a45c28dc384db88122774f43a2981
7
- data.tar.gz: 202628dd1eb5bd7035c972970e9f6d522290aa19d01de5267bcae54d7e53cdbb4c7289822aa159fe32e06c6855d88db4bb04c34e9a5a5f059ba329ce821e6249
6
+ metadata.gz: 723f7e27bf32c48db72bedf24e68d3ad601ae07e1ffe50d8301fe2c86ddd2b6851241a0db3979028ee41e601d984822179f8aa033df7b16cb11648d52141c115
7
+ data.tar.gz: e2c6a1717b5b4f6633cdc09eb052deee6506f78c6eabfd41bad45f59ed366935eebead9929cbc3491d3ef246bb8d51f202216668747ffa5c5f0261513d64fe50
data/circle.yml CHANGED
@@ -1,3 +1,6 @@
1
+ dependencies:
2
+ post:
3
+ - bundle update
1
4
  test:
2
5
  pre:
3
6
  - bundle exec rake rubocop
data/lib/soapy_cake.rb CHANGED
@@ -5,6 +5,7 @@ require 'active_support/core_ext/hash/reverse_merge'
5
5
  require 'active_support/core_ext/date'
6
6
  require 'active_support/core_ext/numeric/time'
7
7
  require 'active_support/core_ext/time/zones'
8
+ require 'active_support/core_ext/hash/transform_values'
8
9
 
9
10
  require 'soapy_cake/version'
10
11
  require 'soapy_cake/const'
@@ -35,7 +35,7 @@ module SoapyCake
35
35
  end
36
36
 
37
37
  def creatives(opts = {})
38
- translate_values!(opts, %i(creative_type_id creative_status_id))
38
+ opts = translate_values(opts, %i(creative_type_id creative_status_id))
39
39
 
40
40
  run Request.new(:admin, :export, :creatives, opts)
41
41
  end
@@ -78,7 +78,7 @@ module SoapyCake
78
78
 
79
79
  def caps(opts)
80
80
  require_params(opts, %i(start_date end_date))
81
- translate_values!(opts, %i(cap_type_id))
81
+ opts = translate_values(opts, %i(cap_type_id))
82
82
 
83
83
  run Request.new(:admin, :reports, :caps, opts)
84
84
  end
@@ -91,24 +91,27 @@ module SoapyCake
91
91
  require_params(opts, %i(offer_contract_id allow_countries))
92
92
 
93
93
  if opts[:allow_countries]
94
- geo_targets_allow_options!(opts)
94
+ opts = geo_targets_allow_options(opts)
95
95
  else
96
- geo_targets_redirect_options!(opts)
96
+ opts = geo_targets_redirect_options(opts)
97
97
  end
98
98
 
99
- opts.merge!(add_edit_option: 'add', set_targeting_to_geo: true)
99
+ opts = opts.merge(add_edit_option: 'add', set_targeting_to_geo: true)
100
100
 
101
101
  run Request.new(:admin, :addedit, :geo_targets, opts)
102
102
  end
103
103
 
104
- def geo_targets_allow_options!(opts)
104
+ def geo_targets_allow_options(opts)
105
105
  require_params(opts, %i(countries))
106
+ opts = opts.dup
106
107
  countries = Array(opts[:countries])
107
108
  opts[:countries] = countries.join(',')
108
109
  opts[:redirect_offer_contract_ids] = ([-1] * countries.count).join(',')
110
+ opts
109
111
  end
110
112
 
111
- def geo_targets_redirect_options!(opts)
113
+ def geo_targets_redirect_options(opts)
114
+ opts = opts.dup
112
115
  redirects = opts.delete(:redirects)
113
116
  unless redirects.is_a?(Hash) && redirects.keys.count > 0
114
117
  fail Error, "Parameter 'redirects' must be a COUNTRY=>REDIRECT_OFFER_CONTRACT_ID hash!"
@@ -116,6 +119,7 @@ module SoapyCake
116
119
 
117
120
  opts[:countries] = redirects.keys.join(',')
118
121
  opts[:redirect_offer_contract_ids] = redirects.values.join(',')
122
+ opts
119
123
  end
120
124
 
121
125
  def add_offer_contract(opts = {})
@@ -131,7 +135,7 @@ module SoapyCake
131
135
  def update_caps(opts)
132
136
  require_params(opts, %i(cap_type_id cap_interval_id cap_amount send_alert_only))
133
137
 
134
- translate_values!(opts, %i(cap_type_id cap_interval_id))
138
+ opts = translate_values(opts, %i(cap_type_id cap_interval_id))
135
139
 
136
140
  run Request.new(:admin, :addedit, :caps, opts)
137
141
  end
@@ -139,19 +143,18 @@ module SoapyCake
139
143
  def remove_caps(opts)
140
144
  require_params(opts, %i(cap_type_id))
141
145
 
142
- translate_values!(opts, %i(cap_type_id))
146
+ opts = translate_values(opts, %i(cap_type_id))
143
147
 
144
- opts.merge!(cap_interval_id: 0, cap_amount: -1, send_alert_only: false)
148
+ opts = opts.merge(cap_interval_id: 0, cap_amount: -1, send_alert_only: false)
145
149
  run Request.new(:admin, :addedit, :caps, opts)
146
150
  end
147
151
 
148
152
  def add_offer_tier(opts)
149
- require_params(opts, %i(offer_id tier_id price_format_id offer_contract_id status_id))
150
-
151
- opts.merge!(redirect_offer_contract_id: -1, add_edit_option: 'add')
152
- translate_values!(opts, %i(status_id price_format_id))
153
+ addedit_offer_tier('add', opts)
154
+ end
153
155
 
154
- run Request.new(:admin, :addedit, :offer_tiers, opts)
156
+ def edit_offer_tier(opts)
157
+ addedit_offer_tier('replace', opts)
155
158
  end
156
159
 
157
160
  def edit_affiliate(opts)
@@ -173,15 +176,24 @@ module SoapyCake
173
176
 
174
177
  private
175
178
 
176
- def apply_tag_opts!(opts)
177
- return unless opts[:tags]
179
+ def addedit_offer_tier(add_edit_option, opts)
180
+ require_params(opts, %i(offer_id tier_id price_format_id offer_contract_id status_id))
178
181
 
179
- apply_tag_modification_type!(opts)
182
+ opts = opts.merge(redirect_offer_contract_id: -1, add_edit_option: add_edit_option)
183
+ opts = translate_values(opts, %i(status_id price_format_id))
180
184
 
185
+ run Request.new(:admin, :addedit, :offer_tiers, opts)
186
+ end
187
+
188
+ def apply_tag_opts(opts)
189
+ return opts unless opts[:tags]
190
+ opts = apply_tag_modification_type(opts)
181
191
  opts[:tags] = Array(opts[:tags]).join(',')
192
+ opts
182
193
  end
183
194
 
184
- def apply_tag_modification_type!(opts)
195
+ def apply_tag_modification_type(opts)
196
+ opts = opts.dup
185
197
  opts[:tags_modification_type] =
186
198
  if opts[:tags].to_s == ''
187
199
  'remove_all'
@@ -190,6 +202,7 @@ module SoapyCake
190
202
  else
191
203
  'add'
192
204
  end
205
+ opts
193
206
  end
194
207
 
195
208
  def default_offer_options
@@ -203,10 +216,9 @@ module SoapyCake
203
216
  def addedit_offer(opts)
204
217
  require_params(opts, REQUIRED_OFFER_PARAMS)
205
218
 
206
- translate_booleans!(opts)
207
- apply_tag_opts!(opts)
208
-
209
- translate_values!(opts, %i(
219
+ opts = translate_booleans(opts)
220
+ opts = apply_tag_opts(opts)
221
+ opts = translate_values(opts, %i(
210
222
  currency_id offer_status_id offer_type_id price_format_id
211
223
  conversion_cap_behavior conversion_behavior_on_redirect
212
224
  ))
@@ -216,7 +228,7 @@ module SoapyCake
216
228
 
217
229
  def addedit_offer_contract(opts)
218
230
  require_params(opts, REQUIRED_OFFER_CONTRACT_PARAMS)
219
- translate_values!(opts, %i(price_format_id))
231
+ opts = translate_values(opts, %i(price_format_id))
220
232
 
221
233
  run Request.new(:admin, :addedit, :offer_contract, opts)
222
234
  end
@@ -224,9 +236,9 @@ module SoapyCake
224
236
  def addedit_campaign(opts)
225
237
  require_params(opts, %i(affiliate_id offer_id media_type_id account_status_id payout))
226
238
 
227
- translate_values!(opts, %i(account_status_id))
239
+ opts = translate_values(opts, %i(account_status_id))
228
240
 
229
- opts.reverse_merge!(
241
+ opts = opts.reverse_merge(
230
242
  display_link_type_id: 1,
231
243
  expiration_date: future_expiration_date
232
244
  )
@@ -28,7 +28,7 @@ module SoapyCake
28
28
  def to_enum
29
29
  Enumerator.new do |y|
30
30
  loop do
31
- result = admin.public_send(method, opts.merge(row_limit: limit, start_at_row: offset))
31
+ result = next_batch
32
32
  @offset += limit
33
33
  limit.times { y << result.next }
34
34
  end
@@ -40,6 +40,10 @@ module SoapyCake
40
40
 
41
41
  private
42
42
 
43
+ def next_batch
44
+ admin.public_send(method, opts.merge(row_limit: limit, start_at_row: offset))
45
+ end
46
+
43
47
  attr_reader :admin, :method, :opts, :offset, :limit
44
48
  end
45
49
 
@@ -53,7 +53,8 @@ module SoapyCake
53
53
  indefinite: 0,
54
54
  daily: 1,
55
55
  weekly: 2,
56
- monthly: 3
56
+ monthly: 3,
57
+ custom: 4
57
58
  },
58
59
  creative_type_id: {
59
60
  link: 1,
@@ -23,17 +23,23 @@ module SoapyCake
23
23
  end
24
24
  end
25
25
 
26
- def translate_booleans!(opts)
27
- opts.each do |k, v|
28
- opts[k] = 'on' if v == true
29
- opts[k] = 'off' if v == false
26
+ def translate_booleans(opts)
27
+ opts.transform_values do |v|
28
+ case v
29
+ when true then 'on'
30
+ when false then 'off'
31
+ else v
32
+ end
30
33
  end
31
34
  end
32
35
 
33
- def translate_values!(opts, params)
34
- params.each do |type|
35
- opts[type] = const_lookup(type, opts[type]) if opts.key?(type)
36
- end
36
+ def translate_values(opts, params)
37
+ opts.map do |k, v|
38
+ [
39
+ k,
40
+ params.include?(k) ? const_lookup(k, v) : v
41
+ ]
42
+ end.to_h
37
43
  end
38
44
 
39
45
  def const_lookup(type, key)
@@ -19,7 +19,7 @@ module SoapyCake
19
19
  xml['env'].Envelope(xml_namespaces) do
20
20
  xml.Header
21
21
  xml.Body do
22
- xml['cake'].send(method.camelize.to_sym) do
22
+ xml['cake'].public_send(method.camelize.to_sym) do
23
23
  xml_params(xml)
24
24
  end
25
25
  end
@@ -40,7 +40,7 @@ module SoapyCake
40
40
  def xml_params(xml)
41
41
  xml.api_key api_key
42
42
  opts.each do |k, v|
43
- xml.send(k.to_sym, format_param(v))
43
+ xml.public_send(k.to_sym, format_param(v))
44
44
  end
45
45
  end
46
46
 
@@ -1,3 +1,3 @@
1
1
  module SoapyCake
2
- VERSION = '1.11.5'
2
+ VERSION = '1.11.6'
3
3
  end
data/soapy_cake.gemspec CHANGED
@@ -1,5 +1,4 @@
1
1
  # coding: utf-8
2
- # rubocop:disable ExtraSpacing
3
2
  lib = File.expand_path('../lib', __FILE__)
4
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
4
  require 'soapy_cake/version'
@@ -12,14 +12,14 @@ http_interactions:
12
12
  <env:Body>
13
13
  <cake:Campaign>
14
14
  <cake:api_key>cake-api-key</cake:api_key>
15
+ <cake:display_link_type_id>1</cake:display_link_type_id>
16
+ <cake:expiration_date>2045-02-09T01:00:00</cake:expiration_date>
15
17
  <cake:affiliate_id>1</cake:affiliate_id>
16
18
  <cake:offer_id>8910</cake:offer_id>
17
19
  <cake:media_type_id>1</cake:media_type_id>
18
20
  <cake:account_status_id>1</cake:account_status_id>
19
21
  <cake:payout>1.23</cake:payout>
20
22
  <cake:campaign_id>0</cake:campaign_id>
21
- <cake:display_link_type_id>1</cake:display_link_type_id>
22
- <cake:expiration_date>2045-02-09T01:00:00</cake:expiration_date>
23
23
  </cake:Campaign>
24
24
  </env:Body>
25
25
  </env:Envelope>
@@ -12,14 +12,14 @@ http_interactions:
12
12
  <env:Body>
13
13
  <cake:Campaign>
14
14
  <cake:api_key>cake-api-key</cake:api_key>
15
+ <cake:display_link_type_id>1</cake:display_link_type_id>
16
+ <cake:expiration_date>2045-02-09T01:00:00</cake:expiration_date>
15
17
  <cake:campaign_id>123</cake:campaign_id>
16
18
  <cake:affiliate_id>1</cake:affiliate_id>
17
19
  <cake:offer_id>8910</cake:offer_id>
18
20
  <cake:media_type_id>1</cake:media_type_id>
19
21
  <cake:account_status_id>1</cake:account_status_id>
20
22
  <cake:payout>1.23</cake:payout>
21
- <cake:display_link_type_id>1</cake:display_link_type_id>
22
- <cake:expiration_date>2045-02-09T01:00:00</cake:expiration_date>
23
23
  </cake:Campaign>
24
24
  </env:Body>
25
25
  </env:Envelope>
@@ -0,0 +1,55 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://cake-partner-domain.com/api/1/addedit.asmx
6
+ body:
7
+ encoding: UTF-8
8
+ string: |
9
+ <?xml version="1.0"?>
10
+ <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:cake="http://cakemarketing.com/api/1/">
11
+ <env:Header/>
12
+ <env:Body>
13
+ <cake:OfferTiers>
14
+ <cake:api_key>cake-api-key</cake:api_key>
15
+ <cake:offer_id>8910</cake:offer_id>
16
+ <cake:offer_contract_id>1456</cake:offer_contract_id>
17
+ <cake:tier_id>4</cake:tier_id>
18
+ <cake:price_format_id>1</cake:price_format_id>
19
+ <cake:status_id>1</cake:status_id>
20
+ <cake:redirect_offer_contract_id>-1</cake:redirect_offer_contract_id>
21
+ <cake:add_edit_option>replace</cake:add_edit_option>
22
+ </cake:OfferTiers>
23
+ </env:Body>
24
+ </env:Envelope>
25
+ headers:
26
+ Content-Type:
27
+ - application/soap+xml;charset=UTF-8
28
+ response:
29
+ status:
30
+ code: 200
31
+ message: OK
32
+ headers:
33
+ Cache-Control:
34
+ - private, max-age=0
35
+ Content-Type:
36
+ - application/soap+xml; charset=utf-8
37
+ Server:
38
+ - Microsoft-IIS/8.5
39
+ X-Aspnet-Version:
40
+ - 4.0.30319
41
+ X-Powered-By:
42
+ - ASP.NET
43
+ Date:
44
+ - Wed, 19 Aug 2015 13:40:14 GMT
45
+ Content-Length:
46
+ - '447'
47
+ body:
48
+ encoding: UTF-8
49
+ string: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
50
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><OfferTiersResponse
51
+ xmlns="http://cakemarketing.com/api/1/"><OfferTiersResult><success>true</success><message>Offer
52
+ Tier Replaced</message><row_count>0</row_count></OfferTiersResult></OfferTiersResponse></soap:Body></soap:Envelope>
53
+ http_version:
54
+ recorded_at: Tue, 17 Feb 2015 12:00:00 GMT
55
+ recorded_with: VCR 2.9.0
@@ -241,6 +241,18 @@ RSpec.describe SoapyCake::AdminAddedit do
241
241
 
242
242
  expect(result[:message]).to eq('Offer Tier Added')
243
243
  end
244
+
245
+ it 'edits an offer tier', :vcr do
246
+ result = subject.edit_offer_tier(
247
+ offer_id: offer_id,
248
+ offer_contract_id: offer_contract_id,
249
+ tier_id: tier_id,
250
+ price_format_id: :cpa,
251
+ status_id: :public
252
+ )
253
+
254
+ expect(result[:message]).to eq('Offer Tier Replaced')
255
+ end
244
256
  end
245
257
 
246
258
  describe 'campaigns' do
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
- require 'codeclimate-test-reporter'
2
- CodeClimate::TestReporter.start
1
+ if ENV['CODECLIMATE_REPO_TOKEN']
2
+ require 'codeclimate-test-reporter'
3
+ CodeClimate::TestReporter.start
4
+ end
3
5
  require 'bundler/setup'
4
6
  Bundler.require(:default, :development)
5
7
  require 'soapy_cake'
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: 1.11.5
4
+ version: 1.11.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - ad2games GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-16 00:00:00.000000000 Z
11
+ date: 2015-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -211,6 +211,7 @@ files:
211
211
  - spec/fixtures/vcr_cassettes/SoapyCake_AdminAddedit/offer_contracts/creates_an_offer_contract.yml
212
212
  - spec/fixtures/vcr_cassettes/SoapyCake_AdminAddedit/offer_contracts/updates_an_offer_contract.yml
213
213
  - spec/fixtures/vcr_cassettes/SoapyCake_AdminAddedit/offer_tiers/adds_an_offer_tier.yml
214
+ - spec/fixtures/vcr_cassettes/SoapyCake_AdminAddedit/offer_tiers/edits_an_offer_tier.yml
214
215
  - spec/fixtures/vcr_cassettes/SoapyCake_AdminAddedit/offers/creates_an_offer.yml
215
216
  - spec/fixtures/vcr_cassettes/SoapyCake_AdminAddedit/offers/updates_an_offer.yml
216
217
  - spec/fixtures/vcr_cassettes/SoapyCake_AdminTrack/_mass_conversion_insert/insers_conversions.yml
@@ -247,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
247
248
  version: '0'
248
249
  requirements: []
249
250
  rubyforge_project:
250
- rubygems_version: 2.4.5
251
+ rubygems_version: 2.4.8
251
252
  signing_key:
252
253
  specification_version: 4
253
254
  summary: Simple client for the CAKE API
@@ -268,6 +269,7 @@ test_files:
268
269
  - spec/fixtures/vcr_cassettes/SoapyCake_AdminAddedit/offer_contracts/creates_an_offer_contract.yml
269
270
  - spec/fixtures/vcr_cassettes/SoapyCake_AdminAddedit/offer_contracts/updates_an_offer_contract.yml
270
271
  - spec/fixtures/vcr_cassettes/SoapyCake_AdminAddedit/offer_tiers/adds_an_offer_tier.yml
272
+ - spec/fixtures/vcr_cassettes/SoapyCake_AdminAddedit/offer_tiers/edits_an_offer_tier.yml
271
273
  - spec/fixtures/vcr_cassettes/SoapyCake_AdminAddedit/offers/creates_an_offer.yml
272
274
  - spec/fixtures/vcr_cassettes/SoapyCake_AdminAddedit/offers/updates_an_offer.yml
273
275
  - spec/fixtures/vcr_cassettes/SoapyCake_AdminTrack/_mass_conversion_insert/insers_conversions.yml