adknowledge 0.0.4 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ gemspec
5
5
 
6
6
  group :development, :test do
7
7
  platforms :jruby do
8
+ gem 'jruby-openssl'
8
9
  gem 'gson'
9
10
  gem 'libxml-jruby'
10
11
  end
data/README.md CHANGED
@@ -100,7 +100,6 @@ For more details see the specs, and [ADK documentation](https://publisher.adknow
100
100
  TODO
101
101
  ----
102
102
  There are several things currently unfinished:
103
- * Error handling when requests are unsuccessful
104
103
  * Options/convenience methods for parsing pivot query results
105
104
  * Add an end-point for "lookup" API
106
105
 
@@ -1,6 +1,7 @@
1
1
  require "adknowledge/version"
2
2
 
3
3
  module Adknowledge
4
+ class Exception < ::Exception; end
4
5
  end
5
6
 
6
7
  require 'faraday_middleware/adknowledge'
@@ -76,7 +76,7 @@ module Adknowledge
76
76
  # @return [Array] mapped recipients
77
77
  def mapped_recipients
78
78
  return [] unless mapped?
79
- recipients.select{|r| r['success']}
79
+ recipients.select{ |r| r['success'] == true }
80
80
  end
81
81
 
82
82
  # Return all errored recipients
@@ -84,7 +84,7 @@ module Adknowledge
84
84
  # @return [Array] errored recipients
85
85
  def errored_recipients
86
86
  return [] unless mapped?
87
- recipients.select{|r| ! r['success']}
87
+ recipients.select{ |r| r['success'] == false }
88
88
  end
89
89
 
90
90
  # Set both click-domain and image-domain
@@ -188,7 +188,7 @@ module Adknowledge
188
188
  unless Adknowledge.token
189
189
  raise ArgumentError, 'Adknowledge token required to perform queries'
190
190
  end
191
- results.body['data'] if results.body.has_key?('data')
191
+ results
192
192
  end
193
193
 
194
194
 
@@ -199,9 +199,14 @@ module Adknowledge
199
199
  end
200
200
 
201
201
  def results
202
- @results ||= conn.get do |req|
202
+ raw_result = conn.get do |req|
203
203
  req.url '/performance.json', query_params
204
+ end.body
205
+
206
+ if raw_result['code'] > 200
207
+ raise Adknowledge::Exception, get_error_str(raw_result)
204
208
  end
209
+ @results ||= raw_result['data']
205
210
  end
206
211
 
207
212
  def conn
@@ -226,6 +231,12 @@ module Adknowledge
226
231
  value ? '1' : '0'
227
232
  end
228
233
 
234
+ def get_error_str raw_result
235
+ raw_result['messages'].map do |msg|
236
+ msg['message']
237
+ end.join(' ')
238
+ end
239
+
229
240
  def valid_pivot_values
230
241
  dimensions.keys + ['*']
231
242
  end
@@ -1,3 +1,3 @@
1
1
  module Adknowledge
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -238,7 +238,7 @@ describe Adknowledge::Integrated do
238
238
  context "single results" do
239
239
 
240
240
  before do
241
- VCR.use_cassette :map_single_success, record: :once do
241
+ VCR.use_cassette :map_single_success do
242
242
  integrated.map!
243
243
  end
244
244
  end
@@ -319,7 +319,7 @@ describe Adknowledge::Integrated do
319
319
  end
320
320
 
321
321
  before do
322
- VCR.use_cassette :map_multi_success, record: :once do
322
+ VCR.use_cassette :map_multi_success do
323
323
  integrated.map!
324
324
  end
325
325
  end
@@ -288,33 +288,53 @@ describe Adknowledge::Performance do
288
288
  limit(20)
289
289
  end
290
290
 
291
- before do
292
- VCR.use_cassette :performance, record: :once do
293
- performance.records
291
+ context "succesful" do
292
+
293
+ let :records do
294
+ VCR.use_cassette :performance do
295
+ performance.records
296
+ end
294
297
  end
295
- end
296
298
 
297
- subject do
298
- performance.records
299
- end
299
+ subject do
300
+ records
301
+ end
300
302
 
301
- it 'has results' do
302
- expect(subject).to be_an Array
303
- end
303
+ it 'has results' do
304
+ expect(subject).to be_an Array
305
+ end
304
306
 
305
- it 'has the correct dimensions' do
306
- expect(subject.first).to have_key 'subid'
307
- expect(subject.first).to have_key 'report_date'
308
- end
307
+ it 'has the correct dimensions' do
308
+ expect(subject.first).to have_key 'subid'
309
+ expect(subject.first).to have_key 'report_date'
310
+ end
309
311
 
310
- it 'has the correct measures' do
311
- expect(subject.first).to have_key 'paid_clicks'
312
- expect(subject.first).to have_key 'revenue'
313
- end
312
+ it 'has the correct measures' do
313
+ expect(subject.first).to have_key 'paid_clicks'
314
+ expect(subject.first).to have_key 'revenue'
315
+ end
316
+
317
+ it 'has the correct count' do
318
+ expect(subject.size).to eql 20
319
+ end
320
+
321
+ end # successful
322
+
323
+ context "unsuccessful" do
314
324
 
315
- it 'has the correct count' do
316
- expect(subject.size).to eql 20
325
+ let :error_str do
326
+ "The email/password or token provided does not match a " +
327
+ "valid account. Please try again."
328
+ end
329
+
330
+ it 'raises an exception' do
331
+ VCR.use_cassette :performance_errored do
332
+ expect{ performance.records }.
333
+ to raise_error(Adknowledge::Exception, error_str)
334
+ end
335
+ end
317
336
  end
318
337
 
319
- end
338
+ end # #records
339
+
320
340
  end
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.publisher.adknowledge.com/performance.json?dimensions=subid,report_date&limit=20&measures=revenue,paid_clicks&product_guid=*&product_id=2&start_date=1&token=b6d8610998e883b3a460fd2fcf71ead4
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.8.6
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - ! '*/*'
16
+ response:
17
+ status:
18
+ code: 401
19
+ message: Authorization Required
20
+ headers:
21
+ Date:
22
+ - Sun, 10 Mar 2013 19:04:43 GMT
23
+ Server:
24
+ - Apache/2.2.12 (Linux/SUSE)
25
+ X-Powered-By:
26
+ - PHP/5.3.8-ZS5.5.0 ZendServer/5.0
27
+ Set-Cookie:
28
+ - ZDEDebuggerPresent=php,phtml,php3; path=/
29
+ Cache-Control:
30
+ - no-cache, must-revalidate
31
+ Expires:
32
+ - Mon, 26 Jul 1997 05:00:00 GMT
33
+ Content-Length:
34
+ - '178'
35
+ Content-Type:
36
+ - application/json
37
+ body:
38
+ encoding: US-ASCII
39
+ string: ! '{"status":0,"data":[],"messages":[{"type":0,"message":"The email\/password
40
+ or token provided does not match a valid account. Please try again."}],"errors":[],"code":401,"time":0}'
41
+ http_version:
42
+ recorded_at: Sun, 10 Mar 2013 19:04:43 GMT
43
+ recorded_with: VCR 2.4.0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adknowledge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-10 00:00:00.000000000 Z
12
+ date: 2013-03-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pry
@@ -244,6 +244,7 @@ files:
244
244
  - spec/cassettes/map_multi_success.yml
245
245
  - spec/cassettes/map_single_success.yml
246
246
  - spec/cassettes/performance.yml
247
+ - spec/cassettes/performance_errored.yml
247
248
  - spec/spec_helper.rb
248
249
  homepage: ''
249
250
  licenses: []
@@ -257,12 +258,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
257
258
  - - ! '>='
258
259
  - !ruby/object:Gem::Version
259
260
  version: '0'
261
+ segments:
262
+ - 0
263
+ hash: -4552902463842622263
260
264
  required_rubygems_version: !ruby/object:Gem::Requirement
261
265
  none: false
262
266
  requirements:
263
267
  - - ! '>='
264
268
  - !ruby/object:Gem::Version
265
269
  version: '0'
270
+ segments:
271
+ - 0
272
+ hash: -4552902463842622263
266
273
  requirements: []
267
274
  rubyforge_project:
268
275
  rubygems_version: 1.8.24
@@ -276,5 +283,5 @@ test_files:
276
283
  - spec/cassettes/map_multi_success.yml
277
284
  - spec/cassettes/map_single_success.yml
278
285
  - spec/cassettes/performance.yml
286
+ - spec/cassettes/performance_errored.yml
279
287
  - spec/spec_helper.rb
280
- has_rdoc: