Class: GoogleMapsService::Client

Inherits:
Object
  • Object
show all
Includes:
Apis::Directions, Apis::DistanceMatrix, Apis::Elevation, Apis::Geocoding, Apis::Places, Apis::Roads, Apis::TimeZone
Defined in:
lib/google_maps_service/client.rb

Overview

Core client functionality, common across all API requests (including performing HTTP requests).

Constant Summary collapse

DEFAULT_BASE_URL =

Default Google Maps Web Service base endpoints

"https://maps.googleapis.com"
RETRIABLE_ERRORS =

Errors those could be retriable.

[GoogleMapsService::Error::ServerError, GoogleMapsService::Error::RateLimitError]

Constants included from Apis::Roads

Apis::Roads::ROADS_BASE_URL

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Apis::TimeZone

#timezone

Methods included from Apis::Roads

#nearest_roads, #snap_to_roads, #snapped_speed_limits, #speed_limits

Methods included from Apis::Places

#place, #places, #places_nearby, #places_photo

Methods included from Apis::Geocoding

#geocode, #reverse_geocode

Methods included from Apis::Elevation

#elevation, #elevation_along_path

Methods included from Apis::DistanceMatrix

#distance_matrix

Methods included from Apis::Directions

#directions

Constructor Details

#initialize(**options) ⇒ Client

Construct Google Maps Web Service API client.

Examples:

Setup API keys

gmaps = GoogleMapsService::Client.new(key: 'Add your key here')

Setup client IDs

gmaps = GoogleMapsService::Client.new(
    client_id: 'Add your client id here',
    client_secret: 'Add your client secret here'
)

Setup time out and QPS limit

gmaps = GoogleMapsService::Client.new(
    key: 'Add your key here',
    retry_timeout: 20,
    queries_per_second: 10
)

Parameters:

  • options (Hash)

    a customizable set of options

Options Hash (**options):

  • :key (String)

    Secret key for accessing Google Maps Web Service. Can be obtained at developers.google.com/maps/documentation/geocoding/get-api-key#key.

  • :client_id (String)

    Client id for using Maps API for Work services.

  • :client_secret (String)

    Client secret for using Maps API for Work services.

  • :retry_timeout (Integer)

    Timeout across multiple retriable requests, in seconds.

  • :queries_per_second (Integer)

    Number of queries per second permitted.



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/google_maps_service/client.rb', line 80

def initialize(**options)
  [:key, :client_id, :client_secret,
    :retry_timeout, :queries_per_second].each do |key|
    instance_variable_set("@#{key}".to_sym, options[key] || GoogleMapsService.instance_variable_get("@#{key}"))
  end
  [:request_options, :ssl_options, :connection].each do |key|
    if options.has_key?(key)
      raise "GoogleMapsService::Client.new no longer supports #{key}."
    end
  end

  initialize_query_tickets
end

Instance Attribute Details

#client_idString

Client id for using Maps API for Work services.

Returns:

  • (String)


40
41
42
# File 'lib/google_maps_service/client.rb', line 40

def client_id
  @client_id
end

#client_secretString

Client secret for using Maps API for Work services.

Returns:

  • (String)


44
45
46
# File 'lib/google_maps_service/client.rb', line 44

def client_secret
  @client_secret
end

#keyString

Secret key for accessing Google Maps Web Service. Can be obtained at developers.google.com/maps/documentation/geocoding/get-api-key#key.

Returns:

  • (String)


36
37
38
# File 'lib/google_maps_service/client.rb', line 36

def key
  @key
end

#queries_per_secondInteger (readonly)

Number of queries per second permitted. If the rate limit is reached, the client will sleep for the appropriate amount of time before it runs the current query.

Returns:

  • (Integer)


54
55
56
# File 'lib/google_maps_service/client.rb', line 54

def queries_per_second
  @queries_per_second
end

#retry_timeoutInteger

Timeout across multiple retriable requests, in seconds.

Returns:

  • (Integer)


48
49
50
# File 'lib/google_maps_service/client.rb', line 48

def retry_timeout
  @retry_timeout
end

Instance Method Details

#clientObject

Deprecated.

Get the current HTTP client.



96
97
98
# File 'lib/google_maps_service/client.rb', line 96

def client
  raise "GoogleMapsService::Client.client is no longer implemented."
end