Class: Yahoo::LocalSearch
- Inherits:
-
Search
- Object
- Search
- Yahoo::LocalSearch
- Defined in:
- lib/yahoo/local_search.rb
Overview
Yahoo local search API.
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
-
#initialize(*args) ⇒ LocalSearch
constructor
:nodoc:.
-
#locate(query, location, results = nil) ⇒ Object
Search for
queryatlocationand return up toresultsitems. -
#parse_response(xml) ⇒ Object
:nodoc:.
Constructor Details
#initialize(*args) ⇒ LocalSearch
:nodoc:
26 27 28 29 30 31 |
# File 'lib/yahoo/local_search.rb', line 26 def initialize(*args) # :nodoc: @host = 'api.local.yahoo.com' @service_name = 'LocalSearchService' @version = 'V3' super end |
Instance Method Details
#locate(query, location, results = nil) ⇒ Object
Search for query at location and return up to results items.
If results is omitted then ten results are returned.
query is the location you are searching for.
location can be any of
-
city, state
-
city, state, zip
-
zip
-
street, city, state
-
street, city, state, zip
-
street, zip
locate returns five items, an Array of search results, a URI for a webpage with a map of the search results, the total number of results available, the number of results returned and the position of the first result in the overall search (one based).
53 54 55 56 57 |
# File 'lib/yahoo/local_search.rb', line 53 def locate(query, location, results = nil) params = { :query => query, :location => location } params[:results] = results unless results.nil? get :localSearch, params end |
#parse_response(xml) ⇒ Object
:nodoc:
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/yahoo/local_search.rb', line 59 def parse_response(xml) # :nodoc: search_results = [] result_set_map_url = URI.parse(xml.at_xpath('//xmlns:ResultSetMapUrl').content) total_results_available, total_results_returned, first_result_position = parse_result_info(xml) xml.xpath('//xmlns:Result').each do |r| sr = Result.new sr.id = r['id'].to_i sr.title = r.at_xpath('xmlns:Title').content sr.address = r.at_xpath('xmlns:Address').content sr.city = r.at_xpath('xmlns:City').content sr.state = r.at_xpath('xmlns:State').content sr.phone = r.at_xpath('xmlns:Phone').content sr.latitude = r.at_xpath('xmlns:Latitude').content.to_f sr.longitude = r.at_xpath('xmlns:Longitude').content.to_f = r.at_xpath('xmlns:Rating') sr. = .at_xpath('xmlns:AverageRating').content.to_f sr. = .at_xpath('xmlns:TotalRatings').content.to_i sr.total_reviews = .at_xpath('xmlns:TotalReviews').content.to_i sr.last_review_date = Time.at .at_xpath('xmlns:LastReviewDate').content.to_i sr.last_review_intro = .at_xpath('xmlns:LastReviewIntro').content sr.distance = r.at_xpath('xmlns:Distance').content.to_f sr.url = URI.parse r.at_xpath('xmlns:Url').content sr.click_url = URI.parse r.at_xpath('xmlns:ClickUrl').content sr.map_url = URI.parse r.at_xpath('xmlns:MapUrl').content sr.business_url = URI.parse r.at_xpath('xmlns:BusinessUrl').content sr.business_click_url = URI.parse r.at_xpath('xmlns:BusinessClickUrl').content sr.categories = {} r.xpath('.//xmlns:Category').each do |c| sr.categories[c.content] = c['id'].to_i end search_results << sr end return search_results, result_set_map_url, total_results_available, total_results_returned, first_result_position end |