From 0d4024a3bdd60500bf01f428d00adbedb3278853 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Tue, 13 Sep 2011 09:18:03 -0400 Subject: [PATCH] Remove Google Premier-specific configuration. Instead use an array for key, client, and channel. --- lib/geocoder/configuration.rb | 7 +------ lib/geocoder/lookups/google_premier.rb | 6 +++--- test/services_test.rb | 4 +--- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/geocoder/configuration.rb b/lib/geocoder/configuration.rb index 5c83adf8..54fceacf 100644 --- a/lib/geocoder/configuration.rb +++ b/lib/geocoder/configuration.rb @@ -22,14 +22,9 @@ module Geocoder [:https_proxy, nil], # API key for geocoding service + # for Google Premier use a 3-element array: [key, client, channel] [:api_key, nil], - # API client for geocoding service - [:api_client, nil], - - # API channel for geocoding service - [:api_channel, nil], - # cache object (must respond to #[], #[]=, and #keys) [:cache, nil], diff --git a/lib/geocoder/lookups/google_premier.rb b/lib/geocoder/lookups/google_premier.rb index 31a033e7..6befdddf 100644 --- a/lib/geocoder/lookups/google_premier.rb +++ b/lib/geocoder/lookups/google_premier.rb @@ -13,15 +13,15 @@ module Geocoder::Lookup (reverse ? :latlng : :address) => query, :sensor => 'false', :language => Geocoder::Configuration.language, - :client => Geocoder::Configuration.api_client, - :channel => Geocoder::Configuration.api_channel + :client => Geocoder::Configuration.api_key[1], + :channel => Geocoder::Configuration.api_key[2] }.reject{ |key, value| value.nil? } path = "/maps/api/geocode/json?#{hash_to_query(params)}" "#{protocol}://maps.googleapis.com#{path}&signature=#{sign(path)}" end def sign(string) - raw_private_key = url_safe_base64_decode(Geocoder::Configuration.api_key) + raw_private_key = url_safe_base64_decode(Geocoder::Configuration.api_key[0]) digest = OpenSSL::Digest::Digest.new('sha1') raw_signature = OpenSSL::HMAC.digest(digest, raw_private_key, string) url_safe_base64_encode(raw_signature) diff --git a/test/services_test.rb b/test/services_test.rb index d1a8218f..da81f7c9 100644 --- a/test/services_test.rb +++ b/test/services_test.rb @@ -43,9 +43,7 @@ class ServicesTest < Test::Unit::TestCase end def test_google_premier_query_url - Geocoder::Configuration.api_key = "deadbeef" - Geocoder::Configuration.api_client = "gme-test" - Geocoder::Configuration.api_channel = "test-dev" + Geocoder::Configuration.api_key = ["deadbeef", "gme-test", "test-dev"] assert_equal "http://maps.googleapis.com/maps/api/geocode/json?address=Madison+Square+Garden%2C+New+York%2C+NY&channel=test-dev&client=gme-test&language=en&sensor=false&signature=doJvJqX7YJzgV9rJ0DnVkTGZqTg=", Geocoder::Lookup::GooglePremier.new.send(:query_url, "Madison Square Garden, New York, NY", false) end -- GitLab