soapy_cake 0.3.4 → 1.0.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.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +1 -0
  3. data/api_versions.yml +110 -110
  4. data/lib/soapy_cake.rb +10 -2
  5. data/lib/soapy_cake/admin.rb +34 -46
  6. data/lib/soapy_cake/affiliate.rb +5 -17
  7. data/lib/soapy_cake/client.rb +33 -3
  8. data/lib/soapy_cake/error.rb +4 -0
  9. data/lib/soapy_cake/helper.rb +16 -0
  10. data/lib/soapy_cake/request.rb +61 -0
  11. data/lib/soapy_cake/response.rb +48 -0
  12. data/lib/soapy_cake/version.rb +1 -1
  13. data/soapy_cake.gemspec +4 -4
  14. data/spec/fixtures/vcr_cassettes/Integration_test/raises_if_there_is_an_error.yml +50 -0
  15. data/spec/fixtures/vcr_cassettes/Integration_test/returns_an_affiliate_with_correct_data_types.yml +114 -0
  16. data/spec/lib/soapy_cake/admin_spec.rb +87 -199
  17. data/spec/lib/soapy_cake/affiliate_spec.rb +19 -39
  18. data/spec/lib/soapy_cake/integration_spec.rb +25 -0
  19. data/spec/spec_helper.rb +2 -0
  20. metadata +14 -55
  21. data/lib/soapy_cake/advertiser.rb +0 -21
  22. data/lib/soapy_cake/client/cake_client.rb +0 -157
  23. data/lib/soapy_cake/client/http_client.rb +0 -14
  24. data/spec/fixtures/vcr_cassettes/client_new_account_statuses.yml +0 -1200
  25. data/spec/fixtures/vcr_cassettes/client_new_advertisers.yml +0 -1202
  26. data/spec/fixtures/vcr_cassettes/client_new_affiliate_tags.yml +0 -1200
  27. data/spec/fixtures/vcr_cassettes/client_new_affiliate_tiers.yml +0 -1201
  28. data/spec/fixtures/vcr_cassettes/client_new_billing_cycles.yml +0 -1200
  29. data/spec/fixtures/vcr_cassettes/client_new_cap_intervals.yml +0 -1201
  30. data/spec/fixtures/vcr_cassettes/client_new_cap_types.yml +0 -1199
  31. data/spec/fixtures/vcr_cassettes/client_new_countries.yml +0 -1515
  32. data/spec/fixtures/vcr_cassettes/client_new_currencies.yml +0 -1199
  33. data/spec/fixtures/vcr_cassettes/client_new_empty_response.yml +0 -1200
  34. data/spec/fixtures/vcr_cassettes/client_new_empty_response_offer_summary.yml +0 -865
  35. data/spec/fixtures/vcr_cassettes/client_new_languages.yml +0 -1199
  36. data/spec/fixtures/vcr_cassettes/client_new_media_types.yml +0 -1215
  37. data/spec/fixtures/vcr_cassettes/client_new_offer_statuses.yml +0 -1202
  38. data/spec/fixtures/vcr_cassettes/client_new_offer_types.yml +0 -1201
  39. data/spec/fixtures/vcr_cassettes/client_new_payment_settings.yml +0 -1203
  40. data/spec/fixtures/vcr_cassettes/client_new_payment_types.yml +0 -1204
  41. data/spec/fixtures/vcr_cassettes/client_new_price_formats.yml +0 -1202
  42. data/spec/fixtures/vcr_cassettes/client_new_roles.yml +0 -1203
  43. data/spec/fixtures/vcr_cassettes/client_new_verticals.yml +0 -1197
  44. data/spec/fixtures/vcr_cassettes/client_new_with_username_and_password.yml +0 -1198
  45. data/spec/fixtures/vcr_cassettes/client_sekken_client_caches_results.yml +0 -1261
  46. data/spec/lib/soapy_cake/advertiser_spec.rb +0 -14
  47. data/spec/lib/soapy_cake/client/cake_client_spec.rb +0 -197
