Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of https://github.com/yarmiganosca/rebay into y…

…armiganosca-master

Conflicts:
	Gemfile
	Gemfile.lock
	lib/rebay/api.rb
	lib/rebay/shopping.rb
	spec/api_spec.rb
	spec/shopping_spec.rb
  • Loading branch information...
commit 2ab8d8eaccd0aaa7b44bdc677fdef5b65c3d1b80 2 parents 6f7d4e9 + 863cab6
@ccollins authored
View
2  Gemfile
@@ -5,5 +5,5 @@ group :dependencies do
end
group :development do
- gem 'rspec', '2.12'
+ gem 'rspec'
end
View
2  Gemfile.lock
@@ -17,4 +17,4 @@ PLATFORMS
DEPENDENCIES
json
- rspec (= 2.12)
+ rspec
View
33 lib/rebay/api.rb
@@ -9,18 +9,37 @@ class Api
EBAY_US = 0
class << self
- attr_accessor :app_id, :default_site_id
- end
+ attr_accessor :app_id, :default_site_id, :sandbox
+
+ def base_url
+ [base_url_prefix,
+ sandbox ? "sandbox" : nil,
+ base_url_suffix].compact.join('.')
+ end
- def self.default_site_id
- @default_site_id || EBAY_US
- end
+ def base_url_prefix
+ "http://svcs"
+ end
- def self.configure
- yield self if block_given?
+ def base_url_suffix
+ "ebay.com"
+ end
+
+ def sandbox
+ @sandbox ||= false
+ end
+
+ def default_site_id
+ @default_site_id || EBAY_US
+ end
+
+ def configure
+ yield self if block_given?
+ end
end
protected
+
def get_json_response(url)
Rebay::Response.new(JSON.parse(Net::HTTP.get_response(URI.parse(url)).body))
end
View
9 lib/rebay/finding.rb
@@ -1,6 +1,9 @@
module Rebay
class Finding < Rebay::Api
- BASE_URL = 'http://svcs.ebay.com/services/search/FindingService/v1'
+ def self.base_url_suffix
+ "ebay.com/services/search/FindingService/v1"
+ end
+
VERSION = '1.0.0'
#http://developer.ebay.com/DevZone/finding/CallRef/findItemsAdvanced.html
@@ -91,9 +94,9 @@ def get_version
private
def build_request_url(service, params=nil)
- url = "#{BASE_URL}?OPERATION-NAME=#{service}&SERVICE-VERSION=#{VERSION}&SECURITY-APPNAME=#{Rebay::Api.app_id}&RESPONSE-DATA-FORMAT=JSON&REST-PAYLOAD"
+ url = "#{self.class.base_url}?OPERATION-NAME=#{service}&SERVICE-VERSION=#{VERSION}&SECURITY-APPNAME=#{Rebay::Api.app_id}&RESPONSE-DATA-FORMAT=JSON&REST-PAYLOAD"
url += build_rest_payload(params)
return url
end
end
-end
+end
View
41 lib/rebay/shopping.rb
@@ -1,11 +1,21 @@
module Rebay
class Shopping < Rebay::Api
- BASE_URL = 'http://open.api.ebay.com/shopping'
- VERSION = '677'
-
+ VERSION = '793'
+
+ class << self
+ def base_url_prefix
+ "http://open.api"
+ end
+
+ def base_url_suffix
+ "ebay.com/shopping"
+ end
+ end
+
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/FindProducts.html
def find_products(params)
- raise ArgumentError unless params[:categoryId] or params[:productId] or params[:queryKeywords]
+ raise ArgumentError unless params[:CategoryID] or params[:ProductID] or params[:QueryKeywords] or
+ (params[:'ProductID.Value'] && params[:'ProductID.type'])
response = get_json_response(build_request_url('FindProducts', params))
if response.response.has_key?('Product')
response.results = response.response['Product']
@@ -15,7 +25,8 @@ def find_products(params)
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/FindHalfProducts.html
def find_half_products(params)
- raise ArgumentError unless params[:productId] or params[:queryKeywords]
+ raise ArgumentError unless params[:ProductID] or params[:QueryKeywords] or
+ (params[:'ProductID.Value'] && params[:'ProductID.type'])
response = get_json_response(build_request_url('FindHalfProducts', params))
if response.response.has_key?('Products') && response.response['Products'].has_key?('Product')
response.results = response.response['Products']['Product']
@@ -25,7 +36,7 @@ def find_half_products(params)
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetSingleItem.html
def get_single_item(params)
- raise ArgumentError unless params[:itemId]
+ raise ArgumentError unless params[:ItemID]
response = get_json_response(build_request_url('GetSingleItem', params))
if response.response.has_key?('Item')
response.results = response.response['Item']
@@ -35,7 +46,7 @@ def get_single_item(params)
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetItemStatus.html
def get_item_status(params)
- raise ArgumentError unless params[:itemId]
+ raise ArgumentError unless params[:ItemID]
response = get_json_response(build_request_url('GetItemStatus', params))
if response.response.has_key?('Item')
response.results = response.response['Item']
@@ -45,14 +56,14 @@ def get_item_status(params)
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetShippingCosts.html
def get_shipping_costs(params)
- raise ArgumentError unless params[:itemId]
+ raise ArgumentError unless params[:ItemID]
response = get_json_response(build_request_url('GetShippingCosts', params))
return response
end
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetMultipleItems.html
def get_multiple_items(params)
- raise ArgumentError unless params[:itemId]
+ raise ArgumentError unless params[:ItemID]
response = get_json_response(build_request_url('GetMultipleItems', params))
if response.response.has_key?('Item')
response.results = response.response['Item']
@@ -62,7 +73,7 @@ def get_multiple_items(params)
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetUserProfile.html
def get_user_profile(params)
- raise ArgumentError unless params[:userId]
+ raise ArgumentError unless params[:UserID]
response = get_json_response(build_request_url('GetUserProfile', params))
if response.response.has_key?('User')
response.results = response.response['User']
@@ -72,7 +83,7 @@ def get_user_profile(params)
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/FindPopularSearches.html
def find_popular_searches(params)
- raise ArgumentError unless params[:categoryId]
+ raise ArgumentError unless params[:CategoryID]
response = get_json_response(build_request_url('FindPopularSearches', params))
if response.response.has_key?('PopularSearchResult')
response.results = response.response['PopularSearchResult']
@@ -82,7 +93,7 @@ def find_popular_searches(params)
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/FindPopularItems.html
def find_popular_items(params={})
- raise ArgumentError unless params[:categoryId] or params[:queryKeywords]
+ raise ArgumentError unless params[:CategoryID] or params[:QueryKeywords]
response = get_json_response(build_request_url('FindPopularItems', params))
if response.response.has_key?('ItemArray') && response.response['ItemArray'].has_key?('Item')
response.results = response.response['ItemArray']['Item']
@@ -101,7 +112,7 @@ def find_reviews_and_guides(params={})
#http://developer.ebay.com/DevZone/shopping/docs/CallRef/GetCategoryInfo.html
def get_category_info(params)
- raise ArgumentError unless params[:categoryId]
+ raise ArgumentError unless params[:CategoryID]
response = get_json_response(build_request_url('GetCategoryInfo', params))
if response.response.has_key?('CategoryArray') && response.response['CategoryArray'].has_key?('Category')
response.results = response.response['CategoryArray']['Category']
@@ -117,8 +128,8 @@ def get_category_info_with_children(params)
private
def build_request_url(service, params=nil)
- url = "#{BASE_URL}?callname=#{service}&appid=#{Rebay::Api.app_id}&version=#{VERSION}&responseencoding=JSON&siteid=#{Rebay::Api::EBAY_US}"
- url += build_rest_payload(params)
+ url = "#{self.class.base_url}?callname=#{service}&appid=#{Rebay::Api.app_id}&version=#{VERSION}&responseencoding=JSON"
+ url += build_rest_payload({siteid: Rebay::Api.default_site_id}.merge(params))
return url
end
end
View
39 spec/api_spec.rb
@@ -7,7 +7,45 @@ module Rebay
it "should respond to configure" do
Rebay::Api.should respond_to(:configure)
end
+
+ describe "#base_url_prefix" do
+ it "shouldn't be nil" do
+ Rebay::Api.base_url_prefix.should_not be_nil
+ end
+ end
+
+ describe "#base_url_suffix" do
+ it "shouldn't be nil" do
+ Rebay::Api.base_url_suffix.should_not be_nil
+ end
+ end
+
+ describe "#base_url" do
+ context "api calls should hit the sandbox" do
+ it "should return a sandboxed url" do
+ Rebay::Api.configure do |c|
+ c.sandbox = true
+ end
+
+ Rebay::Api.base_url.should include "sandbox"
+ end
+ end
+ context "api calls shouldn't hit the sandbox" do
+ it "should return a un-sandboxed url" do
+ Rebay::Api.configure do |c|
+ c.sandbox = false
+ end
+
+ Rebay::Api.base_url.should_not include "sandbox"
+ end
+ end
+ end
+
+ describe "#sandbox" do
+ it_behaves_like "a configuration option", :sandbox, true
+ end
+
describe "#app_id" do
it_behaves_like "a configuration option", :app_id, 'super_id-11'
end
@@ -42,3 +80,4 @@ module Rebay
end
end
end
+
View
4 spec/finding_spec.rb
@@ -6,9 +6,9 @@ module Rebay
@finder = Finding.new
@finder.stub!(:get_json_response).and_return(Rebay::Response.new({"Ack" => 'Success'}))
end
-
+
it "should specify base url" do
- Finding::BASE_URL.should_not be_nil
+ Finding.base_url.should_not be_nil
end
it "should specify version" do
View
69 spec/shopping_spec.rb
@@ -8,7 +8,7 @@ module Rebay
end
it "should specify base url" do
- Shopping::BASE_URL.should_not be_nil
+ Shopping.base_url.should_not be_nil
end
it "should specify version" do
@@ -18,19 +18,19 @@ module Rebay
context "siteid" do
it "should default siteid" do
@shopper.should_receive(:get_json_response).with(/siteid=0&/)
- @shopper.get_category_info(:categoryId => '-1')
+ @shopper.get_category_info(:CategoryID => '-1')
end
it "should default siteid" do
- @shopper.class.default_site_id = 100
+ Rebay::Api.default_site_id = 100
@shopper.should_receive(:get_json_response).with(/siteid=100&/)
- @shopper.get_category_info(:categoryId => '-1')
+ @shopper.get_category_info(:CategoryID => '-1')
end
it "should default siteid" do
- @shopper.class.default_site_id = 100
+ Rebay::Api.default_site_id = 100
@shopper.should_receive(:get_json_response).with(/siteid=99&/)
- @shopper.get_category_info(:categoryId => '-1', :siteid => 99)
+ @shopper.get_category_info(:CategoryID => '-1', :siteid => 99)
end
end
@@ -90,18 +90,19 @@ module Rebay
end
it "should return a hash response" do
- @shopper.get_category_info({:categoryId => 29223}).class.should eq(Rebay::Response)
+ @shopper.get_category_info({:CategoryID => 29223}).class.should eq(Rebay::Response)
end
it "should succeed" do
- @shopper.get_category_info({:categoryId => 29223}).success?.should be_true
+ @shopper.get_category_info({:CategoryID => 29223}).success?.should be_true
end
it "should iterate over results" do
json = JSON.parse(File.read(File.dirname(__FILE__) + "/json_responses/shopping/get_category_info"))
@shopper.stub!(:get_json_response).and_return(Rebay::Response.new(json))
- response = @shopper.get_category_info({:categoryId => 1})
-
+
+ response = @shopper.get_category_info({:CategoryID => 1})
+
count = 0
response.each { |r| count = count + 1 }
count.should eq(1)
@@ -114,18 +115,19 @@ module Rebay
end
it "should return a hash response" do
- @shopper.find_products({:queryKeywords => 'harry potter'}).class.should eq(Rebay::Response)
+ @shopper.find_products({:QueryKeywords => 'harry potter'}).class.should eq(Rebay::Response)
end
it "should succeed" do
- @shopper.find_products({:queryKeywords => 'harry potter'}).success?.should be_true
+ @shopper.find_products({:QueryKeywords => 'harry potter'}).success?.should be_true
end
it "should iterate over results" do
json = JSON.parse(File.read(File.dirname(__FILE__) + "/json_responses/shopping/find_products"))
@shopper.stub!(:get_json_response).and_return(Rebay::Response.new(json))
- response = @shopper.find_products({:queryKeywords => 'whatevs'})
+ response = @shopper.find_products({:QueryKeywords => 'whatevs'})
+
count = 0
response.each { |r| count = count + 1 }
count.should eq(2)
@@ -138,18 +140,19 @@ module Rebay
end
it "should return a hash response" do
- @shopper.find_half_products({:queryKeywords => 'harry potter'}).class.should eq(Rebay::Response)
+ @shopper.find_half_products({:QueryKeywords => 'harry potter'}).class.should eq(Rebay::Response)
end
it "should succeed" do
- @shopper.find_half_products({:queryKeywords => 'harry potter'}).success?.should be_true
+ @shopper.find_half_products({:QueryKeywords => 'harry potter'}).success?.should be_true
end
it "should iterate over results" do
json = JSON.parse(File.read(File.dirname(__FILE__) + "/json_responses/shopping/find_half_products"))
@shopper.stub!(:get_json_response).and_return(Rebay::Response.new(json))
- response = @shopper.find_half_products({:queryKeywords => 'whatevs'})
+ response = @shopper.find_half_products({:QueryKeywords => 'whatevs'})
+
count = 0
response.each { |r| count = count + 1 }
count.should eq(2)
@@ -162,11 +165,11 @@ module Rebay
end
it "should return a hash response" do
- @shopper.get_single_item({:itemId => 230139965209}).class.should eq(Rebay::Response)
+ @shopper.get_single_item({:ItemID => 230139965209}).class.should eq(Rebay::Response)
end
it "should succeed" do
- @shopper.get_single_item({:itemId => 230139965209}).success?.should be_true
+ @shopper.get_single_item({:ItemID => 230139965209}).success?.should be_true
end
end
@@ -176,11 +179,11 @@ module Rebay
end
it "should return a hash response" do
- @shopper.get_item_status({:itemId => 230139965209}).class.should eq(Rebay::Response)
+ @shopper.get_item_status({:ItemID => 230139965209}).class.should eq(Rebay::Response)
end
it "should succeed" do
- @shopper.get_item_status({:itemId => 230139965209}).success?.should be_true
+ @shopper.get_item_status({:ItemID => 230139965209}).success?.should be_true
end
end
@@ -190,11 +193,11 @@ module Rebay
end
it "should return a hash response" do
- @shopper.get_shipping_costs({:itemId => 230139965209}).class.should eq(Rebay::Response)
+ @shopper.get_shipping_costs({:ItemID => 230139965209}).class.should eq(Rebay::Response)
end
it "should succeed" do
- @shopper.get_shipping_costs({:itemId => 230139965209}).success?.should be_true
+ @shopper.get_shipping_costs({:ItemID => 230139965209}).success?.should be_true
end
end
@@ -204,11 +207,11 @@ module Rebay
end
it "should return a hash response" do
- @shopper.get_multiple_items({:itemId => 230139965209}).class.should eq(Rebay::Response)
+ @shopper.get_multiple_items({:ItemID => 230139965209}).class.should eq(Rebay::Response)
end
it "should succeed" do
- @shopper.get_multiple_items({:itemId => 230139965209}).success?.should be_true
+ @shopper.get_multiple_items({:ItemID => 230139965209}).success?.should be_true
end
end
@@ -218,11 +221,11 @@ module Rebay
end
it "should return a hash response" do
- @shopper.get_user_profile({:userId => 1}).class.should eq(Rebay::Response)
+ @shopper.get_user_profile({:UserID => 1}).class.should eq(Rebay::Response)
end
it "should succeed" do
- @shopper.get_user_profile({:userId => 1}).success?.should be_true
+ @shopper.get_user_profile({:UserID => 1}).success?.should be_true
end
end
@@ -232,18 +235,19 @@ module Rebay
end
it "should return a hash response" do
- @shopper.find_popular_searches({:categoryId => 1}).class.should eq(Rebay::Response)
+ @shopper.find_popular_searches({:CategoryID => 1}).class.should eq(Rebay::Response)
end
it "should succeed" do
- @shopper.find_popular_searches({:categoryId => 1}).success?.should be_true
+ @shopper.find_popular_searches({:CategoryID => 1}).success?.should be_true
end
it "should iterate over results" do
json = JSON.parse(File.read(File.dirname(__FILE__) + "/json_responses/shopping/find_popular_searches"))
@shopper.stub!(:get_json_response).and_return(Rebay::Response.new(json))
- response = @shopper.find_popular_searches({:categoryId => 1})
+ response = @shopper.find_popular_searches({:CategoryID => 1})
+
count = 0
response.each { |r| count = count + 1 }
count.should eq(1)
@@ -252,18 +256,19 @@ module Rebay
context "when calling find_popular_items" do
it "should return a hash response" do
- @shopper.find_popular_items({:categoryId => 1}).class.should eq(Rebay::Response)
+ @shopper.find_popular_items({:CategoryID => 1}).class.should eq(Rebay::Response)
end
it "should succeed" do
- @shopper.find_popular_items({:categoryId => 1}).success?.should be_true
+ @shopper.find_popular_items({:CategoryID => 1}).success?.should be_true
end
it "should iterate over results" do
json = JSON.parse(File.read(File.dirname(__FILE__) + "/json_responses/shopping/find_popular_items"))
@shopper.stub!(:get_json_response).and_return(Rebay::Response.new(json))
- response = @shopper.find_popular_items({:categoryId => 1})
+ response = @shopper.find_popular_items({:CategoryID => 1})
+
count = 0
response.each { |r| count = count + 1 }
count.should eq(19)
Please sign in to comment.
Something went wrong with that request. Please try again.