Class: Yahoo::WebSearch
- Inherits:
-
Search
- Object
- Search
- Yahoo::WebSearch
- Defined in:
- lib/yahoo/web_search.rb
Overview
Yahoo Web Search API
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
-
#initialize(*args) ⇒ WebSearch
constructor
:nodoc:.
-
#parse_response(xml) ⇒ Object
:nodoc:.
-
#search(query, results = nil) ⇒ Object
Searches the web for
query
and returns up toresults
items.
Constructor Details
#initialize(*args) ⇒ WebSearch
:nodoc:
13 14 15 16 17 18 |
# File 'lib/yahoo/web_search.rb', line 13 def initialize(*args) # :nodoc: @host = 'api.search.yahoo.com' @service_name = 'WebSearchService' @version = 'V1' super end |
Instance Method Details
#parse_response(xml) ⇒ Object
:nodoc:
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/yahoo/web_search.rb', line 34 def parse_response(xml) # :nodoc: search_results = [] total_results_available, total_results_returned, first_result_position = parse_result_info xml xml.xpath('//xmlns:Result').each do |r| result = Result.new result.title = r.at_xpath('xmlns:Title').content result.summary = r.at_xpath('xmlns:Summary').content result.url = URI.parse(r.at_xpath('xmlns:Url').content) result.click_url = URI.parse(r.at_xpath('xmlns:ClickUrl').content) result.mime_type = r.at_xpath('xmlns:MimeType').content result.modification_date = Time.at(r.at_xpath('xmlns:ModificationDate').content.to_i) cacheurl = r.at_xpath('xmlns:Cache/xmlns:Url') if cacheurl result.cache_url = URI.parse(cacheurl.content) result.cache_size = r.at_xpath('xmlns:Cache/xmlns:Size').content.to_i end search_results << result end return search_results, total_results_available, total_results_returned, first_result_position end |
#search(query, results = nil) ⇒ Object
Searches the web for query
and returns up to results
items.
If results
is omitted then ten results are returned.
For details on constructing query
, see: help.yahoo.com/help/us/ysearch/tips/tips-04.html
28 29 30 31 32 |
# File 'lib/yahoo/web_search.rb', line 28 def search(query, results = nil) params = { :query => query } params[:results] = results unless results.nil? get :webSearch, params end |