Class: GoogleMapsPlatform::GeocodingResponse

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

Overview

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

Returns a new instance of GeocodingResponse.



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/google_maps_platform/models/geocoding_response.rb', line 79

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

  additional_properties = {} if additional_properties.nil?

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

Instance Attribute Details

#error_messageString

A short description of the error.

Returns:

  • (String)


54
55
56
# File 'lib/google_maps_platform/models/geocoding_response.rb', line 54

def error_message
  @error_message
end

#plus_codePlusCode

An encoded location reference, derived from latitude and longitude coordinates, that represents an area, 1/8000th of a degree by 1/8000th of a degree (about 14m x 14m at the equator) or smaller. Plus codes can be used as a replacement for street addresses in places where they do not exist (where buildings are not numbered or streets are not named).

Returns:



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

def plus_code
  @plus_code
end

#resultsArray[GeocodingResult]

An encoded location reference, derived from latitude and longitude coordinates, that represents an area, 1/8000th of a degree by 1/8000th of a degree (about 14m x 14m at the equator) or smaller. Plus codes can be used as a replacement for street addresses in places where they do not exist (where buildings are not numbered or streets are not named).

Returns:



26
27
28
# File 'lib/google_maps_platform/models/geocoding_response.rb', line 26

def results
  @results
end

#statusGeocodingStatus

The status field within the Geocoding response object contains the status of the request, and may contain debugging information to help you track down why geocoding is not working. The “status” field may contain the following values:

  • OK indicates that no errors occurred; the address was successfully

parsed and at least one geocode was returned.

  • ZERO_RESULTS indicates that the geocode was successful but returned no

results. This may occur if the geocoder was passed a non-existent address or a latlng in a remote location.

  • 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 that you are over your quota.

  • REQUEST_DENIED indicates that your request was denied.

  • INVALID_REQUEST generally indicates that the query (address,

components, or latlng) is missing.

  • UNKNOWN_ERROR indicates that the request could not be processed due to

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

Returns:



50
51
52
# File 'lib/google_maps_platform/models/geocoding_response.rb', line 50

def status
  @status
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
117
118
119
120
121
122
123
# File 'lib/google_maps_platform/models/geocoding_response.rb', line 92

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

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

  results = nil unless hash.key?('results')
  status = hash.key?('status') ? hash['status'] : nil
  plus_code = PlusCode.from_hash(hash['plus_code']) if hash['plus_code']
  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.

  GeocodingResponse.new(results: results,
                        status: status,
                        plus_code: plus_code,
                        error_message: error_message,
                        additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



57
58
59
60
61
62
63
64
# File 'lib/google_maps_platform/models/geocoding_response.rb', line 57

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

.nullablesObject

An array for nullable fields



75
76
77
# File 'lib/google_maps_platform/models/geocoding_response.rb', line 75

def self.nullables
  []
end

.optionalsObject

An array for optional fields



67
68
69
70
71
72
# File 'lib/google_maps_platform/models/geocoding_response.rb', line 67

def self.optionals
  %w[
    plus_code
    error_message
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



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

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} plus_code: #{@plus_code.inspect}, results: #{@results.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.



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

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