Class: GoogleMapsPlatform::DistanceMatrixResponse

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/google_maps_platform/models/distance_matrix_response.rb

Overview

DistanceMatrixResponse Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(origin_addresses:, destination_addresses:, rows:, status:, error_message: SKIP, additional_properties: nil) ⇒ DistanceMatrixResponse

Returns a new instance of DistanceMatrixResponse.



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/google_maps_platform/models/distance_matrix_response.rb', line 81

def initialize(origin_addresses:, destination_addresses:, rows:, status:,
               error_message: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @origin_addresses = origin_addresses
  @destination_addresses = destination_addresses
  @rows = rows
  @status = status
  @error_message = error_message unless error_message == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#destination_addressesArray[String]

An array of addresses as returned by the API from your original request. As with origin_addresses, these are localized if appropriate. This content is meant to be read as-is. Do not programatically parse the formatted addresses.

Returns:

  • (Array[String])


24
25
26
# File 'lib/google_maps_platform/models/distance_matrix_response.rb', line 24

def destination_addresses
  @destination_addresses
end

#error_messageString

A string containing the human-readable text of any errors encountered while the request was being processed.

Returns:

  • (String)


56
57
58
# File 'lib/google_maps_platform/models/distance_matrix_response.rb', line 56

def error_message
  @error_message
end

#origin_addressesArray[String]

An array of addresses as returned by the API from your original request. These are formatted by the geocoder and localized according to the language parameter passed with the request. This content is meant to be read as-is. Do not programatically parse the formatted addresses.

Returns:

  • (Array[String])


17
18
19
# File 'lib/google_maps_platform/models/distance_matrix_response.rb', line 17

def origin_addresses
  @origin_addresses
end

#rowsArray[DistanceMatrixRow]

An array of elements, which in turn each contain a status, duration, and distance element.

Returns:



29
30
31
# File 'lib/google_maps_platform/models/distance_matrix_response.rb', line 29

def rows
  @rows
end

#statusDistanceMatrixStatus

Status codes returned by service.

  • OK indicates the response contains a valid result.

  • INVALID_REQUEST indicates that the provided request was invalid.

  • MAX_ELEMENTS_EXCEEDED indicates that the product of origins and

destinations exceeds the per-query limit.

  • MAX_DIMENSIONS_EXCEEDED indicates that the number of origins or

destinations exceeds the per-query limit.

  • OVER_DAILY_LIMIT indicates 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).

  • OVER_QUERY_LIMIT indicates the service has received too many requests

from your application within the allowed time period.

  • REQUEST_DENIED indicates that the service denied use of the Distance

Matrix service by your application.

  • UNKNOWN_ERROR indicates a Distance Matrix request could not be

processed due to a server error. The request may succeed if you try again.



51
52
53
# File 'lib/google_maps_platform/models/distance_matrix_response.rb', line 51

def status
  @status
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/google_maps_platform/models/distance_matrix_response.rb', line 95

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  origin_addresses =
    hash.key?('origin_addresses') ? hash['origin_addresses'] : nil
  destination_addresses =
    hash.key?('destination_addresses') ? hash['destination_addresses'] : nil
  # Parameter is an array, so we need to iterate through it
  rows = nil
  unless hash['rows'].nil?
    rows = []
    hash['rows'].each do |structure|
      rows << (DistanceMatrixRow.from_hash(structure) if structure)
    end
  end

  rows = nil unless hash.key?('rows')
  status = hash.key?('status') ? hash['status'] : nil
  error_message = 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.
  DistanceMatrixResponse.new(origin_addresses: origin_addresses,
                             destination_addresses: destination_addresses,
                             rows: rows,
                             status: status,
                             error_message: error_message,
                             additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



59
60
61
62
63
64
65
66
67
# File 'lib/google_maps_platform/models/distance_matrix_response.rb', line 59

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['origin_addresses'] = 'origin_addresses'
  @_hash['destination_addresses'] = 'destination_addresses'
  @_hash['rows'] = 'rows'
  @_hash['status'] = 'status'
  @_hash['error_message'] = 'error_message'
  @_hash
end

.nullablesObject

An array for nullable fields



77
78
79
# File 'lib/google_maps_platform/models/distance_matrix_response.rb', line 77

def self.nullables
  []
end

.optionalsObject

An array for optional fields



70
71
72
73
74
# File 'lib/google_maps_platform/models/distance_matrix_response.rb', line 70

def self.optionals
  %w[
    error_message
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



141
142
143
144
145
146
147
# File 'lib/google_maps_platform/models/distance_matrix_response.rb', line 141

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} origin_addresses: #{@origin_addresses.inspect}, destination_addresses:"\
  " #{@destination_addresses.inspect}, rows: #{@rows.inspect}, status: #{@status.inspect},"\
  " error_message: #{@error_message.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



133
134
135
136
137
138
# File 'lib/google_maps_platform/models/distance_matrix_response.rb', line 133

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} origin_addresses: #{@origin_addresses}, destination_addresses:"\
  " #{@destination_addresses}, rows: #{@rows}, status: #{@status}, error_message:"\
  " #{@error_message}, additional_properties: #{@additional_properties}>"
end