From f5c7fc0308f7f23b6aaa62ec4365b1836bd71cfe Mon Sep 17 00:00:00 2001 From: Han Loong Liauw <hanloongliauw@gmail.com> Date: Thu, 28 Apr 2016 16:54:30 +1000 Subject: [PATCH] add result type as option for google --- lib/geocoder/lookups/google.rb | 3 +++ test/unit/lookups/google_test.rb | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/geocoder/lookups/google.rb b/lib/geocoder/lookups/google.rb index 831b619f..d3ffeb74 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 d658a827..490b863d 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") -- GitLab