Permalink
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...
2 parents 6f7d4e9 + 863cab6 commit 2ab8d8eaccd0aaa7b44bdc677fdef5b65c3d1b80 @ccollins committed Jan 3, 2013
Showing with 138 additions and 61 deletions.
  1. +1 −1 Gemfile
  2. +1 −1 Gemfile.lock
  3. +26 −7 lib/rebay/api.rb
  4. +6 −3 lib/rebay/finding.rb
  5. +26 −15 lib/rebay/shopping.rb
  6. +39 −0 spec/api_spec.rb
  7. +2 −2 spec/finding_spec.rb
  8. +37 −32 spec/shopping_spec.rb
View
@@ -5,5 +5,5 @@ group :dependencies do
end
group :development do
- gem 'rspec', '2.12'
+ gem 'rspec'
end
View
@@ -17,4 +17,4 @@ PLATFORMS
DEPENDENCIES
json
- rspec (= 2.12)
+ rspec
View
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Oops, something went wrong.

0 comments on commit 2ab8d8e

Please sign in to comment.