adcloud 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/.document +5 -0
  2. data/.gitignore +69 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +50 -0
  6. data/LICENSE.txt +20 -0
  7. data/README.md +221 -0
  8. data/RELEASE_NOTES.md +14 -0
  9. data/Rakefile +8 -0
  10. data/adcloud.gemspec +27 -0
  11. data/lib/adcloud.rb +62 -0
  12. data/lib/adcloud/advertisement.rb +28 -0
  13. data/lib/adcloud/api_error.rb +33 -0
  14. data/lib/adcloud/authentication.rb +24 -0
  15. data/lib/adcloud/campaign.rb +69 -0
  16. data/lib/adcloud/connection.rb +46 -0
  17. data/lib/adcloud/customer.rb +9 -0
  18. data/lib/adcloud/entity.rb +84 -0
  19. data/lib/adcloud/exception_raiser.rb +22 -0
  20. data/lib/adcloud/media_file.rb +10 -0
  21. data/lib/adcloud/product.rb +10 -0
  22. data/lib/adcloud/report.rb +28 -0
  23. data/lib/adcloud/report_entry.rb +48 -0
  24. data/lib/adcloud/response_error_handler.rb +23 -0
  25. data/lib/adcloud/topic.rb +19 -0
  26. data/lib/adcloud/topic_discount.rb +16 -0
  27. data/lib/adcloud/version.rb +3 -0
  28. data/lib/adcloud/webhook.rb +35 -0
  29. data/lib/adcloud/webhook_config.rb +18 -0
  30. data/lib/adcloud/webhook_event.rb +18 -0
  31. data/test/adcloud/advertisement_test.rb +11 -0
  32. data/test/adcloud/authentication_test.rb +58 -0
  33. data/test/adcloud/campaign_test.rb +54 -0
  34. data/test/adcloud/connection_test.rb +78 -0
  35. data/test/adcloud/customer_test.rb +6 -0
  36. data/test/adcloud/entity_test.rb +159 -0
  37. data/test/adcloud/media_file_test.rb +7 -0
  38. data/test/adcloud/product_test.rb +5 -0
  39. data/test/adcloud/report_test.rb +34 -0
  40. data/test/adcloud/topic_test.rb +14 -0
  41. data/test/adcloud/webhook_event_test.rb +19 -0
  42. data/test/adcloud/webhook_test.rb +62 -0
  43. data/test/adcloud_test.rb +47 -0
  44. data/test/test_helper.rb +23 -0
  45. metadata +251 -0
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ describe Adcloud::MediaFile do
4
+
5
+ # Check entity tests
6
+
7
+ end
@@ -0,0 +1,5 @@
1
+ require 'test_helper'
2
+
3
+ describe Adcloud::Product do
4
+ # check the entity tests
5
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ describe Adcloud::Report do
5
+ subject { Adcloud::Report }
6
+
7
+ let(:connection) { stub }
8
+
9
+ describe ".find_by_date" do
10
+ let(:response_data) { { '_meta' => {}, 'items' => [{date: "1981-06-21", website_id: 2369, topic_id: 100, ad_placement_id: 7979, product_id: 20426, ad_id: 44956, booking_id: 88352, page_type: 0, ad_position: 2, ad_count: 3, ad_impressions: 2, clicks: 0, clicks_overdelivered: 0, clicks_filtered: 0, clicks_image: 0, clicks_head: 0, clicks_txt: 0, clicks_link: 0, postview_conversions: 0, postview_conversions_overdelivered: 0, postview_conversions_filtered: 0, cancellations: 0, publisher: "OMS Online Marketing Service GmbH & Co. KG - Germany", website: "rmsi.radioeuskirchen.de", position: "", design_id: 32, design: "LB (728x90) | 3 IHC (90x68)", topic: "Unterhaltung", ad: "Pferdefutter - Bonn", booking: "GT: 176266_catdog_Bonn", product: "176266_catdog_GT", ad_impressions_costs: 0, clicks_costs: 0, postclick_conversions: 0, postclick_conversions_overdelivered: 0, postclick_conversions_filtered: 0, postclick_conversions_costs: 0, postview_conversions_costs: 0, costs: 0, language: "de", country: "DE", currency: "EUR"}] } }
11
+
12
+ before do
13
+ subject.stubs(:connection => connection)
14
+ connection.stubs(:get).returns(response_data)
15
+ end
16
+
17
+ it 'access the api at the correct path' do
18
+ subject.connection.expects(:get).with('reports/advertiser', { filter: { date: '1981-06-21' } })
19
+ subject.find_by_date(Date.new(1981, 06, 21))
20
+ end
21
+
22
+ it 'returns a report' do
23
+ subject.find_by_date(Date.new(1981, 06, 21)).must_be_instance_of(Adcloud::Report)
24
+ end
25
+
26
+ it 'creates report entries for all items' do
27
+ subject.find_by_date(Date.new(1981, 06, 21)).items.first.must_be_instance_of(Adcloud::ReportEntry)
28
+ end
29
+
30
+ it 'parses the entry data correctly' do
31
+ subject.find_by_date(Date.new(1981, 06, 21)).items.first[:website_id].must_equal 2369
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,14 @@
1
+ require 'test_helper'
2
+
3
+ describe Adcloud::Topic do
4
+ # the basic features are tested in entity test
5
+
6
+ describe '#discounts' do
7
+ let(:raw_data) { [{ 'country_id' => 11, 'discount' => '0.0', 'reach' => '4.0', 'min_price_cpc' => 0, 'price_cpc' => 0, 'max_price_cpc' => 0, 'min_price_cpm' => 0, 'price_cpm' => 0, 'max_price_cpm' => 0, 'country_code' => 'es' }] }
8
+ it 'transforms the data into a hash with locale as key' do
9
+ topic = Adcloud::Topic.new
10
+ topic.discounts = raw_data
11
+ topic.discounts['es'].must_be_instance_of Adcloud::TopicDiscount
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ describe Adcloud::WebhookEvent do
4
+ let(:payload) { { 'id' => 1, 'name' => 'Test run', '_meta' => { 'event' => 'Test.create', 'foo' => 'bar' } } }
5
+
6
+ subject { Adcloud::WebhookEvent.new(payload) }
7
+
8
+ describe '#type' do
9
+ specify { subject.type.must_equal 'Test.create' }
10
+ end
11
+
12
+ describe '#data' do
13
+ specify { subject.data.must_equal({ 'id' => 1, 'name' => 'Test run' }) }
14
+ end
15
+
16
+ describe '#meta' do
17
+ specify { subject.meta.must_equal({ 'event' => 'Test.create', 'foo' => 'bar' }) }
18
+ end
19
+ end
@@ -0,0 +1,62 @@
1
+ require 'test_helper'
2
+
3
+ describe Adcloud::Webhook do
4
+ let(:event_payload) { '{"id":"2","country_id":"1","guidance_price_cpc":"1.49","guidance_price_cpm":"0.6","variance":"20.00","modified":"2012-09-04 14:21:20","created":"2012-04-10 20:40:24","_meta":{"is_test_data":true,"model":"TopicPrice","event":"TopicPrice.update","updated_fields":["guidance_price_cpc","guidance_price_cpm"],"id":"2"}}' }
5
+ let(:payload) { "[#{event_payload}]" }
6
+
7
+ subject { Adcloud::Webhook.new(payload) }
8
+
9
+ describe '.new' do
10
+ it 'takes an array as argument' do
11
+ Adcloud::Webhook.new([]).events.must_equal []
12
+ end
13
+
14
+ it 'takes a json string as argument' do
15
+ Adcloud::Webhook.new('[]').events.must_equal []
16
+ end
17
+
18
+ it 'fails with an argument error' do
19
+ -> { Adcloud::Webhook.new('').events }.must_raise ArgumentError
20
+ end
21
+
22
+ it 'fails without an argument' do
23
+ -> { Adcloud::Webhook.new().events }.must_raise ArgumentError
24
+ end
25
+ end
26
+
27
+ describe '#events=' do
28
+ describe 'configured to ignore test data' do
29
+ before { Adcloud.config.webhooks.filter_tests = true }
30
+
31
+ it 'removes test calls' do
32
+ subject.events.length.must_equal 0
33
+ end
34
+ end
35
+
36
+ describe 'configured to process test data' do
37
+ before { Adcloud.config.webhooks.filter_tests = false }
38
+
39
+ it 'keeps test calls' do
40
+ subject.events.length.must_equal 1
41
+ end
42
+ end
43
+ end
44
+
45
+ describe '#process!' do
46
+ it 'calls the configured proc' do
47
+ the_proc = mock(:call => true)
48
+ Adcloud.config.webhooks.expects(:on_topic_price_update).returns(the_proc)
49
+ subject.process!
50
+ end
51
+
52
+ describe 'with multiple events' do
53
+ let(:payload) { "[#{event_payload},#{event_payload}]" }
54
+
55
+ it 'iterates over all events' do
56
+ the_proc = stub(:call => true)
57
+ Adcloud.config.webhooks.expects(:on_topic_price_update).twice.returns(the_proc)
58
+ subject.process!
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,47 @@
1
+ require 'test_helper'
2
+
3
+ describe "Adcloud" do
4
+
5
+ describe "Configuration" do
6
+
7
+ subject { Adcloud.config }
8
+
9
+ it "should return the default debug setting" do
10
+ subject.debug.must_equal false
11
+ end
12
+
13
+ it "should return the default port" do
14
+ subject.port.must_equal 443
15
+ end
16
+
17
+ it "should return the default protocol" do
18
+ subject.protocol.must_equal 'https'
19
+ end
20
+
21
+ it "should return the default host" do
22
+ subject.host.must_equal 'api.adcloud.com'
23
+ end
24
+
25
+ it "should return the default version" do
26
+ subject.api_version.must_equal 'v2'
27
+ end
28
+
29
+ it "should return the default open timout" do
30
+ subject.http_open_timeout.must_equal 5
31
+ end
32
+
33
+ it "should return the default read timeout" do
34
+ subject.http_read_timeout.must_equal 10
35
+ end
36
+
37
+ end
38
+
39
+ describe "Logger" do
40
+
41
+ it "should be a logger" do
42
+ Adcloud.logger.must_be_instance_of Logger
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,23 @@
1
+ require 'simplecov'
2
+ SimpleCov.start 'rails'
3
+
4
+ require 'rubygems'
5
+ require 'bundler'
6
+ require 'minitest/mock'
7
+ require 'minitest/autorun'
8
+ require 'minitest/pride'
9
+ require 'webmock/minitest'
10
+ require 'mocha'
11
+
12
+ begin
13
+ Bundler.setup(:default, :development)
14
+ rescue Bundler::BundlerError => e
15
+ $stderr.puts e.message
16
+ $stderr.puts "Run `bundle install` to install missing gems"
17
+ exit e.status_code
18
+ end
19
+
20
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
21
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
22
+
23
+ require 'adcloud'
metadata ADDED
@@ -0,0 +1,251 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: adcloud
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jan Kus
9
+ - Max Schulz
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-09-13 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: minitest
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 3.4.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 3.4.0
31
+ - !ruby/object:Gem::Dependency
32
+ name: mocha
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 0.12.4
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 0.12.4
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: simplecov
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ - !ruby/object:Gem::Dependency
80
+ name: webmock
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: virtus
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activesupport
113
+ requirement: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ~>
117
+ - !ruby/object:Gem::Version
118
+ version: 3.2.6
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ none: false
123
+ requirements:
124
+ - - ~>
125
+ - !ruby/object:Gem::Version
126
+ version: 3.2.6
127
+ - !ruby/object:Gem::Dependency
128
+ name: faraday
129
+ requirement: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ! '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ type: :runtime
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ - !ruby/object:Gem::Dependency
144
+ name: faraday_middleware
145
+ requirement: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ type: :runtime
152
+ prerelease: false
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ none: false
155
+ requirements:
156
+ - - ! '>='
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ description: This is the official adcloud API gem. If you have any problems or requests
160
+ please contact api@adcloud.com.
161
+ email:
162
+ - jan@railslove.com
163
+ - m.schulz@kulturfluss.de
164
+ executables: []
165
+ extensions: []
166
+ extra_rdoc_files: []
167
+ files:
168
+ - .document
169
+ - .gitignore
170
+ - .travis.yml
171
+ - Gemfile
172
+ - Gemfile.lock
173
+ - LICENSE.txt
174
+ - README.md
175
+ - RELEASE_NOTES.md
176
+ - Rakefile
177
+ - adcloud.gemspec
178
+ - lib/adcloud.rb
179
+ - lib/adcloud/advertisement.rb
180
+ - lib/adcloud/api_error.rb
181
+ - lib/adcloud/authentication.rb
182
+ - lib/adcloud/campaign.rb
183
+ - lib/adcloud/connection.rb
184
+ - lib/adcloud/customer.rb
185
+ - lib/adcloud/entity.rb
186
+ - lib/adcloud/exception_raiser.rb
187
+ - lib/adcloud/media_file.rb
188
+ - lib/adcloud/product.rb
189
+ - lib/adcloud/report.rb
190
+ - lib/adcloud/report_entry.rb
191
+ - lib/adcloud/response_error_handler.rb
192
+ - lib/adcloud/topic.rb
193
+ - lib/adcloud/topic_discount.rb
194
+ - lib/adcloud/version.rb
195
+ - lib/adcloud/webhook.rb
196
+ - lib/adcloud/webhook_config.rb
197
+ - lib/adcloud/webhook_event.rb
198
+ - test/adcloud/advertisement_test.rb
199
+ - test/adcloud/authentication_test.rb
200
+ - test/adcloud/campaign_test.rb
201
+ - test/adcloud/connection_test.rb
202
+ - test/adcloud/customer_test.rb
203
+ - test/adcloud/entity_test.rb
204
+ - test/adcloud/media_file_test.rb
205
+ - test/adcloud/product_test.rb
206
+ - test/adcloud/report_test.rb
207
+ - test/adcloud/topic_test.rb
208
+ - test/adcloud/webhook_event_test.rb
209
+ - test/adcloud/webhook_test.rb
210
+ - test/adcloud_test.rb
211
+ - test/test_helper.rb
212
+ homepage: http://adcloud.com/
213
+ licenses: []
214
+ post_install_message:
215
+ rdoc_options: []
216
+ require_paths:
217
+ - lib
218
+ required_ruby_version: !ruby/object:Gem::Requirement
219
+ none: false
220
+ requirements:
221
+ - - ! '>='
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ required_rubygems_version: !ruby/object:Gem::Requirement
225
+ none: false
226
+ requirements:
227
+ - - ! '>='
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ requirements: []
231
+ rubyforge_project:
232
+ rubygems_version: 1.8.24
233
+ signing_key:
234
+ specification_version: 3
235
+ summary: Wrapper for adcloud API
236
+ test_files:
237
+ - test/adcloud/advertisement_test.rb
238
+ - test/adcloud/authentication_test.rb
239
+ - test/adcloud/campaign_test.rb
240
+ - test/adcloud/connection_test.rb
241
+ - test/adcloud/customer_test.rb
242
+ - test/adcloud/entity_test.rb
243
+ - test/adcloud/media_file_test.rb
244
+ - test/adcloud/product_test.rb
245
+ - test/adcloud/report_test.rb
246
+ - test/adcloud/topic_test.rb
247
+ - test/adcloud/webhook_event_test.rb
248
+ - test/adcloud/webhook_test.rb
249
+ - test/adcloud_test.rb
250
+ - test/test_helper.rb
251
+ has_rdoc: