Class: Google::Geo::Response

Inherits:
Object
  • Object
show all
Includes:
Parser
Defined in:
lib/google/geo.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parser

#fetch, #fetch_accuracy

Constructor Details

#initialize(xml, geo_key) ⇒ Response

:nodoc



147
148
149
150
151
152
153
154
155
156
# File 'lib/google/geo.rb', line 147

def initialize(xml, geo_key) #:nodoc
  @xml, @geo_key = xml, geo_key
  
  @query  = fetch(:name)
  @status = fetch(:code).to_i
  
  check_for_errors
  
  @placemarks = @xml.scan %r{<Placemark(?: id="p\d+")?>.+?</Placemark>}m
end

Instance Attribute Details

#placemarksObject (readonly)

Returns the value of attribute placemarks.



145
146
147
# File 'lib/google/geo.rb', line 145

def placemarks
  @placemarks
end

#queryObject (readonly)

Returns the value of attribute query.



145
146
147
# File 'lib/google/geo.rb', line 145

def query
  @query
end

#statusObject (readonly)

Returns the value of attribute status.



145
146
147
# File 'lib/google/geo.rb', line 145

def status
  @status
end

Instance Method Details

#check_for_errorsObject

:nodoc:



158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/google/geo.rb', line 158

def check_for_errors #:nodoc:
  case status
    when 200 then # Success
    when 500 then raise ServerError, "Unknown error from Google's server"
    when 601 then raise MissingAddressError, "Missing address"
    when 602 then raise UnknownAddressError, "Unknown address: #{@query}"
    when 603 then raise UnavailableAddressError, "Unavailable address: #{@query}"
    when 610 then raise InvalidMapKeyError, "Invalid map key: #{@geo_key}"
    when 620 then raise TooManyQueriesError, "Too many queries for map key: #{@geo_key}"
    else          raise UnknownError, "Unknown error: #{@status}"
  end
end