soapy_cake 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +16 -0
  3. data/Gemfile +2 -1
  4. data/circle.yml +2 -0
  5. data/lib/soapy_cake.rb +3 -0
  6. data/lib/soapy_cake/admin.rb +2 -2
  7. data/lib/soapy_cake/admin_addedit.rb +5 -50
  8. data/lib/soapy_cake/campaigns.rb +104 -0
  9. data/lib/soapy_cake/client.rb +5 -5
  10. data/lib/soapy_cake/helper.rb +14 -9
  11. data/lib/soapy_cake/modification_type.rb +45 -0
  12. data/lib/soapy_cake/version.rb +1 -1
  13. data/spec/fixtures/vcr_cassettes/SoapyCake_AdminAddedit/campaigns/edits_a_campaign.yml +18 -5
  14. data/spec/fixtures/vcr_cassettes/SoapyCake_Campaigns/_create/creates_campaigns.yml +60 -0
  15. data/spec/fixtures/vcr_cassettes/SoapyCake_Campaigns/_create/raises_an_error_if_the_creation_was_unsuccessful.yml +60 -0
  16. data/spec/fixtures/vcr_cassettes/SoapyCake_Campaigns/_get/gets_campaigns.yml +1205 -0
  17. data/spec/fixtures/vcr_cassettes/SoapyCake_Campaigns/_patch/different_pre-existing_values/does_not_change_anything_unintentionally_attribute_set_0_.yml +380 -0
  18. data/spec/fixtures/vcr_cassettes/SoapyCake_Campaigns/_patch/different_pre-existing_values/does_not_change_anything_unintentionally_attribute_set_1_.yml +383 -0
  19. data/spec/fixtures/vcr_cassettes/SoapyCake_Campaigns/_patch/updates_a_campaign.yml +454 -0
  20. data/spec/fixtures/vcr_cassettes/SoapyCake_Campaigns/_update/raises_an_error_if_the_update_was_unsuccessful.yml +82 -0
  21. data/spec/fixtures/vcr_cassettes/SoapyCake_Campaigns/_update/updates_campaigns.yml +82 -0
  22. data/spec/integration/soapy_cake/admin_addedit_spec.rb +0 -31
  23. data/spec/integration/soapy_cake/campaigns_spec.rb +175 -0
  24. data/spec/lib/soapy_cake/admin_spec.rb +0 -1
  25. data/spec/lib/soapy_cake/campaigns_spec.rb +127 -0
  26. data/spec/lib/soapy_cake/modification_type_spec.rb +59 -0
  27. data/spec/spec_helper.rb +3 -3
  28. metadata +27 -2
