diff --git a/lib/geocoder/lookups/google.rb b/lib/geocoder/lookups/google.rb index 831b619f15f723830475ea10cb47c7065ca6ce74..d3ffeb74cfd84ca9b8c52b5fcede046d788e220b 100644 --- a/lib/geocoder/lookups/google.rb +++ b/lib/geocoder/lookups/google.rb @@ -65,6 +65,9 @@ module Geocoder::Lookup unless (components = query.options[:components]).nil? params[:components] = components.is_a?(Array) ? components.join("|") : components end + unless (result_type = query.options[:result_type]).nil? + params[:result_type] = result_type.is_a?(Array) ? result_type.join("|") : result_type + end params end diff --git a/test/unit/lookups/google_test.rb b/test/unit/lookups/google_test.rb index d658a82745c980de185d4dfca0ffded0b3adc2e5..490b863d523ed1c777413f4f885127fbb0de9029 100644 --- a/test/unit/lookups/google_test.rb +++ b/test/unit/lookups/google_test.rb @@ -86,6 +86,26 @@ class GoogleTest < GeocoderTestCase assert url.include?(formatted), "Expected #{formatted} to be included in #{url}" end + def test_google_query_url_contains_result_type_when_given_as_string + lookup = Geocoder::Lookup::Google.new + url = lookup.query_url(Geocoder::Query.new( + "Some Intersection", + :result_type => "country" + )) + formatted = "result_type=" + CGI.escape("country") + assert url.include?(formatted), "Expected #{formatted} to be included in #{url}" + end + + def test_google_query_url_contains_result_type_when_given_as_array + lookup = Geocoder::Lookup::Google.new + url = lookup.query_url(Geocoder::Query.new( + "Some Intersection", + :result_type => ["country", "postal_code"] + )) + formatted = "result_type=" + CGI.escape("country|postal_code") + 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")