Skip to content
Snippets Groups Projects
Commit 0d4024a3 authored by Alex Reisner's avatar Alex Reisner
Browse files

Remove Google Premier-specific configuration.

Instead use an array for key, client, and channel.
parent eac42d33
No related branches found
No related tags found
No related merge requests found
......@@ -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],
......
......@@ -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)
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment