soapy_cake 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +24 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +56 -0
  8. data/Rakefile +6 -0
  9. data/api_versions.yml +103 -0
  10. data/circle.yml +7 -0
  11. data/lib/soapy_cake.rb +8 -0
  12. data/lib/soapy_cake/client.rb +145 -0
  13. data/lib/soapy_cake/version.rb +3 -0
  14. data/script/update_versions.rb +41 -0
  15. data/soapy_cake.gemspec +30 -0
  16. data/spec/fixtures/vcr_cassettes/client_new_account_statuses.yml +1200 -0
  17. data/spec/fixtures/vcr_cassettes/client_new_advertisers.yml +1202 -0
  18. data/spec/fixtures/vcr_cassettes/client_new_affiliate_tags.yml +1200 -0
  19. data/spec/fixtures/vcr_cassettes/client_new_affiliate_tiers.yml +1201 -0
  20. data/spec/fixtures/vcr_cassettes/client_new_billing_cycles.yml +1200 -0
  21. data/spec/fixtures/vcr_cassettes/client_new_cap_intervals.yml +1201 -0
  22. data/spec/fixtures/vcr_cassettes/client_new_cap_types.yml +1199 -0
  23. data/spec/fixtures/vcr_cassettes/client_new_countries.yml +1515 -0
  24. data/spec/fixtures/vcr_cassettes/client_new_currencies.yml +1199 -0
  25. data/spec/fixtures/vcr_cassettes/client_new_empty_response.yml +1200 -0
  26. data/spec/fixtures/vcr_cassettes/client_new_empty_response_offer_summary.yml +865 -0
  27. data/spec/fixtures/vcr_cassettes/client_new_languages.yml +1199 -0
  28. data/spec/fixtures/vcr_cassettes/client_new_media_types.yml +1215 -0
  29. data/spec/fixtures/vcr_cassettes/client_new_offer_statuses.yml +1202 -0
  30. data/spec/fixtures/vcr_cassettes/client_new_offer_types.yml +1201 -0
  31. data/spec/fixtures/vcr_cassettes/client_new_payment_settings.yml +1203 -0
  32. data/spec/fixtures/vcr_cassettes/client_new_payment_types.yml +1204 -0
  33. data/spec/fixtures/vcr_cassettes/client_new_price_formats.yml +1202 -0
  34. data/spec/fixtures/vcr_cassettes/client_new_roles.yml +1203 -0
  35. data/spec/fixtures/vcr_cassettes/client_new_verticals.yml +1197 -0
  36. data/spec/fixtures/vcr_cassettes/client_new_with_username_and_password.yml +1198 -0
  37. data/spec/fixtures/vcr_cassettes/client_sekken_client_caches_results.yml +1261 -0
  38. data/spec/lib/soapy_cake/client_spec.rb +164 -0
  39. data/spec/spec_helper.rb +36 -0
  40. metadata +219 -0
@@ -0,0 +1,164 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe SoapyCake::Client do
6
+ before do
7
+ SoapyCake::Client.instance_variable_set(:@sekken_clients, nil)
8
+ end
9
+
10
+ subject(:client) { SoapyCake::Client.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
+ SoapyCake::Client.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
+ it 'handles responses with a message field as not having a collection' do
153
+ expect(client.send(:process_response, :affiliate, response)).to eq(
154
+ response[:affiliate_response][:affiliate_result])
155
+ end
156
+ end
157
+
158
+ describe 'instantiating through class method' do
159
+ it 'creates an instance with the service set according to the method name used' do
160
+ instance = SoapyCake::Client.get
161
+ expect(instance.service).to eq(:get)
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,36 @@
1
+ require 'bundler/setup'
2
+ Bundler.require(:default, :development)
3
+ require 'soapy_cake'
4
+
5
+ # This file was generated by the `rspec --init` command. Conventionally, all
6
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
7
+ # Require this file using `require "spec_helper"` to ensure that it is only
8
+ # loaded once.
9
+ #
10
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
11
+ RSpec.configure do |config|
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+
21
+ config.expect_with :rspec do |c|
22
+ # Disable the `should` syntax
23
+ c.syntax = :expect
24
+ end
25
+ end
26
+
27
+ ENV['CAKE_API_KEY'] = 'cake-api-key' if ENV['CAKE_API_KEY'].blank?
28
+ ENV['CAKE_DOMAIN'] = 'cake-partner-domain.com' if ENV['CAKE_DOMAIN'].blank?
29
+
30
+ VCR.configure do |c|
31
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
32
+ c.hook_into :webmock
33
+ c.filter_sensitive_data('cake-api-key') { ENV['CAKE_API_KEY'] }
34
+ c.filter_sensitive_data('cake-partner-domain.com') { ENV['CAKE_DOMAIN'] }
35
+ c.default_cassette_options = { match_requests_on: [:method, :uri, :body] }
36
+ end
metadata ADDED
@@ -0,0 +1,219 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soapy_cake
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - ad2games GmbH
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sekken
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: byebug
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Simple client for the CAKE API (http://getcake.com)
126
+ email:
127
+ - developers@ad2games.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .rspec
134
+ - .ruby-version
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - api_versions.yml
140
+ - circle.yml
141
+ - lib/soapy_cake.rb
142
+ - lib/soapy_cake/client.rb
143
+ - lib/soapy_cake/version.rb
144
+ - script/update_versions.rb
145
+ - soapy_cake.gemspec
146
+ - spec/fixtures/vcr_cassettes/client_new_account_statuses.yml
147
+ - spec/fixtures/vcr_cassettes/client_new_advertisers.yml
148
+ - spec/fixtures/vcr_cassettes/client_new_affiliate_tags.yml
149
+ - spec/fixtures/vcr_cassettes/client_new_affiliate_tiers.yml
150
+ - spec/fixtures/vcr_cassettes/client_new_billing_cycles.yml
151
+ - spec/fixtures/vcr_cassettes/client_new_cap_intervals.yml
152
+ - spec/fixtures/vcr_cassettes/client_new_cap_types.yml
153
+ - spec/fixtures/vcr_cassettes/client_new_countries.yml
154
+ - spec/fixtures/vcr_cassettes/client_new_currencies.yml
155
+ - spec/fixtures/vcr_cassettes/client_new_empty_response.yml
156
+ - spec/fixtures/vcr_cassettes/client_new_empty_response_offer_summary.yml
157
+ - spec/fixtures/vcr_cassettes/client_new_languages.yml
158
+ - spec/fixtures/vcr_cassettes/client_new_media_types.yml
159
+ - spec/fixtures/vcr_cassettes/client_new_offer_statuses.yml
160
+ - spec/fixtures/vcr_cassettes/client_new_offer_types.yml
161
+ - spec/fixtures/vcr_cassettes/client_new_payment_settings.yml
162
+ - spec/fixtures/vcr_cassettes/client_new_payment_types.yml
163
+ - spec/fixtures/vcr_cassettes/client_new_price_formats.yml
164
+ - spec/fixtures/vcr_cassettes/client_new_roles.yml
165
+ - spec/fixtures/vcr_cassettes/client_new_verticals.yml
166
+ - spec/fixtures/vcr_cassettes/client_new_with_username_and_password.yml
167
+ - spec/fixtures/vcr_cassettes/client_sekken_client_caches_results.yml
168
+ - spec/lib/soapy_cake/client_spec.rb
169
+ - spec/spec_helper.rb
170
+ homepage: http://ad2games.com
171
+ licenses:
172
+ - MIT
173
+ metadata: {}
174
+ post_install_message:
175
+ rdoc_options: []
176
+ require_paths:
177
+ - lib
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - '>='
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - '>='
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirements: []
189
+ rubyforge_project:
190
+ rubygems_version: 2.3.0
191
+ signing_key:
192
+ specification_version: 4
193
+ summary: Simple client for the CAKE API
194
+ test_files:
195
+ - spec/fixtures/vcr_cassettes/client_new_account_statuses.yml
196
+ - spec/fixtures/vcr_cassettes/client_new_advertisers.yml
197
+ - spec/fixtures/vcr_cassettes/client_new_affiliate_tags.yml
198
+ - spec/fixtures/vcr_cassettes/client_new_affiliate_tiers.yml
199
+ - spec/fixtures/vcr_cassettes/client_new_billing_cycles.yml
200
+ - spec/fixtures/vcr_cassettes/client_new_cap_intervals.yml
201
+ - spec/fixtures/vcr_cassettes/client_new_cap_types.yml
202
+ - spec/fixtures/vcr_cassettes/client_new_countries.yml
203
+ - spec/fixtures/vcr_cassettes/client_new_currencies.yml
204
+ - spec/fixtures/vcr_cassettes/client_new_empty_response.yml
205
+ - spec/fixtures/vcr_cassettes/client_new_empty_response_offer_summary.yml
206
+ - spec/fixtures/vcr_cassettes/client_new_languages.yml
207
+ - spec/fixtures/vcr_cassettes/client_new_media_types.yml
208
+ - spec/fixtures/vcr_cassettes/client_new_offer_statuses.yml
209
+ - spec/fixtures/vcr_cassettes/client_new_offer_types.yml
210
+ - spec/fixtures/vcr_cassettes/client_new_payment_settings.yml
211
+ - spec/fixtures/vcr_cassettes/client_new_payment_types.yml
212
+ - spec/fixtures/vcr_cassettes/client_new_price_formats.yml
213
+ - spec/fixtures/vcr_cassettes/client_new_roles.yml
214
+ - spec/fixtures/vcr_cassettes/client_new_verticals.yml
215
+ - spec/fixtures/vcr_cassettes/client_new_with_username_and_password.yml
216
+ - spec/fixtures/vcr_cassettes/client_sekken_client_caches_results.yml
217
+ - spec/lib/soapy_cake/client_spec.rb
218
+ - spec/spec_helper.rb
219
+ has_rdoc: