diff --git a/lib/geocoder/lookups/google.rb b/lib/geocoder/lookups/google.rb index 74d273de94bd539b05f4101e930cd093ceb82331..831b619f15f723830475ea10cb47c7065ca6ce74 100644 --- a/lib/geocoder/lookups/google.rb +++ b/lib/geocoder/lookups/google.rb @@ -12,6 +12,15 @@ module Geocoder::Lookup "http://maps.google.com/maps?q=#{coordinates.join(',')}" end + def supported_protocols + # Google requires HTTPS if an API key is used. + if configuration.api_key + [:https] + else + [:http, :https] + end + end + def query_url(query) "#{protocol}://maps.googleapis.com/maps/api/geocode/json?" + url_query_string(query) end diff --git a/test/unit/https_test.rb b/test/unit/https_test.rb index 6392f2a1e6a6151949820c64a602ebae30891a2b..dbdbc75e62da9405005571c24cd2f23590511ac0 100644 --- a/test/unit/https_test.rb +++ b/test/unit/https_test.rb @@ -10,7 +10,7 @@ class HttpsTest < GeocoderTestCase end def test_uses_http_by_default - g = Geocoder::Lookup::Google.new + g = Geocoder::Lookup::Esri.new assert_match(/^http:/, g.query_url(Geocoder::Query.new("test"))) end end diff --git a/test/unit/lookups/google_premier_test.rb b/test/unit/lookups/google_premier_test.rb index c96c4a1ff212a7df5105599b50e0376ac16f4ab8..ceb5e8c6acaa01e16f278f445e35a9a22bffe387 100644 --- a/test/unit/lookups/google_premier_test.rb +++ b/test/unit/lookups/google_premier_test.rb @@ -16,6 +16,6 @@ class GooglePremierTest < GeocoderTestCase def test_query_url Geocoder.configure(google_premier: {api_key: ["deadbeef", "gme-test", "test-dev"]}) query = Geocoder::Query.new("Madison Square Garden, New York, NY") - 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=", query.url + assert_equal "https://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=", query.url end end diff --git a/test/unit/lookups/google_test.rb b/test/unit/lookups/google_test.rb index 0581fbf193d748af2d66383512dea59d6ff5a30e..d7f72e769b7954f17dce53446082ed7facc69c54 100644 --- a/test/unit/lookups/google_test.rb +++ b/test/unit/lookups/google_test.rb @@ -80,4 +80,9 @@ class GoogleTest < GeocoderTestCase assert url.include?(formatted), "Expected #{formatted} to be included in #{url}" end + def test_google_uses_https_when_api_key_is_set + Geocoder.configure(api_key: "deadbeef") + query = Geocoder::Query.new("Madison Square Garden, New York, NY") + assert_match /^https:/, query.url + end end diff --git a/test/unit/proxy_test.rb b/test/unit/proxy_test.rb index 23d8789a2379c72ed591224fe14b109cf616a06b..4f6715424ff3a8e19f5b45b548defdb48500b6ae 100644 --- a/test/unit/proxy_test.rb +++ b/test/unit/proxy_test.rb @@ -5,25 +5,25 @@ class ProxyTest < GeocoderTestCase def test_uses_proxy_when_specified Geocoder.configure(:http_proxy => 'localhost') - lookup = Geocoder::Lookup::Google.new + lookup = Geocoder::Lookup::Esri.new assert lookup.send(:http_client).proxy_class? end def test_doesnt_use_proxy_when_not_specified - lookup = Geocoder::Lookup::Google.new + lookup = Geocoder::Lookup::Esri.new assert !lookup.send(:http_client).proxy_class? end def test_exception_raised_on_bad_proxy_url Geocoder.configure(:http_proxy => ' \\_O< Quack Quack') assert_raise Geocoder::ConfigurationError do - Geocoder::Lookup::Google.new.send(:http_client) + Geocoder::Lookup::Esri.new.send(:http_client) end end def test_accepts_proxy_with_http_protocol Geocoder.configure(:http_proxy => 'http://localhost') - lookup = Geocoder::Lookup::Google.new + lookup = Geocoder::Lookup::Esri.new assert lookup.send(:http_client).proxy_class? end