Class: Yahoo::Answers
- Inherits:
-
Yahoo
- Object
- Yahoo
- Yahoo::Answers
- Defined in:
- lib/yahoo/answers.rb
Overview
Yahoo! Answers API
Defined Under Namespace
Classes: Question
Instance Method Summary collapse
-
#initialize(*args) ⇒ Answers
constructor
:nodoc:.
-
#parse_response(xml) ⇒ Object
:nodoc:.
-
#search(options) ⇒ Object
Searches the web for
:query
and returns up to:results
results.
Constructor Details
#initialize(*args) ⇒ Answers
:nodoc:
14 15 16 17 18 19 |
# File 'lib/yahoo/answers.rb', line 14 def initialize(*args) # :nodoc: @host = 'answers.yahooapis.com' @service_name = 'AnswersService' @version = 'V1' super end |
Instance Method Details
#parse_response(xml) ⇒ Object
:nodoc:
33 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 61 62 63 |
# File 'lib/yahoo/answers.rb', line 33 def parse_response(xml) # :nodoc: results = [] xml.xpath('//xmlns:Question').each do |r| result = Question.new result.id = r.attribute('id').content result.type = r.attribute('type').content result.subject = r.at_xpath('xmlns:Subject').content result.content = r.at_xpath('xmlns:Content').content result.date = r.at_xpath('xmlns:Date').content result. = r.at_xpath('xmlns:Timestamp').content.to_i result.link = r.at_xpath('xmlns:Link').content result.category_id = r.at_xpath('xmlns:Category').attribute('id').content.to_i result.category = r.at_xpath('xmlns:Category').content result.user_id = r.at_xpath('xmlns:UserId').content result.user_nick = r.at_xpath('xmlns:UserNick').content result.user_photo_url = r.at_xpath('xmlns:UserPhotoURL').content result.num_answers = r.at_xpath('xmlns:NumAnswers').content.to_i result.num_comments = r.at_xpath('xmlns:NumComments').content.to_i result.answer = r.at_xpath('xmlns:ChosenAnswer').content result.answerer_id = r.at_xpath('xmlns:ChosenAnswererId').content result.answerer_nick = r.at_xpath('xmlns:ChosenAnswererNick').content result. = r.at_xpath('xmlns:ChosenAnswerTimestamp').content.to_i result. = r.at_xpath('xmlns:ChosenAnswerAwardTimestamp').content.to_i results << result end return results end |
#search(options) ⇒ Object
Searches the web for :query
and returns up to :results
results
:results
defaults to 10 questions, maximum per Yahoo! Answers API is 50
All options on developer.yahoo.com/answers/V1/questionSearch.html can be used
28 29 30 31 |
# File 'lib/yahoo/answers.rb', line 28 def search() params = { :results => 10 }.merge() get :questionSearch, params end |