diff --git a/lib/geocoder/configuration.rb b/lib/geocoder/configuration.rb index e7bc208bb098871217cceaddd601b5aff6a2584d..775a4ff39c68c659cd1618755e6664a31dcb98a3 100644 --- a/lib/geocoder/configuration.rb +++ b/lib/geocoder/configuration.rb @@ -15,11 +15,8 @@ module Geocoder # use HTTPS for lookup requests? (if supported) [:use_https, false], - # app id (if using Yahoo geocoding service) - [:yahoo_appid, nil], - - # API key (if using Google geocoding service) - [:google_api_key, nil], + # API key for geocoding service + [:api_key, nil], # cache object (must respond to #[], #[]=, and #keys) [:cache, nil], @@ -35,6 +32,13 @@ module Geocoder eval("def self.#{o}=(obj); @@#{o} = obj; end") end + # legacy support + def self.yahoo_app_id=(value) + warn "DEPRECATION WARNING: Geocoder's 'yahoo_app_id' setting has been replaced by 'api_key'. " + + "This method will be removed in Geocoder v1.0." + @@api_key = value + end + ## # Set all values to default. # diff --git a/lib/geocoder/lookups/google.rb b/lib/geocoder/lookups/google.rb index 7584bf733778ce93df22c674515bd8a563720bba..72e54184f21a4dc6260a295c8d1ea5be5913b9d8 100644 --- a/lib/geocoder/lookups/google.rb +++ b/lib/geocoder/lookups/google.rb @@ -24,7 +24,7 @@ module Geocoder::Lookup (reverse ? :latlng : :address) => query, :sensor => "false", :language => Geocoder::Configuration.language, - :key => Geocoder::Configuration.google_api_key + :key => Geocoder::Configuration.api_key } "#{protocol}://maps.google.com/maps/api/geocode/json?" + hash_to_query(params) end diff --git a/lib/geocoder/lookups/yahoo.rb b/lib/geocoder/lookups/yahoo.rb index c0ba9d19ff63fd680348d928623ae380f5513c41..7d4b5494082352d94f96a626544408156d41e207 100644 --- a/lib/geocoder/lookups/yahoo.rb +++ b/lib/geocoder/lookups/yahoo.rb @@ -21,7 +21,7 @@ module Geocoder::Lookup :flags => "JXTSR", :gflags => "AC#{'R' if reverse}", :locale => "#{Geocoder::Configuration.language}_US", - :appid => Geocoder::Configuration.yahoo_appid + :appid => Geocoder::Configuration.api_key } "http://where.yahooapis.com/geocode?" + hash_to_query(params) end diff --git a/test/geocoder_test.rb b/test/geocoder_test.rb index 78c7874bb459df6aafb29bed0fe303eb3909c6f2..3dda9307cfb7bde474d8984948af01e3c80e1573 100644 --- a/test/geocoder_test.rb +++ b/test/geocoder_test.rb @@ -232,11 +232,17 @@ class GeocoderTest < Test::Unit::TestCase end def test_google_api_key - Geocoder::Configuration.google_api_key = "MY_KEY" + Geocoder::Configuration.api_key = "MY_KEY" g = Geocoder::Lookup::Google.new assert_match "key=MY_KEY", g.send(:query_url, "Madison Square Garden, New York, NY 10001, United States") end + def test_yahoo_app_id + Geocoder::Configuration.api_key = "MY_KEY" + g = Geocoder::Lookup::Yahoo.new + assert_match "appid=MY_KEY", g.send(:query_url, "Madison Square Garden, New York, NY 10001, United States") + end + private # ------------------------------------------------------------------