Permalink
Browse files

Added initial support for Finding API.

  • Loading branch information...
RevoHoffman committed Sep 8, 2011
1 parent bd959f9 commit ca2ecd7cb5dfc092f455506b54cebee414706cb7
Showing with 30 additions and 0 deletions.
  1. +1 −0 Rakefile
  2. +29 −0 lib/ebay/finding.rb
View
@@ -116,6 +116,7 @@ spec = Gem::Specification.new do |s|
s.homepage = "http://ebayapi.rubyforge.org"
s.add_dependency('xml-mapping', '= 0.8.1')
s.add_dependency('money', '= 3.7.1')
+ s.add_dependency('httparty','>=0.7.8')
end
Rake::GemPackageTask.new(spec) do |p|
View
@@ -0,0 +1,29 @@
+module Ebay
+ class Finding
+ SERVICE_VERSION="1.0.0"
+
+ include HTTParty
+ base_uri "svcs.ebay.com/services/search/FindingService/v1?SERVICE-VERSION=#{SERVICE_VERSION}&SECURITY-APPNAME=#{Ebay::Api.app_id}&RESPONSE-DATA-FORMAT=JSON&REST-PAYLOAD"
+ format :json
+
+ def self.find_by_keyword(keywords,page_number)
+ parse_response(get("&OPERATION-NAME=findItemsByKeywords&paginationInput.pageNumber=#{page_number}",:query=>{:keywords=>keywords}))
+ end
+
+ def self.find_by_category(category,page_number)
+ parse_response(get("&OPERATION-NAME=findItemsByCategory&paginationInput.pageNumber=#{page_number}",:query=>{:categoryId=>category}))
+ end
+
+ def self.parse_response(response)
+ response=response.parsed_response["findItemsByCategoryResponse"][0]
+ ack=response["ack"][0].downcase.to_sym
+ message=response["errorMessage"][0]["error"][0]["message"][0] if ack==:failure
+ if ack==:success
+ items=response["searchResult"][0]["item"]
+ total_pages=Integer(response["paginationOutput"][0]["totalPages"].first)
+ page_number=Integer(response["paginationOutput"][0]["pageNumber"].first)
+ end
+ {:ack=>ack,:message=>message,:items=>items,:total_pages=>total_pages,:page_number=>page_number}
+ end
+ end
+end

0 comments on commit ca2ecd7

Please sign in to comment.