Created
October 3, 2010 15:04
-
-
Save joshrendek/608640 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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