Class: Graticule::Geocoder::GeocoderCa
- Defined in:
- lib/graticule/geocoder/geocoder_ca.rb
Overview
TODO: Reverse Geocoding
Instance Method Summary collapse
-
#check_error(xml) ⇒ Object
:nodoc:.
-
#initialize(auth = nil) ⇒ GeocoderCa
constructor
A new instance of GeocoderCa.
- #locate(address) ⇒ Object
-
#make_url(params) ⇒ Object
:nodoc:.
-
#parse_response(xml) ⇒ Object
:nodoc:.
Constructor Details
#initialize(auth = nil) ⇒ GeocoderCa
Returns a new instance of GeocoderCa.
7 8 9 10 |
# File 'lib/graticule/geocoder/geocoder_ca.rb', line 7 def initialize(auth = nil) @url = URI.parse 'http://geocoder.ca/' @auth = auth end |
Instance Method Details
#check_error(xml) ⇒ Object
:nodoc:
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/graticule/geocoder/geocoder_ca.rb', line 26 def check_error(xml) #:nodoc: error = xml.elements['geodata/error'] if error code = error.elements['code'].text.to_i = error.elements['description'].text if (1..3).include?(code) raise CredentialsError, elsif (4..8).include?(code) raise AddressError, else raise Error, end end end |
#locate(address) ⇒ Object
12 13 14 |
# File 'lib/graticule/geocoder/geocoder_ca.rb', line 12 def locate(address) get :locate => address.is_a?(String) ? address : location_from_params(address).to_s(:country => false) end |
#make_url(params) ⇒ Object
:nodoc:
41 42 43 44 45 46 47 |
# File 'lib/graticule/geocoder/geocoder_ca.rb', line 41 def make_url(params) #:nodoc: params[:auth] = @auth if @auth params[:standard] = 1 params[:showpostal] = 1 params[:geoit] = 'XML' super params end |
#parse_response(xml) ⇒ Object
:nodoc:
16 17 18 19 20 21 22 23 24 |
# File 'lib/graticule/geocoder/geocoder_ca.rb', line 16 def parse_response(xml) #:nodoc: returning Location.new do |location| location.latitude = xml.elements['geodata/latt'].text.to_f location.longitude = xml.elements['geodata/longt'].text.to_f location.street = xml.elements['geodata/standard/staddress'].text location.locality = xml.elements['geodata/standard/city'].text location.region = xml.elements['geodata/standard/prov'].text end end |