Class: GoogleDistanceMatrix::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/google_distance_matrix/client.rb

Overview

HTTP client making request to Google’s API

Constant Summary collapse

CLIENT_ERRORS =
%w[
  INVALID_REQUEST
  MAX_ELEMENTS_EXCEEDED
  OVER_QUERY_LIMIT
  REQUEST_DENIED
  UNKNOWN_ERROR
].freeze

Instance Method Summary collapse

Instance Method Details

#get(url, instrumentation: {}, **_options) ⇒ Object

Make a GET request to given URL

Parameters:

  • url

    The URL to Google’s API we’ll make a request to

  • instrumentation (defaults to: {})

    A hash with instrumentation payload

  • options

    Other options we don’t care about, for example we’ll capture ‘configuration` option which we are not using, but the ClientCache is using.

Returns:

  • Hash with data from parsed response body



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/google_distance_matrix/client.rb', line 25

def get(url, instrumentation: {}, **_options)
  uri = URI.parse url

  response = ActiveSupport::Notifications.instrument(
    'client_request_matrix_data.google_distance_matrix', instrumentation
  ) do
    Net::HTTP.get_response uri
  end

  handle response, url
rescue Timeout::Error => error
  raise ServerError, error
end