@@ -0,0 +1,82 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://cake-partner-domain.com/api/3/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/3/">
11
+ <env:Header/>
12
+ <env:Body>
13
+ <cake:Campaign>
14
+ <cake:api_key>cake-api-key</cake:api_key>
15
+ <cake:account_status_id>0</cake:account_status_id>
16
+ <cake:expiration_date_modification_type>remove</cake:expiration_date_modification_type>
17
+ <cake:currency_id>0</cake:currency_id>
18
+ <cake:use_offer_contract_payout>no_change</cake:use_offer_contract_payout>
19
+ <cake:payout_update_option>change</cake:payout_update_option>
20
+ <cake:paid>no_change</cake:paid>
21
+ <cake:paid_redirects>no_change</cake:paid_redirects>
22
+ <cake:paid_upsells>no_change</cake:paid_upsells>
23
+ <cake:review>no_change</cake:review>
24
+ <cake:auto_disposition_delay_hours>0</cake:auto_disposition_delay_hours>
25
+ <cake:redirect_offer_contract_id>0</cake:redirect_offer_contract_id>
26
+ <cake:redirect_404>no_change</cake:redirect_404>
27
+ <cake:clear_session_on_conversion>no_change</cake:clear_session_on_conversion>
28
+ <cake:postback_delay_ms>-1</cake:postback_delay_ms>
29
+ <cake:affiliate_id>9643</cake:affiliate_id>
30
+ <cake:display_link_type_id>1</cake:display_link_type_id>
31
+ <cake:media_type_id>1</cake:media_type_id>
32
+ <cake:offer_contract_id>10338</cake:offer_contract_id>
33
+ <cake:offer_id>11390</cake:offer_id>
34
+ <cake:payout>1.23</cake:payout>
35
+ <cake:pixel_html>&lt;img src="https://example.com/pixel.png"&gt;</cake:pixel_html>
36
+ <cake:postback_url>http://example.com/postback</cake:postback_url>
37
+ <cake:redirect_domain>trk_ad2games.cakemarketing.net</cake:redirect_domain>
38
+ <cake:test_link>http://example.com/test</cake:test_link>
39
+ <cake:third_party_name>Max</cake:third_party_name>
40
+ <cake:unique_key_hash>sha1</cake:unique_key_hash>
41
+ <cake:campaign_id>9999999</cake:campaign_id>
42
+ <cake:expiration_date>1970-01-01T01:00:00</cake:expiration_date>
43
+ </cake:Campaign>
44
+ </env:Body>
45
+ </env:Envelope>
46
+ headers:
47
+ Content-Type:
48
+ - application/soap+xml;charset=UTF-8
49
+ Accept-Encoding:
50
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
51
+ Accept:
52
+ - "*/*"
53
+ User-Agent:
54
+ - Ruby
55
+ response:
56
+ status:
57
+ code: 200
58
+ message: OK
59
+ headers:
60
+ Cache-Control:
61
+ - private, max-age=0
62
+ Content-Type:
63
+ - application/soap+xml; charset=utf-8
64
+ Server:
65
+ - Microsoft-IIS/8.5
66
+ X-Aspnet-Version:
67
+ - 4.0.30319
68
+ X-Powered-By:
69
+ - ASP.NET
70
+ Date:
71
+ - Fri, 11 Nov 2016 15:57:24 GMT
72
+ Content-Length:
73
+ - '416'
74
+ body:
75
+ encoding: UTF-8
76
+ string: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
77
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CampaignResponse
78
+ xmlns="http://cakemarketing.com/api/3/"><CampaignResult><success>false</success><message>Invalid
79
+ Campaign ID</message></CampaignResult></CampaignResponse></soap:Body></soap:Envelope>
80
+ http_version:
81
+ recorded_at: Fri, 11 Nov 2016 15:57:47 GMT
82
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,82 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://cake-partner-domain.com/api/3/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/3/">
11
+ <env:Header/>
12
+ <env:Body>
13
+ <cake:Campaign>
14
+ <cake:api_key>cake-api-key</cake:api_key>
15
+ <cake:account_status_id>0</cake:account_status_id>
16
+ <cake:expiration_date_modification_type>remove</cake:expiration_date_modification_type>
17
+ <cake:currency_id>0</cake:currency_id>
18
+ <cake:use_offer_contract_payout>no_change</cake:use_offer_contract_payout>
19
+ <cake:payout_update_option>change</cake:payout_update_option>
20
+ <cake:paid>no_change</cake:paid>
21
+ <cake:paid_redirects>no_change</cake:paid_redirects>
22
+ <cake:paid_upsells>no_change</cake:paid_upsells>
23
+ <cake:review>no_change</cake:review>
24
+ <cake:auto_disposition_delay_hours>0</cake:auto_disposition_delay_hours>
25
+ <cake:redirect_offer_contract_id>0</cake:redirect_offer_contract_id>
26
+ <cake:redirect_404>no_change</cake:redirect_404>
27
+ <cake:clear_session_on_conversion>no_change</cake:clear_session_on_conversion>
28
+ <cake:postback_delay_ms>-1</cake:postback_delay_ms>
29
+ <cake:affiliate_id>9643</cake:affiliate_id>
30
+ <cake:display_link_type_id>1</cake:display_link_type_id>
31
+ <cake:media_type_id>1</cake:media_type_id>
32
+ <cake:offer_contract_id>10338</cake:offer_contract_id>
33
+ <cake:offer_id>11390</cake:offer_id>
34
+ <cake:payout>1.23</cake:payout>
35
+ <cake:pixel_html>&lt;img src="https://example.com/pixel.png"&gt;</cake:pixel_html>
36
+ <cake:postback_url>http://example.com/postback</cake:postback_url>
37
+ <cake:redirect_domain>trk_ad2games.cakemarketing.net</cake:redirect_domain>
38
+ <cake:test_link>http://example.com/test</cake:test_link>
39
+ <cake:third_party_name>Max</cake:third_party_name>
40
+ <cake:unique_key_hash>sha1</cake:unique_key_hash>
41
+ <cake:campaign_id>23602</cake:campaign_id>
42
+ <cake:expiration_date>1970-01-01T01:00:00</cake:expiration_date>
43
+ </cake:Campaign>
44
+ </env:Body>
45
+ </env:Envelope>
46
+ headers:
47
+ Content-Type:
48
+ - application/soap+xml;charset=UTF-8
49
+ Accept-Encoding:
50
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
51
+ Accept:
52
+ - "*/*"
53
+ User-Agent:
54
+ - Ruby
55
+ response:
56
+ status:
57
+ code: 200
58
+ message: OK
59
+ headers:
60
+ Cache-Control:
61
+ - private, max-age=0
62
+ Content-Type:
63
+ - application/soap+xml; charset=utf-8
64
+ Server:
65
+ - Microsoft-IIS/8.5
66
+ X-Aspnet-Version:
67
+ - 4.0.30319
68
+ X-Powered-By:
69
+ - ASP.NET
70
+ Date:
71
+ - Fri, 11 Nov 2016 15:57:24 GMT
72
+ Content-Length:
73
+ - '633'
74
+ body:
75
+ encoding: UTF-8
76
+ string: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
77
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><CampaignResponse
78
+ xmlns="http://cakemarketing.com/api/3/"><CampaignResult><success>true</success><message>Campaign
79
+ Updated</message><success_info><campaign_id>23602</campaign_id><affiliate_id>9643</affiliate_id><offer_id>11390</offer_id><offer_contract_id>10338</offer_contract_id><media_type_id>1</media_type_id><original>true</original></success_info></CampaignResult></CampaignResponse></soap:Body></soap:Envelope>
80
+ http_version:
81
+ recorded_at: Fri, 11 Nov 2016 15:57:47 GMT
82
+ recorded_with: VCR 3.0.3
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  RSpec.describe SoapyCake::AdminAddedit do
3
- # rubocop:disable RSpec/NestedGroups
4
3
  subject(:admin_addedit) { described_class.new }
