Permalink
Browse files

Add method for fetching CJ categories (thanks mnutt).

  • Loading branch information...
1 parent fcc922e commit 493b7ef6de0ca9a3a0f258831367e05f4b4007ac @aevernon committed Jan 23, 2011
Showing with 33 additions and 2 deletions.
  1. +2 −0 README.rdoc
  2. +1 −1 Rakefile
  3. +17 −1 lib/commission_junction.rb
  4. +13 −0 test/commission_junction_test.rb
View
@@ -43,6 +43,8 @@ Ruby wrapper for the Commission Junction web services APIs (REST)
puts ''
end
+ puts cj.categories
+
== Dependencies
* httparty
View
@@ -9,7 +9,7 @@ begin
gem.description = %Q{Ruby wrapper for the Commission Junction web services APIs (REST)}
gem.email = "aev@vernon.nu"
gem.homepage = "http://github.com/aevernon/commission_junction"
- gem.authors = ["Albert Vernon", "C.J. Sanders"]
+ gem.authors = ["Albert Vernon", "C.J. Sanders", "Michael Nutt"]
gem.add_dependency('httparty')
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
View
@@ -26,7 +26,8 @@ class CommissionJunction
WEB_SERVICE_URIS =
{
:product_search => 'https://product-search.api.cj.com/v2/product-search',
- :advertiser_lookup => 'https://advertiser-lookup.api.cj.com/v3/advertiser-lookup'
+ :advertiser_lookup => 'https://advertiser-lookup.api.cj.com/v3/advertiser-lookup',
+ :categories => 'https://support-services.api.cj.com/v2/categories'
}
def initialize(developer_key, website_id, timeout = 10)
@@ -45,6 +46,21 @@ def initialize(developer_key, website_id, timeout = 10)
self_class.headers('authorization' => developer_key)
end
+ def categories(params={})
+ raise ArgumentError, "params must be a Hash; got #{params.class} instead" unless params.is_a?(Hash)
+
+ params = {'locale' => 'en'}.merge(params)
+
+ response = self.class.get(WEB_SERVICE_URIS[:categories], :query => params, :timeout => @timeout)
+
+ cj_api = response['cj_api']
+ error_message = cj_api['error_message']
+
+ raise ArgumentError, error_message if error_message
+
+ @categories = cj_api['categories']['category']
+ end
+
def advertiser_lookup(params = { 'advertiser-ids' => 'joined', 'records-per-page' => '5' })
raise ArgumentError, "params must be a Hash; got #{params.class} instead" unless params.is_a?(Hash)
@@ -301,4 +301,17 @@ def check_advertiser_lookup_results(results)
assert_respond_to(advertiser, :three_month_epc)
end
end
+
+ def test_categories_live
+ key_file = File.join(ENV['HOME'], '.commission_junction.yaml')
+
+ unless File.exist?(key_file)
+ warn "Warning: #{key_file} does not exist. Put your CJ developer key and website ID in there to enable live testing."
+ else
+ credentials = YAML.load(File.read(key_file))
+ cj = CommissionJunction.new(credentials['developer_key'], credentials['website_id'])
+
+ assert cj.categories.size > 0
+ end
+ end
end

0 comments on commit 493b7ef

Please sign in to comment.