Class: YahooWebAPI::BlogSearchService

Inherits:
Client
  • Object
show all
Defined in:
lib/yahoo_web_api/search/blog_search.rb

Constant Summary collapse

END_POINT =
'http://search.yahooapis.jp/BlogSearchService/V1/blogSearch'

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

make_response_object

Constructor Details

#initialize(args) ⇒ BlogSearchService

Returns a new instance of BlogSearchService.



26
27
28
29
# File 'lib/yahoo_web_api/search/blog_search.rb', line 26

def initialize(args)
  @parameters = {} 
  @parameters.merge!(args)
end

Class Method Details

.parse(doc, selector) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/yahoo_web_api/search/blog_search.rb', line 12

def parse(doc, selector)
  results = super
  result_set = Nokogiri::XML(doc).css('ResultSet')[0]
  klass = (class << results; self; end)
  result_set.keys.each do |key|
    method_name = key.gsub(/([a-z])([A-Z])/) {
                    $1 + '_' + $2
                  }.downcase
    klass.__send__(:define_method, method_name) {result_set[key].to_i}
  end
  return results
end

Instance Method Details

#blog_search(params) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/yahoo_web_api/search/blog_search.rb', line 31

def blog_search(params)
  params = @parameters.merge(params)
  res = get(END_POINT, params)
  if res.code == '200'
    results = self.class.parse(res.body.to_s, 'ResultSet Result')
    return results
  else
    raise Exception, Nokogiri::XML(res.body).css('Error Message').inner_text
  end
end