5
4
 
6
5
  around { |example| Timecop.freeze(Time.utc(2015, 2, 17, 12), &example) }
@@ -284,34 +283,4 @@ RSpec.describe SoapyCake::AdminAddedit do
284
283
  expect(result[:message]).to eq('Offer Tier Replaced')
285
284
  end
286
285
  end
287
-
288
- describe 'campaigns' do
289
- it 'adds a campaign', :vcr do
290
- result = admin_addedit.add_campaign(
291
- affiliate_id: affiliate_id,
292
- offer_id: offer_id,
293
- media_type_id: 1,
294
- account_status_id: :active,
295
- payout: '1.23',
296
- redirect_404: false,
297
- clear_session_on_conversion: false,
298
- paid_upsells: false
299
- )
300
-
301
- expect(result[:message]).to eq('Campaign Created')
302
- end
303
-
304
- it 'edits a campaign', :vcr do
305
- result = admin_addedit.edit_campaign(
306
- campaign_id: 123,
307
- affiliate_id: affiliate_id,
308
- offer_id: offer_id,
309
- media_type_id: 1,
310
- account_status_id: :active,
311
- payout: '1.23'
312
- )
313
-
314
- expect(result[:message]).to eq('Campaign Updated')
315
- end
316
- end
317
286
  end
