Skip to content

Commit

Permalink
Remove Google Premier-specific configuration.
Browse files Browse the repository at this point in the history
Instead use an array for key, client, and channel.
  • Loading branch information
alexreisner committed Sep 13, 2011
1 parent eac42d3 commit 0d4024a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
7 changes: 1 addition & 6 deletions lib/geocoder/configuration.rb
Expand Up @@ -22,14 +22,9 @@ def self.options_and_defaults
[: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],

Expand Down
6 changes: 3 additions & 3 deletions lib/geocoder/lookups/google_premier.rb
Expand Up @@ -13,15 +13,15 @@ def query_url(query, reverse = false)
(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)
Expand Down
4 changes: 1 addition & 3 deletions test/services_test.rb
Expand Up @@ -43,9 +43,7 @@ def test_google_premier_result_components
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
Expand Down

0 comments on commit 0d4024a

Please sign in to comment.