commission_junction 1.7.1 → 1.7.2
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.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/commission_junction.rb +18 -33
- data/lib/commission_junction/version.rb +1 -1
- data/test/commission_junction_test.rb +39 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e00330e15a7b42cf61330c9aa59685979dbdfd50
|
|
4
|
+
data.tar.gz: c56a45455189f9c159b871f70f9fdf22bdfcafb4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 41046a5ab67a67afe7efd89461180923740a47de1cf87ac2df6bc05b683be395da0f5a4382de0a4bf46f03c4d1ca39f6742ade2f964b901fa88d71dd46777c2a
|
|
7
|
+
data.tar.gz: f5e6df6e63b1007d415288a19def29301729d26e2fb4f922417deb5eceac987e292455df8affda7d09747f752d71b790f133a51aaf70cc9521894b86ddb303ef
|
data/README.md
CHANGED
data/lib/commission_junction.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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)
|
|
@@ -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.
|
|
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:
|
|
11
|
+
date: 2015-01-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|