@@ -1,14 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe SoapyCake::Advertiser do
4
- subject { described_class.new(api_key: 'abc', advertiser_id: 1) }
5
-
6
- describe '.bills' do
7
- it 'returns bills for an advertiser' do
8
- expect_any_instance_of(SoapyCake::Client::CakeClient).to receive(:bills)
9
- .with(advertiser_id: 1, api_key: 'abc')
10
-
11
- subject.bills
12
- end
13
- end
14
- end
@@ -1,197 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe SoapyCake::Client::CakeClient do
6
- before do
7
- described_class.instance_variable_set(:@sekken_clients, nil)
8
- end
9
-
10
- subject(:client) { described_class.new(:get, opts) }
11
- let(:opts) { {} }
12
-
13
- describe '.new' do
14
- context 'when passed api key' do
15
- let(:opts) { { api_key: 'api-key' } }
16
-
17
- around { |example| VCR.use_cassette(:client_new_with_api_key, &example) }
18
-
19
- describe '#api_key' do
20
- subject { super().api_key }
21
- it { is_expected.to eq('api-key') }
22
- end
23
- end
24
-
25
- context 'when passed username and password' do
26
- let(:opts) { { username: 'username', password: 'password' } }
27
-
28
- around do |example|
29
- VCR.use_cassette(:client_new_with_username_and_password, &example)
30
- end
31
-
32
- describe '#api_key' do
33
- subject { super().api_key }
34
- it { is_expected.to eq('api-key') }
35
- end
36
- end
37
- end
38
-
39
- {
40
- account_statuses: { id: '1', name: 'Active' },
41
- advertisers: { id: '1', name: 'ad2games GmbH' },
42
- affiliate_tags: { id: '1', name: 'Suspicious' },
43
- affiliate_tiers: { id: '1', name: 'Tier 1' },
44
- billing_cycles: { id: '1', name: 'Weekly' },
45
- cap_intervals: { id: '1', name: 'Daily' },
46
- cap_types: { id: '1', name: 'Click' },
47
- countries: { code: 'DE', name: 'Germany' },
48
- currencies: { id: '1', symbol: '€', name: 'Euro', abbr: 'EUR' },
49
- # TODO: Let's test this when there is data.
50
- # departments: [],
51
- # TODO: We don't get any exchange rates from the test API. Fill in when we
52
- # have real API access.
53
- # exchange_rates: {},
54
- languages: { id: '1', name: 'ENGLISH', abbr: 'en' },
55
- offer_statuses: { id: '3', name: 'Apply To Run' },
56
- offer_types: { id: '3', name: '3rd Party' },
57
- payment_settings: { id: '1', name: 'Pay affiliate in system default currency' },
58
- payment_types: { id: '1', name: 'Check' },
59
- price_formats: { id: '1', name: 'CPA' },
60
- roles: { id: '3', name: 'Account Manager', entity_type_id: nil, entity_type_name: 'Employee' },
61
- verticals: { id: '-1', name: 'Global' },
62
- }.each do |name, exp_sample|
63
- describe "##{name}" do
64
- subject { client.public_send(name) }
65
-
66
- around do |example|
67
- VCR.use_cassette(:"client_new_#{name}", &example)
68
- end
69
-
70
- it { is_expected.to include(exp_sample) }
71
- end
72
- end
73
-
74
- describe 'an empty response' do
75
- context 'for exchange rates' do
76
- subject do
77
- client.exchange_rates(
78
- start_date: Time.parse('2013-01-01 00:00:00 +0000)'),
79
- end_date: Date.parse('2013-01-31')
80
- )
81
- end
82
-
83
- around do |example|
84
- VCR.use_cassette(:client_new_empty_response, &example)
85
- end
86
-
87
- it { is_expected.to eq([]) }
88
- end
89
-
90
- context 'for offer summary' do
91
- subject do
92
- described_class.new(:reports, opts).offer_summary(
93
- start_date: Time.utc(2013, 1, 1),
94
- end_date: Time.utc(2013, 1, 2)
95
- )
96
- end
97
-
98
- around do |example|
99
- VCR.use_cassette(:client_new_empty_response_offer_summary, &example)
100
- end
101
-
102
- it { is_expected.to eq([]) }
103
- end
104
- end
105
-
106
- describe '#remove_prefixes' do
107
- it 'removes prefix from hash keys' do
108
- expect(
109
- client.send(:remove_prefix, 'foo', foo_id: 'bar', foo_name: 'baz')
110
- ).to eq(id: 'bar', name: 'baz')
111
- end
112
- end
113
-
114
- describe '#sekken_client' do
115
- around do |example|
116
- VCR.use_cassette(:"client_sekken_client_caches_results", &example)
117
- end
118
-
119
- it 'results are cached' do
120
- expect(client.sekken_client('roles')).to equal(client.sekken_client('roles'))
121
- end
122
-
123
- context 'for different methods with the same wsdl url' do
124
- it 'results are cached' do
125
- expect(client.sekken_client('roles')).to equal(client.sekken_client('advertisers'))
126
- end
127
- end
128
- end
129
-
130
- describe '#not_a_valid_method' do
131
- subject { -> { client.send('not_a_valid_method') } }
132
-
133
- context 'when an unsupported method is called' do
134
- it { is_expected.to raise_error }
135
- end
136
- end
137
-
138
- describe '#process_response' do
139
- let(:response) do
140
- {
141
- affiliate_response: {
142
- affiliate_result: {
143
- success: true,
144
- message: 'Affiliate Added Successfully',
145
- affiliate_id: '16103',
146
- tipalti_iframe_expiration_date: nil,
147
- }
148
- }
149
- }
150
- end
151
-
152
- let(:get_response) do
153
- {
154
- get_campaign_response: {
155
- get_campaign_result: {
156
- success: true,
157
- campaign: {
158
- offer_id: '5129'
159
- }
160
- }
161
- }
162
- }
163
- end
164
-
165
- it 'handles responses with a message field as not having a collection' do
166
- expect(client.send(:process_response, :affiliate, response)).to eq(
167
- response[:affiliate_response][:affiliate_result])
168
- end
169
-
170
- it 'handles get API responses as having no collection' do
171
- expect(client.send(:process_response, :get_campaign, get_response)).to eq(
172
- get_response[:get_campaign_response][:get_campaign_result])
173
- end
174
-
175
- it 'raises RequestUnsuccessful if response contains success: false' do
176
- expect do
177
- client.send(:process_response, :affiliate, affiliate_response: {
178
- affiliate_result: { message: 'FAIL!', success: false }
179
- })
180
- end.to raise_error(described_class::RequestUnsuccessful, 'FAIL!')
181
- end
182
-
183
- it 'raises RequestUnsuccessful if response contains `:fault` key' do
184
- expect do
185
- client.send(:process_response, :affiliate,
186
- fault: { reason: { text: 'FAIL!' } })
187
- end.to raise_error(described_class::RequestUnsuccessful, 'FAIL!')
188
- end
189
- end
190
-
191
- describe 'instantiating through class method' do
192
- it 'creates an instance with the service set according to the method name used' do
193
- instance = described_class.get
194
- expect(instance.service).to eq(:get)
195
- end
196
- end
197
- end