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
|