Class: YahooShoppingSearch::Clients::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/yahoo_shopping_search/clients/base.rb

Direct Known Subclasses

Item

Class Method Summary collapse

Class Method Details

.response_class_nameObject

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/yahoo_shopping_search/clients/base.rb', line 34

def response_class_name
  raise NotImplementedError
end

.search(params = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/yahoo_shopping_search/clients/base.rb', line 7

def search(params = {})
  queries = params.merge(base_params).to_query

  uri = URI.parse("#{url}?#{queries}")
  req = Net::HTTP::Get.new uri

  Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
    res = http.request(req)
    case res
    when Net::HTTPOK
      return response_class_name.new(res.body, params)
    when Net::HTTPBadRequest
      raise BadRequestError.new(error_message(res))
    when Net::HTTPUnauthorized
      raise UnauthorizedError.new(error_message(res))
    when Net::HTTPForbidden
      raise ForbiddenError.new(error_message(res))
    when Net::HTTPNotFound
      raise NotFoundError.new(error_message(res))
    when Net::HTTPInternalServerError
      raise InternalServerError.new(error_message(res))
    when Net::HTTPServiceUnavailable
      raise ServiceUnavailableError.new(error_message(res))
    end
  end
end

.urlObject

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/yahoo_shopping_search/clients/base.rb', line 38

def url
  raise NotImplementedError
end