Class: GoogleMapsPlatform::DirectionsResponse
- Inherits:
-
BaseModel
- Object
- CoreLibrary::BaseModel
- BaseModel
- GoogleMapsPlatform::DirectionsResponse
- Defined in:
- lib/google_maps_platform/models/directions_response.rb
Overview
DirectionsResponse Model.
Instance Attribute Summary collapse
-
#available_travel_modes ⇒ Array[TravelMode]
Contains an array of available travel modes.
-
#error_message ⇒ String
When the service returns a status code other than
OK, there may be an additionalerror_messagefield within the response object. -
#geocoded_waypoints ⇒ Array[DirectionsGeocodedWaypoint]
Contains an array with details about the geocoding of origin, destination and waypoints.
-
#routes ⇒ Array[DirectionsRoute]
Contains an array of routes from the origin to the destination.
-
#status ⇒ DirectionsStatus
The status field within the Directions response object contains the status of the request, and may contain debugging information to help you track down why the Directions service failed.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
Instance Method Summary collapse
-
#initialize(routes:, status:, geocoded_waypoints: SKIP, available_travel_modes: SKIP, error_message: SKIP, additional_properties: nil) ⇒ DirectionsResponse
constructor
A new instance of DirectionsResponse.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
Methods inherited from BaseModel
#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json
Constructor Details
#initialize(routes:, status:, geocoded_waypoints: SKIP, available_travel_modes: SKIP, error_message: SKIP, additional_properties: nil) ⇒ DirectionsResponse
Returns a new instance of DirectionsResponse.
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/google_maps_platform/models/directions_response.rb', line 108 def initialize(routes:, status:, geocoded_waypoints: SKIP, available_travel_modes: SKIP, error_message: SKIP, additional_properties: nil) # Add additional model properties to the instance additional_properties = {} if additional_properties.nil? @geocoded_waypoints = geocoded_waypoints unless geocoded_waypoints == SKIP @routes = routes @status = status @available_travel_modes = available_travel_modes unless available_travel_modes == SKIP @error_message = unless == SKIP @additional_properties = additional_properties end |
Instance Attribute Details
#available_travel_modes ⇒ Array[TravelMode]
Contains an array of available travel modes. This field is returned when a request specifies a travel mode and gets no results. The array contains the available travel modes in the countries of the given set of waypoints. This field is not returned if one or more of the waypoints are ‘via waypoints’.
73 74 75 |
# File 'lib/google_maps_platform/models/directions_response.rb', line 73 def available_travel_modes @available_travel_modes end |
#error_message ⇒ String
When the service returns a status code other than OK, there may be an additional error_message field within the response object. This field contains more detailed information about the reasons behind the given status code. This field is not always returned, and its content is subject to change.
81 82 83 |
# File 'lib/google_maps_platform/models/directions_response.rb', line 81 def @error_message end |
#geocoded_waypoints ⇒ Array[DirectionsGeocodedWaypoint]
Contains an array with details about the geocoding of origin, destination and waypoints. Elements in the geocoded_waypoints array correspond, by their zero-based position, to the origin, the waypoints in the order they are specified, and the destination. These details will not be present for waypoints specified as textual latitude/longitude values if the service returns no results. This is because such waypoints are only reverse geocoded to obtain their representative address after a route has been found. An empty JSON object will occupy the corresponding places in the geocoded_waypoints array.
22 23 24 |
# File 'lib/google_maps_platform/models/directions_response.rb', line 22 def geocoded_waypoints @geocoded_waypoints end |
#routes ⇒ Array[DirectionsRoute]
Contains an array of routes from the origin to the destination. Routes consist of nested Legs and Steps.
27 28 29 |
# File 'lib/google_maps_platform/models/directions_response.rb', line 27 def routes @routes end |
#status ⇒ DirectionsStatus
The status field within the Directions response object contains the status of the request, and may contain debugging information to help you track down why the Directions service failed. The status field may contain the following values:
-
OKindicates the response contains a valid result. -
NOT_FOUNDindicates at least one of the locations specified in the
request’s origin, destination, or waypoints could not be geocoded.
-
ZERO_RESULTSindicates no route could be found between the origin and
destination.
-
MAX_WAYPOINTS_EXCEEDEDindicates that too many waypoints were provided
in the request. For applications using the Directions API as a web service, or the directions service in the Maps JavaScript API, the maximum allowed number of waypoints is 25, plus the origin and destination.
-
MAX_ROUTE_LENGTH_EXCEEDEDindicates the requested route is too long
and cannot be processed. This error occurs when more complex directions are returned. Try reducing the number of waypoints, turns, or instructions.
-
INVALID_REQUESTindicates that the provided request was invalid.
Common causes of this status include an invalid parameter or parameter value.
-
OVER_DAILY_LIMITindicates any of the following:- The API key is missing or invalid. - Billing has not been enabled on your account. - A self-imposed usage cap has been exceeded. - The provided method of payment is no longer valid (for example, a
credit card has expired).
See the [Maps
FAQ](developers.google.com/maps/faq#over-limit-key-error) to learn how to fix this.
-
OVER_QUERY_LIMITindicates the service has received too many requests
from your application within the allowed time period.
-
REQUEST_DENIEDindicates that the service denied use of the directions
service by your application.
-
UNKNOWN_ERRORindicates a directions request could not be processed
due to a server error. The request may succeed if you try again.
65 66 67 |
# File 'lib/google_maps_platform/models/directions_response.rb', line 65 def status @status end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/google_maps_platform/models/directions_response.rb', line 123 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. # Parameter is an array, so we need to iterate through it routes = nil unless hash['routes'].nil? routes = [] hash['routes'].each do |structure| routes << (DirectionsRoute.from_hash(structure) if structure) end end routes = nil unless hash.key?('routes') status = hash.key?('status') ? hash['status'] : nil # Parameter is an array, so we need to iterate through it geocoded_waypoints = nil unless hash['geocoded_waypoints'].nil? geocoded_waypoints = [] hash['geocoded_waypoints'].each do |structure| geocoded_waypoints << (DirectionsGeocodedWaypoint.from_hash(structure) if structure) end end geocoded_waypoints = SKIP unless hash.key?('geocoded_waypoints') available_travel_modes = hash.key?('available_travel_modes') ? hash['available_travel_modes'] : SKIP = hash.key?('error_message') ? hash['error_message'] : SKIP # Create a new hash for additional properties, removing known properties. new_hash = hash.reject { |k, _| names.value?(k) } additional_properties = APIHelper.get_additional_properties( new_hash, proc { |value| value } ) # Create object from extracted values. DirectionsResponse.new(routes: routes, status: status, geocoded_waypoints: geocoded_waypoints, available_travel_modes: available_travel_modes, error_message: , additional_properties: additional_properties) end |
.names ⇒ Object
A mapping from model property names to API property names.
84 85 86 87 88 89 90 91 92 |
# File 'lib/google_maps_platform/models/directions_response.rb', line 84 def self.names @_hash = {} if @_hash.nil? @_hash['geocoded_waypoints'] = 'geocoded_waypoints' @_hash['routes'] = 'routes' @_hash['status'] = 'status' @_hash['available_travel_modes'] = 'available_travel_modes' @_hash['error_message'] = 'error_message' @_hash end |
.nullables ⇒ Object
An array for nullable fields
104 105 106 |
# File 'lib/google_maps_platform/models/directions_response.rb', line 104 def self.nullables [] end |
.optionals ⇒ Object
An array for optional fields
95 96 97 98 99 100 101 |
# File 'lib/google_maps_platform/models/directions_response.rb', line 95 def self.optionals %w[ geocoded_waypoints available_travel_modes error_message ] end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
177 178 179 180 181 182 183 |
# File 'lib/google_maps_platform/models/directions_response.rb', line 177 def inspect class_name = self.class.name.split('::').last "<#{class_name} geocoded_waypoints: #{@geocoded_waypoints.inspect}, routes:"\ " #{@routes.inspect}, status: #{@status.inspect}, available_travel_modes:"\ " #{@available_travel_modes.inspect}, error_message: #{@error_message.inspect},"\ " additional_properties: #{@additional_properties}>" end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
169 170 171 172 173 174 |
# File 'lib/google_maps_platform/models/directions_response.rb', line 169 def to_s class_name = self.class.name.split('::').last "<#{class_name} geocoded_waypoints: #{@geocoded_waypoints}, routes: #{@routes}, status:"\ " #{@status}, available_travel_modes: #{@available_travel_modes}, error_message:"\ " #{@error_message}, additional_properties: #{@additional_properties}>" end |