Method: GoogleMapsService::Client#initialize

Defined in:
lib/google_maps_service/client.rb

#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.



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

def initialize(**options)
  [:key, :client_id, :client_secret,
    :retry_timeout, :queries_per_second].each do |key|
    instance_variable_set(:"@#{key}", 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