module Google::Maps::Configuration

Defines constants and methods related to configuration

Constants

API_KEY
DEFAULT_DIRECTIONS_SERVICE
DEFAULT_DISTANCE_MATRIX_SERVICE
DEFAULT_END_POINT

By default, set “maps.googleapis.com/maps/api/” as the server

DEFAULT_FORMAT
DEFAULT_GEOCODE_SERVICE
DEFAULT_LANGUAGE

default language

DEFAULT_PARAMS

params to send which each request configured per service ie.: {places_service: {location: “52.0910,5.1220”, radius: 300000}}

DEFAULT_PLACES_SERVICE
DEFAULT_PLACE_DETAILS_SERVICE
DIGITAL_SIGNATURE
VALID_OPTIONS_KEYS

An array of valid keys in the options hash when configuring an {Google::Maps::API}

Public Class Methods

extended(base) click to toggle source

When this module is extended, set all configuration options to their default values

# File lib/google_maps/configuration.rb, line 40
def self.extended(base)
  base.reset
end

Public Instance Methods

configure() { |self| ... } click to toggle source

Convenience method to allow configuration options to be set in a block

# File lib/google_maps/configuration.rb, line 45
def configure
  yield self
  validate_config
end
options() click to toggle source

Create a hash of options and their values

# File lib/google_maps/configuration.rb, line 67
def options
  VALID_OPTIONS_KEYS.inject({}) do |option, key|
    option.merge!(key => send(key))
  end
end
reset() click to toggle source

Reset all configuration options to defaults

# File lib/google_maps/configuration.rb, line 74
def reset
  self.end_point = DEFAULT_END_POINT
  self.format = DEFAULT_FORMAT
  self.directions_service = DEFAULT_DIRECTIONS_SERVICE
  self.places_service = DEFAULT_PLACES_SERVICE
  self.place_details_service = DEFAULT_PLACE_DETAILS_SERVICE
  self.geocode_service = DEFAULT_GEOCODE_SERVICE
  self.distance_matrix_service = DEFAULT_DISTANCE_MATRIX_SERVICE
  self.default_language = DEFAULT_LANGUAGE
  self.default_params = DEFAULT_PARAMS
  self.authentication_mode = nil
  self.api_key = nil
  self.client_id = nil
  self.client_secret = nil
  self
end
validate_api_key() click to toggle source
# File lib/google_maps/configuration.rb, line 57
def validate_api_key
  raise Google::Maps::InvalidConfigurationError, 'No API key provided' unless api_key
end
validate_config() click to toggle source
# File lib/google_maps/configuration.rb, line 50
def validate_config
  return validate_api_key if authentication_mode == API_KEY
  return validate_digital_signature if authentication_mode == DIGITAL_SIGNATURE

  raise Google::Maps::InvalidConfigurationError, 'No valid authentication mode provided'
end
validate_digital_signature() click to toggle source
# File lib/google_maps/configuration.rb, line 61
def validate_digital_signature
  raise Google::Maps::InvalidConfigurationError, 'No client id provided' unless client_id
  raise Google::Maps::InvalidConfigurationError, 'No client secret provided' unless client_secret
end