11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/google_distance_matrix/client.rb', line 11
def get(url, options = {})
uri = URI.parse url
instrumentation = {url: url}.merge(options[:instrumentation] || {})
response = ActiveSupport::Notifications.instrument "client_request_matrix_data.google_distance_matrix", instrumentation do
Net::HTTP.get_response uri
end
case response
when Net::HTTPSuccess
inspect_for_client_errors! response
when Net::HTTPRequestURITooLong
fail MatrixUrlTooLong.new url, UrlBuilder::MAX_URL_SIZE, response
when Net::HTTPClientError
fail ClientError.new response
when Net::HTTPServerError
fail ServerError.new response
else fail ServerError.new response
end
rescue Timeout::Error => error
fail ServerError.new error
end
|