Class: Google::Geo::Response

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

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parser

#fetch, #fetch_accuracy

Constructor Details

#initialize(geo, params) ⇒ Response

:nodoc



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/google/geo/response.rb', line 12

def initialize(geo, params) #:nodoc
  @geo = geo
  
  @params = params
  @xml = open(params.to_uri).read
  
  @query  = fetch(:name)
  @status = fetch(:code).to_i
  
  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}"
    when 400 then raise BadRequestError, "Bad request: #{@status}"
    else          raise UnknownError, "Unknown error: #{@status}"
  end
  
  @placemarks = @xml.scan %r{<Placemark(?: id="p\d+")?>.+?</Placemark>}m
end

Instance Attribute Details

#geoObject (readonly)

Returns the value of attribute geo.



10
11
12
# File 'lib/google/geo/response.rb', line 10

def geo
  @geo
end

#paramsObject (readonly)

Returns the value of attribute params.



10
11
12
# File 'lib/google/geo/response.rb', line 10

def params
  @params
end

#queryObject (readonly)

Returns the value of attribute query.



10
11
12
# File 'lib/google/geo/response.rb', line 10

def query
  @query
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/google/geo/response.rb', line 10

def status
  @status
end

#xmlObject (readonly)

Returns the value of attribute xml.



10
11
12
# File 'lib/google/geo/response.rb', line 10

def xml
  @xml
end

Instance Method Details

#addressesObject



36
37
38
# File 'lib/google/geo/response.rb', line 36

def addresses
  @placemarks.map { |p| Address.new p, @query, @geo }
end