commission_junction 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ pkg
2
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ # Specify your gem's dependencies in commission_junction.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2012, Albert Vernon
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+ * Redistributions of source code must retain the above copyright notice,
7
+ this list of conditions and the following disclaimer.
8
+ * Redistributions in binary form must reproduce the above copyright notice,
9
+ this list of conditions and the following disclaimer in the documentation
10
+ and/or other materials provided with the distribution.
11
+ * The names of its contributors may not be used to endorse or promote
12
+ products derived from this software without specific prior written
13
+ permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18
+ DISCLAIMED. IN NO EVENT SHALL ALBERT VERNON BE LIABLE FOR ANY DIRECT, INDIRECT,
19
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
23
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # commission_junction
2
+
3
+ Ruby wrapper for the Commission Junction web services APIs (REST)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ `gem 'commission_junction'`
10
+
11
+ And then execute
12
+
13
+ `bundle`
14
+
15
+ Or install it yourself as:
16
+
17
+ `gem install commission_junction`
18
+
19
+ ## Example
20
+
21
+ ```ruby
22
+ require 'rubygems'
23
+ require 'commission_junction'
24
+
25
+ # See https://api.cj.com/sign_up.cj
26
+ DEVELOPER_KEY = '????????'
27
+
28
+ # See cj.com > Account > Web site Settings > PID
29
+ WEBSITE_ID = '????????'
30
+
31
+ cj = CommissionJunction.new(DEVELOPER_KEY, WEBSITE_ID)
32
+
33
+ # See http://help.cj.com/en/web_services/product_catalog_search_service_rest.htm
34
+ # for the list of request and response parameters.
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 ''
44
+ end
45
+
46
+ # See http://help.cj.com/en/web_services/advertiser_lookup_service_rest.htm
47
+ # for the list of request and response parameters.
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 ''
55
+ end
56
+
57
+ # See http://help.cj.com/en/web_services/support_services_rest.htm
58
+ # for the list of request and response parameters.
59
+ puts cj.categories
60
+
61
+ # See http://help.cj.com/en/web_services/Commission_Detail_Service.htm
62
+ # for the list of request and response parameters.
63
+ 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 ''
72
+ end
73
+ ```
74
+
75
+ ## Dependencies
76
+
77
+ * httparty
78
+
79
+ ## Contributing
80
+
81
+ * Feel free to file a bug report or enhancement request, even if you don't have time to submit a patch.
82
+ * Please try to include a test for any patch you submit. If you don't include a test, I'll have to write one, and it'll take longer to get your code in.
83
+ * Remember to send me a pull request.
84
+
85
+ ## Authors
86
+
87
+ * [Albert Vernon](https://github.com/aevernon)
88
+ * [C.J. Sanders](https://github.com/cjsanders)
89
+ * [Michael Nutt](https://github.com/mnutt)
90
+ * [Jean-Sebastien Boulanger](https://github.com/jsboulanger)
91
+
92
+ ## Copyright
93
+
94
+ Copyright (c) 2012 Albert Vernon. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |test|
5
+ test.libs << 'lib' << 'test'
6
+ test.pattern = 'test/**/*_test.rb'
7
+ test.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'commission_junction/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'commission_junction'
8
+ gem.version = CommissionJunction::VERSION
9
+ gem.author = 'Albert Vernon'
10
+ gem.email = 'aev@vernon.nu'
11
+ gem.description = %q{Ruby wrapper for the Commission Junction web services APIs (REST)}
12
+ gem.summary = %q{Commission Junction web services APIs (REST)}
13
+ gem.homepage = %q{https://github.com/aevernon/commission_junction}
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
19
+ gem.add_dependency 'httparty', '~> 0.8.3'
20
+ end
@@ -0,0 +1,3 @@
1
+ class CommissionJunction
2
+ VERSION = '1.4.1'
3
+ end
@@ -0,0 +1,184 @@
1
+ require 'commission_junction/version'
2
+ require 'httparty'
3
+
4
+ # Silence peer certificate warnings from Net::HTTP.
5
+ # Credit: http://www.5dollarwhitebox.org/drupal/node/64
6
+ class Net::HTTP
7
+ alias_method :old_initialize, :initialize
8
+
9
+ def initialize(*args)
10
+ old_initialize(*args)
11
+ @ssl_context = OpenSSL::SSL::SSLContext.new
12
+ @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
13
+ end
14
+ end
15
+
16
+ # Interact with CJ web services.
17
+ class CommissionJunction
18
+ include HTTParty
19
+ format(:xml)
20
+ #debug_output $stderr
21
+
22
+ attr_reader :total_matched,
23
+ :records_returned,
24
+ :page_number,
25
+ :cj_objects
26
+
27
+ WEB_SERVICE_URIS =
28
+ {
29
+ :product_search => 'https://product-search.api.cj.com/v2/product-search',
30
+ :advertiser_lookup => 'https://advertiser-lookup.api.cj.com/v3/advertiser-lookup',
31
+ :categories => 'https://support-services.api.cj.com/v2/categories',
32
+ :commissions => 'https://commission-detail.api.cj.com/v3/commissions'
33
+ }
34
+
35
+ def initialize(developer_key, website_id, timeout = 10)
36
+ raise ArgumentError, "developer_key must be a String; got #{developer_key.class} instead" unless developer_key.is_a?(String)
37
+ raise ArgumentError, "You must supply your developer key.\nSee https://api.cj.com/sign_up.cj" unless developer_key.length > 0
38
+
39
+ website_id = website_id.to_s
40
+ raise ArgumentError, "You must supply your website ID.\nSee cj.com > Account > Web site Settings > PID" unless website_id.length > 0
41
+ @website_id = website_id
42
+
43
+ raise ArgumentError, "timeout must be a Fixnum; got #{timeout.class} instead" unless timeout.is_a?(Fixnum)
44
+ raise ArgumentError, "timeout must be > 0; got #{timeout} instead" unless timeout > 0
45
+ @timeout = timeout
46
+
47
+ self_class = self.class
48
+ self_class.headers('authorization' => developer_key)
49
+ end
50
+
51
+ def categories(params = {})
52
+ raise ArgumentError, "params must be a Hash; got #{params.class} instead" unless params.is_a?(Hash)
53
+
54
+ params = {'locale' => 'en'}.merge(params)
55
+
56
+ response = self.class.get(WEB_SERVICE_URIS[:categories], :query => params, :timeout => @timeout)
57
+
58
+ cj_api = response['cj_api']
59
+ error_message = cj_api['error_message']
60
+
61
+ raise ArgumentError, error_message if error_message
62
+
63
+ @categories = cj_api['categories']['category']
64
+ end
65
+
66
+ def advertiser_lookup(params = {})
67
+ raise ArgumentError, "params must be a Hash; got #{params.class} instead" unless params.is_a?(Hash)
68
+
69
+ params = {'advertiser-ids' => 'joined'}.merge(params)
70
+
71
+ @cj_objects = []
72
+
73
+ begin
74
+ response = self.class.get(WEB_SERVICE_URIS[:advertiser_lookup], :query => params)
75
+ cj_api = response['cj_api']
76
+ error_message = cj_api['error_message']
77
+
78
+ raise ArgumentError, error_message if error_message
79
+
80
+ advertisers = cj_api['advertisers']
81
+
82
+ @total_matched = advertisers['total_matched'].to_i
83
+ @records_returned = advertisers['records_returned'].to_i
84
+ @page_number = advertisers['page_number'].to_i
85
+
86
+ advertiser = advertisers['advertiser']
87
+ advertiser = [advertiser] if advertiser.is_a?(Hash) # If we got exactly one result, put it in an array.
88
+ advertiser.each { |item| @cj_objects << Advertiser.new(item) } if advertiser
89
+ rescue Timeout::Error
90
+ @total_matched = @records_returned = @page_number = 0
91
+ end
92
+
93
+ @cj_objects
94
+ end
95
+
96
+ def product_search(params)
97
+ raise ArgumentError, "params must be a Hash; got #{params.class} instead" unless params.is_a?(Hash)
98
+
99
+ unless params.size > 0
100
+ 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"
101
+ end
102
+
103
+ params['website-id'] = @website_id
104
+
105
+ @cj_objects = []
106
+
107
+ begin
108
+ response = self.class.get(WEB_SERVICE_URIS[:product_search], :query => params, :timeout => @timeout)
109
+
110
+ cj_api = response['cj_api']
111
+ error_message = cj_api['error_message']
112
+
113
+ raise ArgumentError, error_message if error_message
114
+
115
+ products = cj_api['products']
116
+
117
+ @total_matched = products['total_matched'].to_i
118
+ @records_returned = products['records_returned'].to_i
119
+ @page_number = products['page_number'].to_i
120
+
121
+ product = products['product']
122
+ product = [product] if product.is_a?(Hash) # If we got exactly one result, put it in an array.
123
+ product.each { |item| @cj_objects << Product.new(item) } if product
124
+ rescue Timeout::Error
125
+ @total_matched = @records_returned = @page_number = 0
126
+ end
127
+
128
+ @cj_objects
129
+ end
130
+
131
+ def commissions(params = {})
132
+ raise ArgumentError, "params must be a Hash; got #{params.class} instead" unless params.is_a?(Hash)
133
+
134
+ params = {'date-type' => 'event'}.merge(params)
135
+
136
+ @cj_objects = []
137
+
138
+ begin
139
+ response = self.class.get(WEB_SERVICE_URIS[:commissions], :query => params)
140
+ cj_api = response['cj_api']
141
+ error_message = cj_api['error_message']
142
+
143
+ raise ArgumentError, error_message if error_message
144
+
145
+ commissions = cj_api['commissions']
146
+
147
+ @total_matched = commissions['total_matched'].to_i
148
+ @records_returned = commissions['records_returned'].to_i
149
+ @page_number = commissions['page_number'].to_i
150
+
151
+ commission = commissions['commission']
152
+ commission = [commission] if commission.is_a?(Hash) # If we got exactly one result, put it in an array.
153
+ commission.each { |item| @cj_objects << Commission.new(item) } if commission
154
+ rescue Timeout::Error
155
+ @total_matched = @records_returned = @page_number = 0
156
+ end
157
+
158
+ @cj_objects
159
+ end
160
+
161
+ class CjObject
162
+ def initialize(params)
163
+ raise ArgumentError, "params must be a Hash; got #{params.class} instead" unless params.is_a?(Hash)
164
+ raise ArgumentError, 'Expecting at least one parameter' unless params.size > 0
165
+
166
+ # Create instance variables and attribute readers on the fly.
167
+ # Credit: http://listlibrary.net/ruby-talk/2004/03/00sGI1cD
168
+ params.each do |key, val|
169
+ raise ArgumentError, "key must be a String; got #{key.class} instead" unless key.is_a?(String)
170
+ instance_variable_set("@#{key}".intern, val)
171
+ instance_eval %Q{ class << self ; attr_reader #{key.intern.inspect} ; end }
172
+ end
173
+ end
174
+ end
175
+
176
+ class Product < CjObject
177
+ end
178
+
179
+ class Advertiser < CjObject
180
+ end
181
+
182
+ class Commission < CjObject
183
+ end
184
+ end
@@ -0,0 +1,340 @@
1
+ require 'test_helper'
2
+
3
+ class CommissionJunctionTest < Test::Unit::TestCase
4
+ def test_new_cj_with_no_params
5
+ assert_raise ArgumentError do
6
+ CommissionJunction.new
7
+ end
8
+ end
9
+
10
+ def test_new_cj_with_one_param
11
+ assert_raise ArgumentError do
12
+ CommissionJunction.new('fake')
13
+ end
14
+ end
15
+
16
+ def test_new_cj_with_nil_param
17
+ assert_raise ArgumentError do
18
+ CommissionJunction.new(nil, 'website_id')
19
+ end
20
+
21
+ assert_raise ArgumentError do
22
+ CommissionJunction.new('developer_key', nil)
23
+ end
24
+
25
+ assert_raise ArgumentError do
26
+ CommissionJunction.new('developer_key', 'website_id', nil)
27
+ end
28
+ end
29
+
30
+ def test_new_cj_with_empty_param
31
+ assert_raise ArgumentError do
32
+ CommissionJunction.new('', 'website_id')
33
+ end
34
+
35
+ assert_raise ArgumentError do
36
+ CommissionJunction.new('developer_key', '')
37
+ end
38
+ end
39
+
40
+ def test_new_cj_with_non_string_param
41
+ assert_raise ArgumentError do
42
+ CommissionJunction.new(123456, 'website_id')
43
+ end
44
+
45
+ assert_nothing_raised ArgumentError do
46
+ CommissionJunction.new('developer_key', 123456)
47
+ end
48
+ end
49
+
50
+ def test_new_cj_with_non_fixnum_timeout
51
+ assert_raise ArgumentError do
52
+ CommissionJunction.new('developer_key', 'website_id', '10')
53
+ end
54
+ end
55
+
56
+ def test_new_cj_with_non_positive_timeout
57
+ assert_raise ArgumentError do
58
+ CommissionJunction.new('developer_key', 'website_id', 0)
59
+ end
60
+
61
+ assert_raise ArgumentError do
62
+ CommissionJunction.new('developer_key', 'website_id', -1)
63
+ end
64
+ end
65
+
66
+ def test_new_cj_with_correct_types
67
+ assert_nothing_raised do
68
+ assert_instance_of(CommissionJunction, CommissionJunction.new('developer_key', 'website_id'))
69
+ end
70
+
71
+ assert_nothing_raised do
72
+ assert_instance_of(CommissionJunction, CommissionJunction.new('developer_key', 'website_id', 50))
73
+ end
74
+ end
75
+
76
+ def test_new_product_with_no_params
77
+ assert_raise ArgumentError do
78
+ CommissionJunction::Product.new
79
+ end
80
+ end
81
+
82
+ def test_new_product_with_nil_params
83
+ assert_raise ArgumentError do
84
+ CommissionJunction::Product.new(nil)
85
+ end
86
+ end
87
+
88
+ def test_new_product_with_empty_params
89
+ assert_raise ArgumentError do
90
+ CommissionJunction::Product.new({})
91
+ end
92
+ end
93
+
94
+ def test_new_product_with_non_hash_params
95
+ assert_raise ArgumentError do
96
+ CommissionJunction::Product.new([1, 2, 3])
97
+ end
98
+ end
99
+
100
+ def test_new_product_with_hash_params_and_non_string_keys
101
+ assert_raise ArgumentError do
102
+ CommissionJunction::Product.new(:name => 'blue jeans', :price => '49.95')
103
+ end
104
+ end
105
+
106
+ def test_new_product_with_hash_params_and_string_keys
107
+ assert_nothing_raised do
108
+ product = CommissionJunction::Product.new('name' => 'blue jeans', 'price' => '49.95')
109
+ assert_instance_of(CommissionJunction::Product, product)
110
+ assert_respond_to(product, :name)
111
+ assert_equal('blue jeans', product.name)
112
+ assert_respond_to(product, :price)
113
+ assert_equal('49.95', product.price)
114
+ end
115
+ end
116
+
117
+ def test_product_search_with_no_params
118
+ assert_raise ArgumentError do
119
+ CommissionJunction.new('developer_key', 'website_id').product_search
120
+ end
121
+ end
122
+
123
+ def test_product_search_with_nil_params
124
+ assert_raise ArgumentError do
125
+ CommissionJunction.new('developer_key', 'website_id').product_search(nil)
126
+ end
127
+ end
128
+
129
+ def test_product_search_with_empty_params
130
+ assert_raise ArgumentError do
131
+ CommissionJunction.new('developer_key', 'website_id').product_search({})
132
+ end
133
+ end
134
+
135
+ def test_product_search_with_non_hash_params
136
+ assert_raise ArgumentError do
137
+ CommissionJunction.new('developer_key', 'website_id').product_search([1, 2, 3])
138
+ end
139
+ end
140
+
141
+ def test_product_search_with_bad_key
142
+ cj = CommissionJunction.new('bad_key', 'website_id')
143
+
144
+ assert_raise ArgumentError do
145
+ cj.product_search('keywords' => '+some +product')
146
+ end
147
+ end
148
+
149
+ def test_product_search_with_keywords_live
150
+ key_file = File.join(ENV['HOME'], '.commission_junction.yaml')
151
+
152
+ 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)
153
+
154
+ credentials = YAML.load(File.read(key_file))
155
+ cj = CommissionJunction.new(credentials['developer_key'], credentials['website_id'])
156
+
157
+ # Zero results
158
+ assert_nothing_raised do
159
+ cj.product_search('keywords' => 'no_matching_results')
160
+ end
161
+
162
+ check_search_results(cj)
163
+
164
+ # One result
165
+ assert_nothing_raised do
166
+ cj.product_search('keywords' => '+blue +jeans', 'records-per-page' => '1')
167
+ end
168
+
169
+ check_search_results(cj)
170
+
171
+ # Multiple results
172
+ assert_nothing_raised do
173
+ cj.product_search('keywords' => '+blue +jeans', 'records-per-page' => '2')
174
+ end
175
+
176
+ check_search_results(cj)
177
+
178
+ # Short timeout
179
+ cj = CommissionJunction.new(credentials['developer_key'], credentials['website_id'], 1)
180
+
181
+ assert_nothing_raised do
182
+ cj.product_search('keywords' => 'One Great Blue Jean~No Limits', 'records-per-page' => '1')
183
+ end
184
+
185
+ check_search_results(cj)
186
+ end
187
+
188
+ def check_search_results(results)
189
+ assert_instance_of(Fixnum, results.total_matched)
190
+ assert_instance_of(Fixnum, results.records_returned)
191
+ assert_instance_of(Fixnum, results.page_number)
192
+ assert_instance_of(Array, results.cj_objects)
193
+
194
+ results.cj_objects.each do |product|
195
+ assert_instance_of(CommissionJunction::Product, product)
196
+ assert_respond_to(product, :ad_id)
197
+ assert_respond_to(product, :advertiser_id)
198
+ assert_respond_to(product, :advertiser_name)
199
+ assert_respond_to(product, :buy_url)
200
+ assert_respond_to(product, :catalog_id)
201
+ assert_respond_to(product, :currency)
202
+ assert_respond_to(product, :description)
203
+ assert_respond_to(product, :image_url)
204
+ assert_respond_to(product, :in_stock)
205
+ assert_respond_to(product, :isbn)
206
+ assert_respond_to(product, :manufacturer_name)
207
+ assert_respond_to(product, :manufacturer_sku)
208
+ assert_respond_to(product, :name)
209
+ assert_respond_to(product, :price)
210
+ assert_respond_to(product, :retail_price)
211
+ assert_respond_to(product, :sale_price)
212
+ assert_respond_to(product, :sku)
213
+ assert_respond_to(product, :upc)
214
+ end
215
+ end
216
+
217
+ def test_advertiser_lookup_live
218
+ key_file = File.join(ENV['HOME'], '.commission_junction.yaml')
219
+
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
+
222
+ credentials = YAML.load(File.read(key_file))
223
+ cj = CommissionJunction.new(credentials['developer_key'], credentials['website_id'])
224
+
225
+ # Use default lookup parameters.
226
+ assert_nothing_raised do
227
+ cj.advertiser_lookup
228
+ end
229
+
230
+ check_advertiser_lookup_results(cj)
231
+
232
+ # One result
233
+ assert_nothing_raised do
234
+ cj.advertiser_lookup('advertiser-ids' => 'joined', 'page-number' => '1')
235
+ end
236
+
237
+ check_advertiser_lookup_results(cj)
238
+
239
+ # Multiple results
240
+ assert_nothing_raised do
241
+ cj.advertiser_lookup('keywords' => '+blue +jeans', 'records-per-page' => '2')
242
+ end
243
+
244
+ check_advertiser_lookup_results(cj)
245
+
246
+ # Short timeout
247
+ cj = CommissionJunction.new(credentials['developer_key'], credentials['website_id'], 1)
248
+
249
+ assert_nothing_raised do
250
+ cj.advertiser_lookup('keywords' => 'One Great Blue Jean~No Limits', 'records-per-page' => '1')
251
+ end
252
+
253
+ check_advertiser_lookup_results(cj)
254
+ end
255
+
256
+ def check_advertiser_lookup_results(results)
257
+ assert_instance_of(Fixnum, results.total_matched)
258
+ assert_instance_of(Fixnum, results.records_returned)
259
+ assert_instance_of(Fixnum, results.page_number)
260
+ assert_instance_of(Array, results.cj_objects)
261
+
262
+ results.cj_objects.each do |advertiser|
263
+ assert_instance_of(CommissionJunction::Advertiser, advertiser)
264
+ assert_respond_to(advertiser, :advertiser_id)
265
+ assert_respond_to(advertiser, :advertiser_name)
266
+ assert_respond_to(advertiser, :language)
267
+ assert_respond_to(advertiser, :link_types)
268
+ assert_respond_to(advertiser, :network_rank)
269
+ assert_respond_to(advertiser, :performance_incentives)
270
+ assert_respond_to(advertiser, :primary_category)
271
+ assert_respond_to(advertiser, :program_url)
272
+ assert_respond_to(advertiser, :relationship_status)
273
+ assert_respond_to(advertiser, :seven_day_epc)
274
+ assert_respond_to(advertiser, :three_month_epc)
275
+ end
276
+ end
277
+
278
+ def test_categories_live
279
+ key_file = File.join(ENV['HOME'], '.commission_junction.yaml')
280
+
281
+ 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)
282
+
283
+ credentials = YAML.load(File.read(key_file))
284
+ cj = CommissionJunction.new(credentials['developer_key'], credentials['website_id'])
285
+
286
+ assert cj.categories.size > 0
287
+ end
288
+
289
+ def test_commissions_live
290
+ key_file = File.join(ENV['HOME'], '.commission_junction.yaml')
291
+
292
+ 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)
293
+
294
+ credentials = YAML.load(File.read(key_file))
295
+ cj = CommissionJunction.new(credentials['developer_key'], credentials['website_id'])
296
+
297
+ assert_nothing_raised do
298
+ cj.commissions
299
+ end
300
+
301
+ check_commission_lookup_results(cj)
302
+
303
+ assert_nothing_raised do
304
+ cj.commissions('date-type' => 'posting')
305
+ end
306
+
307
+ check_commission_lookup_results(cj)
308
+ end
309
+
310
+ def check_commission_lookup_results(results)
311
+ assert_instance_of(Fixnum, results.total_matched)
312
+ assert_instance_of(Fixnum, results.records_returned)
313
+ assert_instance_of(Fixnum, results.page_number)
314
+ assert_instance_of(Array, results.cj_objects)
315
+
316
+ results.cj_objects.each do |commission|
317
+ assert_instance_of(CommissionJunction::Commission, commission)
318
+ assert_respond_to(commission, :action_status)
319
+ assert_respond_to(commission, :action_type)
320
+ assert_respond_to(commission, :action_tracker_id)
321
+ assert_respond_to(commission, :action_tracker_name)
322
+ assert_respond_to(commission, :aid)
323
+ assert_respond_to(commission, :commission_id)
324
+ assert_respond_to(commission, :country)
325
+ assert_respond_to(commission, :event_date)
326
+ assert_respond_to(commission, :locking_date)
327
+ assert_respond_to(commission, :order_id)
328
+ assert_respond_to(commission, :original)
329
+ assert_respond_to(commission, :original_action_id)
330
+ assert_respond_to(commission, :posting_date)
331
+ assert_respond_to(commission, :website_id)
332
+ assert_respond_to(commission, :cid)
333
+ assert_respond_to(commission, :advertiser_name)
334
+ assert_respond_to(commission, :commission_amount)
335
+ assert_respond_to(commission, :order_discount)
336
+ assert_respond_to(commission, :sid)
337
+ assert_respond_to(commission, :sale_amount)
338
+ end
339
+ end
340
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ require 'commission_junction'
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: commission_junction
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.4.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Albert Vernon
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.8.3
30
+ description: Ruby wrapper for the Commission Junction web services APIs (REST)
31
+ email: aev@vernon.nu
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - Gemfile
38
+ - LICENSE
39
+ - README.md
40
+ - Rakefile
41
+ - commission_junction.gemspec
42
+ - lib/commission_junction.rb
43
+ - lib/commission_junction/version.rb
44
+ - test/commission_junction_test.rb
45
+ - test/test_helper.rb
46
+ homepage: https://github.com/aevernon/commission_junction
47
+ licenses: []
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ segments:
59
+ - 0
60
+ hash: 2510825910021186561
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ segments:
68
+ - 0
69
+ hash: 2510825910021186561
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.24
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Commission Junction web services APIs (REST)
76
+ test_files:
77
+ - test/commission_junction_test.rb
78
+ - test/test_helper.rb