Class: GoogleDistanceMatrix::Configuration

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/google_distance_matrix/configuration.rb

Overview

Public: Configuration of matrix and it’s request.

Holds configuration used when building API URL.

See developers.google.com/maps/documentation/distance-matrix/intro for documentation on each configuration.

Constant Summary collapse

ATTRIBUTES =

Attributes we’ll include building URL for our matrix

%w[
  mode avoid units language
  departure_time arrival_time
  transit_mode transit_routing_preference
  traffic_model channel
].freeze
API_DEFAULTS =
{
  mode: 'driving',
  units: 'metric',
  traffic_model: 'best_guess',
  use_encoded_polylines: false,
  protocol: 'https',
  lat_lng_scale: 5,
  filter_parameters_in_logged_url: %w[key signature].freeze,
  cache_key_transform: ->(url) { Digest::SHA512.new.update(url).to_s }
}.with_indifferent_access

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



83
84
85
86
87
88
89
90
91
# File 'lib/google_distance_matrix/configuration.rb', line 83

def initialize
  API_DEFAULTS.each_pair do |attr_name, value|
    self[attr_name] = begin
                        value.dup
                      rescue StandardError
                        value
                      end
  end
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



53
54
55
# File 'lib/google_distance_matrix/configuration.rb', line 53

def cache
  @cache
end

#cache_key_transformObject

Callable object which transform given url to key used in cache



60
61
62
# File 'lib/google_distance_matrix/configuration.rb', line 60

def cache_key_transform
  @cache_key_transform
end

#filter_parameters_in_logged_urlObject

When logging we filter sensitive parameters



56
57
58
# File 'lib/google_distance_matrix/configuration.rb', line 56

def filter_parameters_in_logged_url
  @filter_parameters_in_logged_url
end

#google_api_keyObject

Google credentials



51
52
53
# File 'lib/google_distance_matrix/configuration.rb', line 51

def google_api_key
  @google_api_key
end

#google_business_api_client_idObject

Google credentials



51
52
53
# File 'lib/google_distance_matrix/configuration.rb', line 51

def google_business_api_client_id
  @google_business_api_client_id
end

#google_business_api_private_keyObject

Google credentials



51
52
53
# File 'lib/google_distance_matrix/configuration.rb', line 51

def google_business_api_private_key
  @google_business_api_private_key
end

#lat_lng_scaleObject

lat_lng_scale is used for each Place when we include it’s lat and lng values in the URL. Defaults to 5 decimals, but you can set it lower to save characters in the URL.

Speaking of saving characters. If you use_encoded_polylines all Places which has lat/lng will use encoded set of coordinates using the Encoded Polyline Algorithm. This is particularly useful if you have a large number of origin points, because the URL is significantly shorter when using an encoded polyline. See: developers.google.com/maps/documentation/distance-matrix/intro#RequestParameters



48
49
50
# File 'lib/google_distance_matrix/configuration.rb', line 48

def lat_lng_scale
  @lat_lng_scale
end

#loggerObject

Returns the value of attribute logger.



53
54
55
# File 'lib/google_distance_matrix/configuration.rb', line 53

def logger
  @logger
end

#protocolObject

The protocol to use, either http or https



38
39
40
# File 'lib/google_distance_matrix/configuration.rb', line 38

def protocol
  @protocol
end

#use_encoded_polylinesObject

lat_lng_scale is used for each Place when we include it’s lat and lng values in the URL. Defaults to 5 decimals, but you can set it lower to save characters in the URL.

Speaking of saving characters. If you use_encoded_polylines all Places which has lat/lng will use encoded set of coordinates using the Encoded Polyline Algorithm. This is particularly useful if you have a large number of origin points, because the URL is significantly shorter when using an encoded polyline. See: developers.google.com/maps/documentation/distance-matrix/intro#RequestParameters



48
49
50
# File 'lib/google_distance_matrix/configuration.rb', line 48

def use_encoded_polylines
  @use_encoded_polylines
end

Instance Method Details

#[]=(attr_name, value) ⇒ Object



97
98
99
# File 'lib/google_distance_matrix/configuration.rb', line 97

def []=(attr_name, value)
  public_send "#{attr_name}=", value
end

#to_paramObject



93
94
95
# File 'lib/google_distance_matrix/configuration.rb', line 93

def to_param
  Hash[array_param]
end