lib/graticule/geocoder/yahoo.rb in graticule-2.0.1 vs lib/graticule/geocoder/yahoo.rb in graticule-2.1.0
- old
+ new
@@ -1,8 +1,9 @@
+# encoding: UTF-8
module Graticule #:nodoc:
module Geocoder #:nodoc:
-
+
# Yahoo geocoding API.
#
# http://developer.yahoo.com/maps/rest/V1/geocode.html
class Yahoo < Base
@@ -40,44 +41,44 @@
def locate(address)
location = (address.is_a?(String) ? address : location_from_params(address).to_s(:country => false))
# yahoo pukes on line breaks
get :location => location.gsub("\n", ', ')
end
-
+
private
-
+
class Address
include HappyMapper
tag 'Result'
-
+
attribute :precision, String
attribute :warning, String
element :latitude, Float, :tag => 'Latitude'
element :longitude, Float, :tag => 'Longitude'
element :street, String, :tag => 'Address'
element :locality, String, :tag => 'City'
element :region, String, :tag => 'State'
element :postal_code, String, :tag => 'Zip'
element :country, String, :tag => 'Country'
-
+
def precision
PRECISION[@precision] || :unknown
end
end
-
+
class Result
include HappyMapper
tag 'ResultSet'
has_many :addresses, Address
end
-
+
class Error
include HappyMapper
tag 'Error'
element :message, String, :tag => 'Message'
end
-
+
def parse_response(response) # :nodoc:
addr = Result.parse(response, :single => true).addresses.first
Location.new(
:latitude => addr.latitude,
:longitude => addr.longitude,
@@ -106,8 +107,8 @@
super params
end
end
-
+
end
end
\ No newline at end of file