commission_junction 1.7.1 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bafc377290960323c66d4b5f9896d87e42ab50fc
4
- data.tar.gz: cf4ddcb839f9b1874c7f78fd1125ff9f08a129df
3
+ metadata.gz: e00330e15a7b42cf61330c9aa59685979dbdfd50
4
+ data.tar.gz: c56a45455189f9c159b871f70f9fdf22bdfcafb4
5
5
  SHA512:
6
- metadata.gz: 79688b4fc4c47888685c67652ef547c256f83d5758a2f9a6d7cb8c4316d0e95a398e203dce167dd8a962b4a2bb509c198dee62136355420ded3eb9e7711ef4ce
7
- data.tar.gz: b318559c47762d3092bdfdf0ecf7d6e79832e258e45be7ff43272e8670e55fecec7ad2d387012d87e2dc24af38d20732c1482c18be323422f2c1259a191f9b05
6
+ metadata.gz: 41046a5ab67a67afe7efd89461180923740a47de1cf87ac2df6bc05b683be395da0f5a4382de0a4bf46f03c4d1ca39f6742ade2f964b901fa88d71dd46777c2a
7
+ data.tar.gz: f5e6df6e63b1007d415288a19def29301729d26e2fb4f922417deb5eceac987e292455df8affda7d09747f752d71b790f133a51aaf70cc9521894b86ddb303ef
data/README.md CHANGED
@@ -104,6 +104,7 @@ end
104
104
  * [Michael Nutt](https://github.com/mnutt)
105
105
  * [Jean-Sebastien Boulanger](https://github.com/jsboulanger)
106
106
  * [luckyjazzbo](https://github.com/luckyjazzbo)
107
+ * [samsaradog](https://github.com/samsaradog)
107
108
 
108
109
  ## Copyright
109
110
 
@@ -45,13 +45,7 @@ class CommissionJunction
45
45
  params = {'locale' => 'en'}.merge(params)
46
46
 
47
47
  response = self.class.get(WEB_SERVICE_URIS[:categories], :query => params, :timeout => @timeout)
48
-
49
- cj_api = response['cj_api']
50
- error_message = cj_api['error_message']
51
-
52
- raise ArgumentError, error_message if error_message
53
-
54
- @categories = cj_api['categories']['category']
48
+ @categories = extract_contents(response, 'categories', 'category')
55
49
  end
56
50
 
57
51
  def advertiser_lookup(params = {})
@@ -63,12 +57,7 @@ class CommissionJunction
63
57
 
64
58
  begin
65
59
  response = self.class.get(WEB_SERVICE_URIS[:advertiser_lookup], :query => params)
66
- cj_api = response['cj_api']
67
- error_message = cj_api['error_message']
68
-
69
- raise ArgumentError, error_message if error_message
70
-
71
- advertisers = cj_api['advertisers']
60
+ advertisers = extract_contents(response, 'advertisers')
72
61
 
73
62
  @total_matched = advertisers['total_matched'].to_i
74
63
  @records_returned = advertisers['records_returned'].to_i
@@ -97,13 +86,7 @@ class CommissionJunction
97
86
 
98
87
  begin
99
88
  response = self.class.get(WEB_SERVICE_URIS[:product_search], :query => params, :timeout => @timeout)
100
-
101
- cj_api = response['cj_api']
102
- error_message = cj_api['error_message']
103
-
104
- raise ArgumentError, error_message if error_message
105
-
106
- products = cj_api['products']
89
+ products = extract_contents(response, 'products')
107
90
 
108
91
  @total_matched = products['total_matched'].to_i
109
92
  @records_returned = products['records_returned'].to_i
@@ -132,13 +115,7 @@ class CommissionJunction
132
115
 
133
116
  begin
134
117
  response = self.class.get(WEB_SERVICE_URIS[:link_search], :query => params, :timeout => @timeout)
135
-
136
- cj_api = response['cj_api']
137
- error_message = cj_api['error_message']
138
-
139
- raise ArgumentError, error_message if error_message
140
-
141
- links = cj_api['links']
118
+ links = extract_contents(response, 'links')
142
119
 
143
120
  @total_matched = links['total_matched'].to_i
144
121
  @records_returned = links['records_returned'].to_i
@@ -163,12 +140,7 @@ class CommissionJunction
163
140
 
164
141
  begin
165
142
  response = self.class.get(WEB_SERVICE_URIS[:commissions], :query => params)
166
- cj_api = response['cj_api']
167
- error_message = cj_api['error_message']
168
-
169
- raise ArgumentError, error_message if error_message
170
-
171
- commissions = cj_api['commissions']
143
+ commissions = extract_contents(response, 'commissions')
172
144
 
173
145
  @total_matched = commissions['total_matched'].to_i
174
146
  @records_returned = commissions['records_returned'].to_i
@@ -184,6 +156,19 @@ class CommissionJunction
184
156
  @cj_objects
185
157
  end
186
158
 
159
+ def extract_contents(response, first_level, second_level=nil)
160
+ cj_api = response['cj_api']
161
+
162
+ raise ArgumentError, "cj api missing from response" if cj_api.nil?
163
+
164
+ error_message = cj_api['error_message']
165
+
166
+ raise ArgumentError, error_message if error_message
167
+
168
+ return cj_api[first_level] if second_level.nil?
169
+ cj_api[first_level][second_level]
170
+ end
171
+
187
172
  class CjObject
188
173
  def initialize(params)
189
174
  raise ArgumentError, "params must be a Hash; got #{params.class} instead" unless params.is_a?(Hash)
@@ -1,3 +1,3 @@
1
1
  class CommissionJunction
2
- VERSION = '1.7.1'
2
+ VERSION = '1.7.2'
3
3
  end
@@ -388,4 +388,43 @@ class CommissionJunctionTest < Minitest::Test
388
388
  assert_respond_to(link, :three_month_epc)
389
389
  end
390
390
  end
391
+
392
+ def test_contents_extractor_with_first_level
393
+ contents = "abc"
394
+ response = {'cj_api' => {'first' => contents}}
395
+
396
+ cj = CommissionJunction.new('developer_key', 123456)
397
+
398
+ assert_equal(contents, cj.extract_contents(response, "first"))
399
+ end
400
+
401
+ def test_contents_extractor_with_second_level
402
+ contents = "abc"
403
+ response = {'cj_api' => {'first' => {'second' => contents}}}
404
+
405
+ cj = CommissionJunction.new('developer_key', 123456)
406
+
407
+ assert_equal(contents, cj.extract_contents(response, "first", "second"))
408
+ end
409
+
410
+ def test_contents_extractor_with_error_message
411
+ contents = "abc"
412
+ response = {'cj_api' => {'error_message' => contents}}
413
+
414
+ cj = CommissionJunction.new('developer_key', 123456)
415
+
416
+ assert_raises ArgumentError do
417
+ cj.extract_contents(response, "first")
418
+ end
419
+ end
420
+
421
+ def test_contents_extractor_with_no_cj_api
422
+ response = {}
423
+
424
+ cj = CommissionJunction.new('developer_key', 123456)
425
+
426
+ assert_raises ArgumentError do
427
+ cj.extract_contents(response, "first")
428
+ end
429
+ end
391
430
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commission_junction
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Albert Vernon
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-15 00:00:00.000000000 Z
11
+ date: 2015-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty