Class: GoogleDistanceMatrix::Configuration
- Inherits:
-
Object
- Object
- GoogleDistanceMatrix::Configuration
- 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
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#cache_key_transform ⇒ Object
Callable object which transform given url to key used in cache.
-
#filter_parameters_in_logged_url ⇒ Object
When logging we filter sensitive parameters.
-
#google_api_key ⇒ Object
Google credentials.
-
#google_business_api_client_id ⇒ Object
Google credentials.
-
#google_business_api_private_key ⇒ Object
Google credentials.
-
#lat_lng_scale ⇒ Object
lat_lng_scale is used for each Place when we include it’s lat and lng values in the URL.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#protocol ⇒ Object
The protocol to use, either http or https.
-
#use_encoded_polylines ⇒ Object
lat_lng_scale is used for each Place when we include it’s lat and lng values in the URL.
Instance Method Summary collapse
- #[]=(attr_name, value) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #to_param ⇒ Object
Constructor Details
#initialize ⇒ Configuration
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
#cache ⇒ Object
Returns the value of attribute cache.
53 54 55 |
# File 'lib/google_distance_matrix/configuration.rb', line 53 def cache @cache end |
#cache_key_transform ⇒ Object
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_url ⇒ Object
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_key ⇒ Object
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_id ⇒ Object
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_key ⇒ Object
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_scale ⇒ Object
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 |
#logger ⇒ Object
Returns the value of attribute logger.
53 54 55 |
# File 'lib/google_distance_matrix/configuration.rb', line 53 def logger @logger end |
#protocol ⇒ Object
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_polylines ⇒ Object
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_param ⇒ Object
93 94 95 |
# File 'lib/google_distance_matrix/configuration.rb', line 93 def to_param Hash[array_param] end |