commission_junction 1.4.1 → 1.5.0

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.
data/README.md CHANGED
@@ -33,25 +33,37 @@ cj = CommissionJunction.new(DEVELOPER_KEY, WEBSITE_ID)
33
33
  # See http://help.cj.com/en/web_services/product_catalog_search_service_rest.htm
34
34
  # for the list of request and response parameters.
35
35
  cj.product_search('keywords' => '+blue +jeans',
36
- 'advertiser-ids' => 'joined',
37
- 'serviceable-area' => 'us',
38
- 'currency' => 'usd',
39
- 'records-per-page' => '5').each do |product|
40
- puts product.name
41
- puts product.price
42
- puts product.image_url
43
- puts ''
36
+ 'advertiser-ids' => 'joined',
37
+ 'serviceable-area' => 'us',
38
+ 'currency' => 'usd',
39
+ 'records-per-page' => '5').each do |product|
40
+ puts product.name
41
+ puts product.price
42
+ puts product.image_url
43
+ puts ''
44
44
  end
45
45
 
46
46
  # See http://help.cj.com/en/web_services/advertiser_lookup_service_rest.htm
47
47
  # for the list of request and response parameters.
48
48
  cj.advertiser_lookup('keywords' => '+used +books',
49
- 'advertiser-ids' => 'joined',
50
- 'records-per-page' => '5').each do |advertiser|
51
- puts advertiser.advertiser_name
52
- puts advertiser.network_rank
53
- puts advertiser.program_url
54
- puts ''
49
+ 'advertiser-ids' => 'joined',
50
+ 'records-per-page' => '5').each do |advertiser|
51
+ puts advertiser.advertiser_name
52
+ puts advertiser.network_rank
53
+ puts advertiser.program_url
54
+ puts ''
55
+ end
56
+
57
+ # See http://help.cj.com/en/web_services/link_search_service_rest.htm
58
+ # for the list of request and response parameters.
59
+ cj.link_search('keywords' => '+used +books',
60
+ 'advertiser-ids' => 'joined',
61
+ 'records-per-page' => '5').each do |link|
62
+ puts link.link_id
63
+ puts link.link_name
64
+ puts link.link_code_html
65
+ puts link.sale_commission
66
+ puts ''
55
67
  end
56
68
 
57
69
  # See http://help.cj.com/en/web_services/support_services_rest.htm
@@ -61,14 +73,14 @@ puts cj.categories
61
73
  # See http://help.cj.com/en/web_services/Commission_Detail_Service.htm
62
74
  # for the list of request and response parameters.
63
75
  cj.commissions.each do |commission|
64
- puts commission.action_type
65
- puts commission.aid
66
- puts commission.commission_id
67
- puts commission.event_date
68
- puts commission.advertiser_name
69
- puts commission.commission_amount
70
- puts commission.sid
71
- puts ''
76
+ puts commission.action_type
77
+ puts commission.aid
78
+ puts commission.commission_id
79
+ puts commission.event_date
80
+ puts commission.advertiser_name
81
+ puts commission.commission_amount
82
+ puts commission.sid
83
+ puts ''
72
84
  end