@@ -0,0 +1,175 @@
1
+ # frozen_string_literal: true
2
+ RSpec.describe SoapyCake::Campaigns, :vcr do
3
+ let(:offer_id) { 11390 }
4
+ let(:affiliate_id) { 9643 }
5
+ let(:redirect_domain) { 'trk_ad2games.cakemarketing.net' }
6
+
7
+ subject(:client) { described_class.new }
8
+
9
+ describe '#get' do
10
+ it 'gets campaigns' do
11
+ campaigns = client.get(offer_id: offer_id)
12
+ expect(campaigns.first.dig(:offer, :offer_id)).to eq(offer_id)
13
+ end
14
+ end
15
+
16
+ describe '#create' do
17
+ it 'creates campaigns' do
18
+ campaign_id = client.create(
19
+ account_status_id: 1,
20
+ affiliate_id: affiliate_id,
21
+ display_link_type_id: 1,
22
+ media_type_id: 1,
23
+ offer_id: offer_id
24
+ )
25
+ expect(campaign_id).to be_a(Integer)
26
+ end
27
+
28
+ it 'raises an error if the creation was unsuccessful' do
29
+ expect do
30
+ client.create(
31
+ account_status_id: 1,
32
+ affiliate_id: 0,
33
+ display_link_type_id: 1,
34
+ media_type_id: 1,
35
+ offer_id: offer_id
36
+ )
37
+ end.to raise_error(SoapyCake::RequestFailed, 'Invalid Affiliate')
38
+ end
39
+ end
40
+
41
+ describe '#update' do
42
+ it 'updates campaigns' do
43
+ response = client.update(
44
+ 23602,
45
+ affiliate_id: affiliate_id,
46
+ display_link_type_id: 1,
47
+ media_type_id: 1,
48
+ offer_contract_id: 10338,
49
+ offer_id: 11390,
50
+ payout: 1.23,
51
+ pixel_html: '<img src="https://example.com/pixel.png">',
52
+ postback_url: 'http://example.com/postback',
53
+ redirect_domain: redirect_domain,
54
+ test_link: 'http://example.com/test',
55
+ third_party_name: 'Max',
56
+ unique_key_hash: 'sha1'
57
+ )
58
+ expect(response).to be(nil)
59
+ end
60
+
61
+ it 'raises an error if the update was unsuccessful' do
62
+ expect do
63
+ client.update(
64
+ 9999999,
65
+ affiliate_id: affiliate_id,
66
+ display_link_type_id: 1,
67
+ media_type_id: 1,
68
+ offer_contract_id: 10338,
69
+ offer_id: 11390,
70
+ payout: 1.23,
71
+ pixel_html: '<img src="https://example.com/pixel.png">',
72
+ postback_url: 'http://example.com/postback',
73
+ redirect_domain: redirect_domain,
74
+ test_link: 'http://example.com/test',
75
+ third_party_name: 'Max',
76
+ unique_key_hash: 'sha1'
77
+ )
78
+ end.to raise_error(SoapyCake::RequestFailed, 'Invalid Campaign ID')
79
+ end
80
+ end
81
+
82
+ describe '#patch' do
83
+ let(:admin) { SoapyCake::Admin.new }
84
+ let(:campaign_id) { 23733 }
85
+
86
+ it 'updates a campaign' do
87
+ %w(foo bar).each do |name|
88
+ client.patch(campaign_id, third_party_name: name)
89
+ campaign = client.get(campaign_id: campaign_id).first
90
+ expect(campaign.fetch(:third_party_name)).to eq(name)
91
+ end
92
+ end
93
+
94
+ context 'different pre-existing values' do
95
+ let(:attribute_sets) do
96
+ [
97
+ {
98
+ affiliate_id: affiliate_id,
99
+ campaign_id: campaign_id,
100
+ offer_id: offer_id,
101
+
102
+ account_status_id: 1,
103
+ auto_disposition_delay_hours: 0,
104
+ clear_session_on_conversion: true,
105
+ currency_id: 1,
106
+ display_link_type_id: 1,
107
+ expiration_date: Time.utc(2016, 11, 9),
108
+ expiration_date_modification_type: 'change',
109
+ media_type_id: 1,
110
+ offer_contract_id: 10338,
111
+ paid: true,
112
+ paid_redirects: true,
113
+ paid_upsells: true,
114
+ payout: 0,
115
+ payout_update_option: 'remove',
116
+ pixel_html: '',
117
+ postback_delay_ms: -1,
118
+ postback_url: '',
119
+ redirect_404: true,
120
+ redirect_domain: redirect_domain,
121
+ redirect_offer_contract_id: 10337,
122
+ review: true,
123
+ test_link: '',
124
+ unique_key_hash: 'none',
125
+ use_offer_contract_payout: true,
126
+ third_party_name: ''
127
+ },
128
+ {
129
+ affiliate_id: affiliate_id,
130
+ campaign_id: campaign_id,
131
+ offer_id: offer_id,
132
+
133
+ account_status_id: 2,
134
+ auto_disposition_delay_hours: 1,
135
+ clear_session_on_conversion: false,
136
+ currency_id: 2,
137
+ display_link_type_id: 1,
138
+ expiration_date: Time.utc(1970, 1, 1),
139
+ expiration_date_modification_type: 'remove',
140
+ media_type_id: 2,
141
+ offer_contract_id: 10342,
142
+ paid: false,
143
+ paid_redirects: false,
144
+ paid_upsells: false,
145
+ payout: 1,
146
+ payout_update_option: 'change',
147
+ pixel_html: 'pixelpixelpixel',
148
+ postback_delay_ms: 100,
149
+ postback_url: 'https://example.com/postback',
150
+ redirect_404: false,
151
+ redirect_domain: redirect_domain,
152
+ redirect_offer_contract_id: 10339,
153
+ review: false,
154
+ test_link: 'https://example.com/test',
155
+ unique_key_hash: 'sha1',
156
+ use_offer_contract_payout: false,
157
+ third_party_name: 'Best Campaign Ever'
158
+ }
159
+ ]
160
+ end
161
+
162
+ 2.times do |i|
163
+ it "does not change anything unintentionally (attribute set: #{i})" do
164
+ client.update(campaign_id, attribute_sets[i])
165
+
166
+ campaign_before = client.get(campaign_id: campaign_id).first
167
+ client.patch(campaign_id)
168
+ campaign_after = client.get(campaign_id: campaign_id).first
169
+
170
+ expect(campaign_after).to eq(campaign_before)
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  RSpec.describe SoapyCake::Admin do
3
- # rubocop:disable RSpec/NestedGroups
4
3
  subject(:admin) { described_class.new }
5
4
  let(:opts) { nil }
6
5
  let(:cake_opts) { opts }
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+ RSpec.describe SoapyCake::Campaigns do
3
+ let(:campaigns) { described_class.new }
4
+ let(:client) { instance_double(SoapyCake::Client) }
5
+ let(:campaign_id) { 1 }
6
+
7
+ before do
8
+ allow(SoapyCake::Client).to receive(:new).and_return(client)
9
+ allow(client).to receive(:run).with(an_instance_of(SoapyCake::Request))
10
+ end
11
+
12
+ let(:default_params) do
13
+ {
14
+ affiliate_id: 1,
15
+ display_link_type_id: 2,
16
+ media_type_id: 3,
17
+ offer_contract_id: 4,
18
+ offer_id: 5,
19
+ payout: 6.0,
20
+ pixel_html: '<img src="https://example.com/pixel.png">',
21
+ postback_url: 'http://example.com/postback',
22
+ redirect_domain: 'example.com',
23
+ test_link: 'http://example.com/test',
24
+ third_party_name: 'Max',
25
+ unique_key_hash: 'foo'
26
+ }
27
+ end
28
+
29
+ def expect_request_to_be_built_with(opts)
30
+ expect(SoapyCake::Request).to receive(:new).with(
31
+ :admin,
32
+ :addedit,
33
+ :campaign,
34
+ a_hash_including(opts)
35
+ ).and_call_original
36
+ end
37
+
38
+ context 'setting an expiration date' do
39
+ let(:expiration_date) { Time.new(2016, 11, 10) }
40
+
41
+ context 'without an `expiration_date_modification_type`' do
42
+ it 'changes the expiration date if an `expiration_date` is provided' do
43
+ expect_request_to_be_built_with(
44
+ expiration_date: expiration_date,
45
+ expiration_date_modification_type: 'change'
46
+ )
47
+
48
+ campaigns.update(
49
+ campaign_id,
50
+ default_params.merge(expiration_date: expiration_date)
51
+ )
52
+ end
53
+
54
+ it 'removes the expiration date if no `expiration_date` is provided' do
55
+ expect_request_to_be_built_with(
56
+ expiration_date: Time.utc(1970, 1, 1),
57
+ expiration_date_modification_type: 'remove'
58
+ )
59
+
60
+ campaigns.update(campaign_id, default_params)
61
+ end
62
+ end
63
+
64
+ context 'with an `expiration_date_modification_type` provided' do
65
+ it 'passes along both, the `expiration_date` and `expiration_date_modification_type`' do
66
+ expect_request_to_be_built_with(
67
+ expiration_date: expiration_date,
68
+ expiration_date_modification_type: 'change'
69
+ )
70
+
71
+ campaigns.update(
72
+ campaign_id,
73
+ default_params.merge(expiration_date: expiration_date,
74
+ expiration_date_modification_type: 'change')
75
+ )
76
+ end
77
+
78
+ it 'sets the expiration_date to something if the modification type is `remove`' do
79
+ expect_request_to_be_built_with(
80
+ expiration_date: Time.utc(1970, 1, 1),
81
+ expiration_date_modification_type: 'remove'
82
+ )
83
+
84
+ campaigns.update(
85
+ campaign_id,
86
+ default_params.merge(expiration_date_modification_type: 'remove')
87
+ )
88
+ end
89
+ end
90
+ end
91
+
92
+ context 'setting a payout' do
93
+ context '`payout_update_option` is not provided' do
94
+ it 'changes the payout if a payout is provided' do
95
+ expect_request_to_be_built_with(payout: 1.23, payout_update_option: 'change')
96
+
97
+ campaigns.update(
98
+ campaign_id,
99
+ default_params.merge(payout: 1.23)
100
+ )
101
+ end
102
+ end
103
+ end
104
+
105
+ describe 'translating values' do
106
+ it 'translates values that have a translation' do
107
+ expect_request_to_be_built_with(account_status_id: 3)
108
+
109
+ campaigns.update(
110
+ campaign_id,
111
+ default_params.merge(account_status: :pending)
112
+ )
113
+ end
114
+
115
+ it 'raises an exception, if the value cannot be translated' do
116
+ expect do
117
+ campaigns.update(
118
+ campaign_id,
119
+ default_params.merge(account_status: :misbehaved)
120
+ )
121
+ end.to raise_error(
122
+ ArgumentError,
123
+ 'misbehaved is not a valid value for account_status_id'
124
+ )
125
+ end
126
+ end
127
+ end