Class: YANAPI::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/yanapi/query.rb

Direct Known Subclasses

CategoryQuery, QuestionQuery, TermQuery, UserQuery

Constant Summary collapse

HOST =
'http://answers.yahooapis.com'
SERVICE =
'AnswersService'
SERVICE_VERSION =
'V1'
VALID_PARAMS =
[:appid, :output, :callback]
REQUIRED_PARAMS =
[:appid]
VALID_OUTPUT_FORMATS =
[nil, 'xml', 'php', 'rss', 'json']

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Query

It accepts a two dimensional hash:

{:method => 'questionSearch', :query_params =>
  {:appid => 'YahooDemo', :query => 'Haus'}}


21
22
23
24
25
26
# File 'lib/yanapi/query.rb', line 21

def initialize(params)
  @method = params[:method]
  @params = check_params(params[:query_params])
  @url = build_url(@params)
  @output = @params[:output] || 'xml'            
end

Instance Method Details

#getObject

This is the main method. It gets the body of the HTTP response and invokes the respective check. It returns the response or <nil> if the response is emtpy.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/yanapi/query.rb', line 31

def get

  http_response = get_response(@url)
  
  case @output
  when 'xml'
    prove_xml(http_response)
  when 'json'
    fail NotImplementedError, 'We do not handle JSON yet!'
  when 'php'
    fail NotImplementedError, 'We do not handle PHP yet!'
  when 'rss'
    fail NotImplementedError, 'We do not handle RSS yet!'
  end

end