Class: GoogleMapsPlatform::PlacesAutocompleteResponse

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

Overview

PlacesAutocompleteResponse 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(predictions:, status:, error_message: SKIP, info_messages: SKIP, additional_properties: nil) ⇒ PlacesAutocompleteResponse

Returns a new instance of PlacesAutocompleteResponse.



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

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

  @predictions = predictions
  @status = status
  @error_message = error_message unless error_message == SKIP
  @info_messages = info_messages unless info_messages == SKIP
  @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)


47
48
49
# File 'lib/google_maps_platform/models/places_autocomplete_response.rb', line 47

def error_message
  @error_message
end

#info_messagesArray[String]

When the service returns additional information about the request specification, there may be an additional info_messages field within the response object. This field is only returned for successful requests. It may not always be returned, and its content is subject to change.

Returns:

  • (Array[String])


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

def info_messages
  @info_messages
end

#predictionsArray[PlaceAutocompletePrediction]

Contains an array of predictions.

Returns:



14
15
16
# File 'lib/google_maps_platform/models/places_autocomplete_response.rb', line 14

def predictions
  @predictions
end

#statusPlacesAutocompleteStatus

Status codes returned by service.

  • OK indicating the API request was successful.

  • ZERO_RESULTS indicating that the search was successful but returned no

results. This may occur if the search was passed a bounds in a remote location.

  • INVALID_REQUEST indicating the API request was malformed, generally

due to the missing input parameter.

  • OVER_QUERY_LIMIT indicating any of the following:

    • You have exceeded the QPS limits.

    • Billing has not been enabled on your account.

    • The monthly $200 credit, or 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) for more information about how to resolve this error.

  • REQUEST_DENIED indicating that your request was denied, generally

because:

- The request is missing an API key.
- The `key` parameter is invalid.
  • UNKNOWN_ERROR indicating an unknown error.



39
40
41
# File 'lib/google_maps_platform/models/places_autocomplete_response.rb', line 39

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/places_autocomplete_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
  predictions = nil
  unless hash['predictions'].nil?
    predictions = []
    hash['predictions'].each do |structure|
      predictions << (PlaceAutocompletePrediction.from_hash(structure) if structure)
    end
  end

  predictions = nil unless hash.key?('predictions')
  status = hash.key?('status') ? hash['status'] : nil
  error_message = hash.key?('error_message') ? hash['error_message'] : SKIP
  info_messages = hash.key?('info_messages') ? hash['info_messages'] : 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.
  PlacesAutocompleteResponse.new(predictions: predictions,
                                 status: status,
                                 error_message: error_message,
                                 info_messages: info_messages,
                                 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/places_autocomplete_response.rb', line 57

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

.nullablesObject

An array for nullable fields



75
76
77
# File 'lib/google_maps_platform/models/places_autocomplete_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/places_autocomplete_response.rb', line 67

def self.optionals
  %w[
    error_message
    info_messages
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



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

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

#to_sObject

Provides a human-readable string representation of the object.



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

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