Class: GoogleMapsPlatform::ElevationResponse

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

Overview

ElevationResponse 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(status:, results:, error_message: SKIP, additional_properties: nil) ⇒ ElevationResponse

Returns a new instance of ElevationResponse.



75
76
77
78
79
80
81
82
83
84
# File 'lib/google_maps_platform/models/elevation_response.rb', line 75

def initialize(status:, results:, error_message: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance

  additional_properties = {} if additional_properties.nil?

  @error_message = error_message unless error_message == SKIP
  @status = status
  @results = results
  @additional_properties = additional_properties
end

Instance Attribute Details

#error_messageString

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 thereasons behind the given status code. This field is not always returned, and its content is subject to change.

Returns:

  • (String)


18
19
20
# File 'lib/google_maps_platform/models/elevation_response.rb', line 18

def error_message
  @error_message
end

#resultsArray[ElevationResult]

Status codes returned by service.

  • OK indicating the API request was successful.

  • DATA_NOT_AVAILABLE indicating that there’s no available data for the

input locations.

  • INVALID_REQUEST indicating the API request was malformed.

  • OVER_DAILY_LIMIT indicating 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 indicating the requestor has exceeded quota.

  • REQUEST_DENIED indicating the API did not complete the request.

  • UNKNOWN_ERROR indicating an unknown error.

Returns:



52
53
54
# File 'lib/google_maps_platform/models/elevation_response.rb', line 52

def results
  @results
end

#statusElevationStatus

Status codes returned by service.

  • OK indicating the API request was successful.

  • DATA_NOT_AVAILABLE indicating that there’s no available data for the

input locations.

  • INVALID_REQUEST indicating the API request was malformed.

  • OVER_DAILY_LIMIT indicating 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 indicating the requestor has exceeded quota.

  • REQUEST_DENIED indicating the API did not complete the request.

  • UNKNOWN_ERROR indicating an unknown error.

Returns:



35
36
37
# File 'lib/google_maps_platform/models/elevation_response.rb', line 35

def status
  @status
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/google_maps_platform/models/elevation_response.rb', line 87

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  status = hash.key?('status') ? hash['status'] : nil
  # Parameter is an array, so we need to iterate through it

  results = nil
  unless hash['results'].nil?
    results = []
    hash['results'].each do |structure|
      results << (ElevationResult.from_hash(structure) if structure)
    end
  end

  results = nil unless hash.key?('results')
  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.

  ElevationResponse.new(status: status,
                        results: results,
                        error_message: error_message,
                        additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



55
56
57
58
59
60
61
# File 'lib/google_maps_platform/models/elevation_response.rb', line 55

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

.nullablesObject

An array for nullable fields



71
72
73
# File 'lib/google_maps_platform/models/elevation_response.rb', line 71

def self.nullables
  []
end

.optionalsObject

An array for optional fields



64
65
66
67
68
# File 'lib/google_maps_platform/models/elevation_response.rb', line 64

def self.optionals
  %w[
    error_message
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



126
127
128
129
130
# File 'lib/google_maps_platform/models/elevation_response.rb', line 126

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

#to_sObject

Provides a human-readable string representation of the object.



119
120
121
122
123
# File 'lib/google_maps_platform/models/elevation_response.rb', line 119

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