73
85
  ```
74
86
 
@@ -88,6 +100,7 @@ end
88
100
  * [C.J. Sanders](https://github.com/cjsanders)
89
101
  * [Michael Nutt](https://github.com/mnutt)
90
102
  * [Jean-Sebastien Boulanger](https://github.com/jsboulanger)
103
+ * [luckyjazzbo](https://github.com/luckyjazzbo)
91
104
 
92
105
  ## Copyright
93
106
 
@@ -27,6 +27,7 @@ class CommissionJunction
27
27
  WEB_SERVICE_URIS =
28
28
  {
29
29
  :product_search => 'https://product-search.api.cj.com/v2/product-search',
30
+ :link_search => 'https://link-search.api.cj.com/v2/link-search',
30
31
  :advertiser_lookup => 'https://advertiser-lookup.api.cj.com/v3/advertiser-lookup',
31
32
  :categories => 'https://support-services.api.cj.com/v2/categories',
32
33
  :commissions => 'https://commission-detail.api.cj.com/v3/commissions'
@@ -128,6 +129,41 @@ class CommissionJunction
128
129
  @cj_objects
129
130
  end
130
131
 
132
+ def link_search(params)
133
+ raise ArgumentError, "params must be a Hash; got #{params.class} instead" unless params.is_a?(Hash)
134
+
135
+ unless params.size > 0
136
+ raise ArgumentError, "You must provide at least one request parameter, for example, \"keywords\".\nSee http://help.cj.com/en/web_services/product_catalog_search_service_rest.htm"
137
+ end
138
+
139
+ params['website-id'] = @website_id
140
+
141
+ @cj_objects = []
142
+
143
+ begin
144
+ response = self.class.get(WEB_SERVICE_URIS[:link_search], :query => params, :timeout => @timeout)
145
+
146
+ cj_api = response['cj_api']
147
+ error_message = cj_api['error_message']
148
+
149
+ raise ArgumentError, error_message if error_message
150
+
151
+ links = cj_api['links']
152
+
153
+ @total_matched = links['total_matched'].to_i
154
+ @records_returned = links['records_returned'].to_i
155
+ @page_number = links['page_number'].to_i
156
+
157
+ link = links['link']
158
+ link = [link] if link.is_a?(Hash) # If we got exactly one result, put it in an array.
159
+ link.each { |item| @cj_objects << Link.new(item) } if link
160
+ rescue Timeout::Error
161
+ @total_matched = @records_returned = @page_number = 0
162
+ end
163
+
164
+ @cj_objects
165
+ end
166
+
131
167
  def commissions(params = {})
132
168
  raise ArgumentError, "params must be a Hash; got #{params.class} instead" unless params.is_a?(Hash)
133
169
 
@@ -179,6 +215,9 @@ class CommissionJunction
179
215
  class Advertiser < CjObject
180
216
  end
181
217
 
218
+ class Link < CjObject
219
+ end
220
+
182
221
  class Commission < CjObject
183
222
  end
184
223
  end
@@ -1,3 +1,3 @@
1
1
  class CommissionJunction
2
- VERSION = '1.4.1'
2
+ VERSION = '1.5.0'
3
3
  end
@@ -218,7 +218,7 @@ class CommissionJunctionTest < Test::Unit::TestCase
218
218
  key_file = File.join(ENV['HOME'], '.commission_junction.yaml')
219
219
 
220
220
  skip "#{key_file} does not exist. Put your CJ developer key and website ID in there to enable live testing." unless File.exist?(key_file)
221
-
221
+
222
222
  credentials = YAML.load(File.read(key_file))
223
223
  cj = CommissionJunction.new(credentials['developer_key'], credentials['website_id'])
224
224
 
@@ -337,4 +337,51 @@ class CommissionJunctionTest < Test::Unit::TestCase
337
337
  assert_respond_to(commission, :sale_amount)
338
338
  end
339
339
  end
340
+
341
+ def test_link_search_live
342
+ key_file = File.join(ENV['HOME'], '.commission_junction.yaml')
343
+
344
+ skip "#{key_file} does not exist. Put your CJ developer key and website ID in there to enable live testing." unless File.exist?(key_file)
345
+
346
+ credentials = YAML.load(File.read(key_file))
347
+ cj = CommissionJunction.new(credentials['developer_key'], credentials['website_id'])
348
+
349
+ assert_nothing_raised do
350
+ cj.link_search('keywords' => '+blue +jeans', 'advertiser-ids' => 'joined')
351
+ end
352
+
353
+ check_link_search_results(cj)
354
+ end
355
+
356
+ def check_link_search_results(results)
357
+ assert_instance_of(Fixnum, results.total_matched)
358
+ assert_instance_of(Fixnum, results.records_returned)
359
+ assert_instance_of(Fixnum, results.page_number)
360
+ assert_instance_of(Array, results.cj_objects)
361
+
362
+ results.cj_objects.each do |link|
363
+ assert_instance_of(CommissionJunction::Link, link)
364
+ assert_respond_to(link, :advertiser_id)
365
+ assert_respond_to(link, :click_commission)
366
+ assert_respond_to(link, :creative_height)
367
+ assert_respond_to(link, :creative_width)
368
+ assert_respond_to(link, :lead_commission)
369
+ assert_respond_to(link, :link_code_html)
370
+ assert_respond_to(link, :link_code_javascript)
371
+ assert_respond_to(link, :destination)
372
+ assert_respond_to(link, :description)
373
+ assert_respond_to(link, :link_id)
374
+ assert_respond_to(link, :link_name)
375
+ assert_respond_to(link, :link_type)
376
+ assert_respond_to(link, :advertiser_name)
377
+ assert_respond_to(link, :performance_incentive)
378
+ assert_respond_to(link, :promotion_type)
379
+ assert_respond_to(link, :promotion_start_date)
380
+ assert_respond_to(link, :promotion_end_date)
381
+ assert_respond_to(link, :relationship_status)
382
+ assert_respond_to(link, :sale_commission)
383
+ assert_respond_to(link, :seven_day_epc)
384
+ assert_respond_to(link, :three_month_epc)
385
+ end
386
+ end
340
387
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commission_junction
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
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: 2012-09-03 00:00:00.000000000 Z
12
+ date: 2012-12-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -55,18 +55,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
55
  - - ! '>='
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
- segments:
59
- - 0
60
- hash: 2510825910021186561
61
58
  required_rubygems_version: !ruby/object:Gem::Requirement
62
59
  none: false
63
60
  requirements:
64
61
  - - ! '>='
65
62
  - !ruby/object:Gem::Version
66
63
  version: '0'
67
- segments:
68
- - 0
69
- hash: 2510825910021186561
70
64
  requirements: []
71
65
  rubyforge_project:
72
66
  rubygems_version: 1.8.24