Skip to content

Instantly share code, notes, and snippets.

@joshrendek
Created October 3, 2010 15:04
Show Gist options
  • Save joshrendek/608640 to your computer and use it in GitHub Desktop.
Save joshrendek/608640 to your computer and use it in GitHub Desktop.
def self.get_search_results(query)
# API request variables
endpoint = 'http://svcs.ebay.com/services/search/FindingService/v1'; # URL to call
version = '1.0.0'; # API version supported by your application
appid = 'YOUR APP ID'; # Replace with your own AppID
globalid = 'EBAY-US'; # Global ID of the eBay site you want to search (e.g., EBAY-DE)
safequery = URI.encode(query); # Make the query URL-friendly
# Construct the findItemsByKeywords HTTP GET call
apicall = "#{endpoint}?";
apicall += "OPERATION-NAME=findItemsByKeywords";
apicall += "&SERVICE-VERSION=#{version}";
apicall += "&SECURITY-APPNAME=#{appid}";
apicall += "&GLOBAL-ID=#{globalid}";
apicall += "&keywords=#{safequery}";
apicall += "&paginationInput.entriesPerPage=25";
res = ""
open( apicall ).each { |s| res << s }
prices = []
doc = Hpricot.parse(res)
(doc/:item).each do |x|
divider = 1
get_count = (x/:title).inner_html.scan(/[0-9]/).first
p "#{(x/:title).inner_html}"
if !get_count.nil?
divider = get_count.to_i
end
prices << (x/:sellingstatus/:currentprice).inner_html.to_f/divider
end
prices
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment