From 46d1cb818c38b3ecd616e123fd1e2263858415c2 Mon Sep 17 00:00:00 2001
From: Alex Reisner <alex@alexreisner.com>
Date: Thu, 17 Mar 2011 23:27:30 -0400
Subject: [PATCH] Deprecate yahoo_app_id in favor of api_key.

Now that we also support an API key for Google it makes sense for this to
be generic.
---
 lib/geocoder/configuration.rb  | 14 +++++++++-----
 lib/geocoder/lookups/google.rb |  2 +-
 lib/geocoder/lookups/yahoo.rb  |  2 +-
 test/geocoder_test.rb          |  8 +++++++-
 4 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/lib/geocoder/configuration.rb b/lib/geocoder/configuration.rb
index e7bc208b..775a4ff3 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 7584bf73..72e54184 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 c0ba9d19..7d4b5494 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 78c7874b..3dda9307 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 # ------------------------------------------------------------------
 
-- 
GitLab