From 64130c007da0fdd899b4ccd698cbd8340225a405 Mon Sep 17 00:00:00 2001
From: Alex Reisner <alex@alexreisner.com>
Date: Sat, 22 Dec 2012 19:20:15 -0500
Subject: [PATCH] Make Geocoder::Lookup::X#query_url method public.

---
 lib/geocoder/cli.rb                    |  2 +-
 lib/geocoder/lookups/base.rb           | 13 ++++++-------
 lib/geocoder/lookups/bing.rb           | 12 ++++++------
 lib/geocoder/lookups/freegeoip.rb      |  8 ++++----
 lib/geocoder/lookups/geocoder_ca.rb    |  8 ++++----
 lib/geocoder/lookups/google.rb         |  9 ++++-----
 lib/geocoder/lookups/google_premier.rb | 10 +++++-----
 lib/geocoder/lookups/mapquest.rb       |  4 ++--
 lib/geocoder/lookups/maxmind.rb        |  8 ++++----
 lib/geocoder/lookups/nominatim.rb      | 12 ++++++------
 lib/geocoder/lookups/yahoo.rb          | 16 ++++++++--------
 lib/geocoder/lookups/yandex.rb         |  8 ++++----
 test/https_test.rb                     |  4 ++--
 test/lookup_test.rb                    |  6 +++---
 test/services_test.rb                  | 14 +++++++-------
 15 files changed, 66 insertions(+), 68 deletions(-)

diff --git a/lib/geocoder/cli.rb b/lib/geocoder/cli.rb
index f564efa5..74e5bb1f 100644
--- a/lib/geocoder/cli.rb
+++ b/lib/geocoder/cli.rb
@@ -79,7 +79,7 @@ module Geocoder
 
       if show_url
         q = Geocoder::Query.new(query)
-        out << q.lookup.send(:query_url, q) + "\n"
+        out << q.lookup.query_url(q) + "\n"
         exit 0
       end
 
diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb
index 821a87b9..4120fc70 100644
--- a/lib/geocoder/lookups/base.rb
+++ b/lib/geocoder/lookups/base.rb
@@ -66,6 +66,12 @@ module Geocoder
         []
       end
 
+      ##
+      # URL to use for querying the geocoding engine.
+      #
+      def query_url(query)
+        fail
+      end
 
       private # -------------------------------------------------------------
 
@@ -113,13 +119,6 @@ module Geocoder
         )
       end
 
-      ##
-      # URL to use for querying the geocoding engine.
-      #
-      def query_url(query)
-        fail
-      end
-
       ##
       # Key to use for caching a geocoding result. Usually this will be the
       # request URL, but in cases where OAuth is used and the nonce,
diff --git a/lib/geocoder/lookups/bing.rb b/lib/geocoder/lookups/bing.rb
index 125dcdcf..44184508 100644
--- a/lib/geocoder/lookups/bing.rb
+++ b/lib/geocoder/lookups/bing.rb
@@ -16,6 +16,12 @@ module Geocoder::Lookup
       ["key"]
     end
 
+    def query_url(query)
+      "#{protocol}://dev.virtualearth.net/REST/v1/Locations" +
+        (query.reverse_geocode? ? "/#{query.sanitized_text}?" : "?") +
+        url_query_string(query)
+    end
+
     private # ---------------------------------------------------------------
 
     def results(query)
@@ -37,11 +43,5 @@ module Geocoder::Lookup
         :query => query.reverse_geocode? ? nil : query.sanitized_text
       )
     end
-
-    def query_url(query)
-      "#{protocol}://dev.virtualearth.net/REST/v1/Locations" +
-        (query.reverse_geocode? ? "/#{query.sanitized_text}?" : "?") +
-        url_query_string(query)
-    end
   end
 end
diff --git a/lib/geocoder/lookups/freegeoip.rb b/lib/geocoder/lookups/freegeoip.rb
index b94946a6..9efaaa4e 100644
--- a/lib/geocoder/lookups/freegeoip.rb
+++ b/lib/geocoder/lookups/freegeoip.rb
@@ -8,6 +8,10 @@ module Geocoder::Lookup
       "FreeGeoIP"
     end
 
+    def query_url(query)
+      "#{protocol}://freegeoip.net/json/#{query.sanitized_text}"
+    end
+
     private # ---------------------------------------------------------------
 
     def parse_raw_data(raw_data)
@@ -39,9 +43,5 @@ module Geocoder::Lookup
         "country_code" => "RD"
       }
     end
-
-    def query_url(query)
-      "#{protocol}://freegeoip.net/json/#{query.sanitized_text}"
-    end
   end
 end
diff --git a/lib/geocoder/lookups/geocoder_ca.rb b/lib/geocoder/lookups/geocoder_ca.rb
index 01919a0f..81e1f850 100644
--- a/lib/geocoder/lookups/geocoder_ca.rb
+++ b/lib/geocoder/lookups/geocoder_ca.rb
@@ -8,6 +8,10 @@ module Geocoder::Lookup
       "Geocoder.ca"
     end
 
+    def query_url(query)
+      "#{protocol}://geocoder.ca/?" + url_query_string(query)
+    end
+
     private # ---------------------------------------------------------------
 
     def results(query)
@@ -42,10 +46,6 @@ module Geocoder::Lookup
       params
     end
 
-    def query_url(query)
-      "#{protocol}://geocoder.ca/?" + url_query_string(query)
-    end
-
     def parse_raw_data(raw_data)
       super raw_data[/^test\((.*)\)\;\s*$/, 1]
     end
diff --git a/lib/geocoder/lookups/google.rb b/lib/geocoder/lookups/google.rb
index 5f5e8fe6..96387c45 100644
--- a/lib/geocoder/lookups/google.rb
+++ b/lib/geocoder/lookups/google.rb
@@ -12,6 +12,10 @@ module Geocoder::Lookup
       "http://maps.google.com/maps?q=#{coordinates.join(',')}"
     end
 
+    def query_url(query)
+      "#{protocol}://maps.googleapis.com/maps/api/geocode/json?" + url_query_string(query)
+    end
+
     private # ---------------------------------------------------------------
 
     def results(query)
@@ -54,10 +58,5 @@ module Geocoder::Lookup
         :key => configuration.api_key
       )
     end
-
-    def query_url(query)
-      "#{protocol}://maps.googleapis.com/maps/api/geocode/json?" + url_query_string(query)
-    end
   end
 end
-
diff --git a/lib/geocoder/lookups/google_premier.rb b/lib/geocoder/lookups/google_premier.rb
index 2bf63dc9..d555c632 100644
--- a/lib/geocoder/lookups/google_premier.rb
+++ b/lib/geocoder/lookups/google_premier.rb
@@ -14,6 +14,11 @@ module Geocoder::Lookup
       ["private key", "client", "channel"]
     end
 
+    def query_url(query)
+      path = "/maps/api/geocode/json?" + url_query_string(query)
+      "#{protocol}://maps.googleapis.com#{path}&signature=#{sign(path)}"
+    end
+
     private # ---------------------------------------------------------------
 
     def query_url_params(query)
@@ -24,11 +29,6 @@ module Geocoder::Lookup
       )
     end
 
-    def query_url(query)
-      path = "/maps/api/geocode/json?" + url_query_string(query)
-      "#{protocol}://maps.googleapis.com#{path}&signature=#{sign(path)}"
-    end
-
     def sign(string)
       raw_private_key = url_safe_base64_decode(configuration.api_key[0])
       digest = OpenSSL::Digest::Digest.new('sha1')
diff --git a/lib/geocoder/lookups/mapquest.rb b/lib/geocoder/lookups/mapquest.rb
index 46cc8c23..a0e31f39 100644
--- a/lib/geocoder/lookups/mapquest.rb
+++ b/lib/geocoder/lookups/mapquest.rb
@@ -13,8 +13,6 @@ module Geocoder::Lookup
       ["key"]
     end
 
-    private # ---------------------------------------------------------------
-
     def query_url(query)
       key = configuration.api_key
       domain = key ? "www" : "open"
@@ -22,6 +20,8 @@ module Geocoder::Lookup
       url + url_query_string(query)
     end
 
+    private # ---------------------------------------------------------------
+
     def search_type(query)
       query.reverse_geocode? ? "reverse" : "address"
     end
diff --git a/lib/geocoder/lookups/maxmind.rb b/lib/geocoder/lookups/maxmind.rb
index 2e6cb349..ba41e40e 100644
--- a/lib/geocoder/lookups/maxmind.rb
+++ b/lib/geocoder/lookups/maxmind.rb
@@ -9,6 +9,10 @@ module Geocoder::Lookup
       "MaxMind"
     end
 
+    def query_url(query)
+      "#{protocol}://geoip3.maxmind.com/f?" + url_query_string(query)
+    end
+
     private # ---------------------------------------------------------------
 
     def results(query)
@@ -40,9 +44,5 @@ module Geocoder::Lookup
         :i => query.sanitized_text
       )
     end
-
-    def query_url(query)
-      "#{protocol}://geoip3.maxmind.com/f?" + url_query_string(query)
-    end
   end
 end
diff --git a/lib/geocoder/lookups/nominatim.rb b/lib/geocoder/lookups/nominatim.rb
index 8fb7a6de..aea86e4b 100644
--- a/lib/geocoder/lookups/nominatim.rb
+++ b/lib/geocoder/lookups/nominatim.rb
@@ -12,6 +12,12 @@ module Geocoder::Lookup
       "http://www.openstreetmap.org/?lat=#{coordinates[0]}&lon=#{coordinates[1]}&zoom=15&layers=M"
     end
 
+    def query_url(query)
+      method = query.reverse_geocode? ? "reverse" : "search"
+      host = configuration[:host] || "nominatim.openstreetmap.org"
+      "#{protocol}://#{host}/#{method}?" + url_query_string(query)
+    end
+
     private # ---------------------------------------------------------------
 
     def results(query)
@@ -35,11 +41,5 @@ module Geocoder::Lookup
       end
       params
     end
-
-    def query_url(query)
-      method = query.reverse_geocode? ? "reverse" : "search"
-      host = configuration[:host] || "nominatim.openstreetmap.org"
-      "#{protocol}://#{host}/#{method}?" + url_query_string(query)
-    end
   end
 end
diff --git a/lib/geocoder/lookups/yahoo.rb b/lib/geocoder/lookups/yahoo.rb
index 77a658b4..a271b776 100644
--- a/lib/geocoder/lookups/yahoo.rb
+++ b/lib/geocoder/lookups/yahoo.rb
@@ -17,6 +17,14 @@ module Geocoder::Lookup
       ["consumer key", "consumer secret"]
     end
 
+    def query_url(query)
+      parsed_url = URI.parse(raw_url(query))
+      o = OauthUtil.new
+      o.consumer_key = configuration.api_key[0]
+      o.consumer_secret = configuration.api_key[1]
+      base_url + o.sign(parsed_url).query_string
+    end
+
     private # ---------------------------------------------------------------
 
     def results(query)
@@ -72,13 +80,5 @@ module Geocoder::Lookup
     def raw_url(query)
       base_url + url_query_string(query)
     end
-
-    def query_url(query)
-      parsed_url = URI.parse(raw_url(query))
-      o = OauthUtil.new
-      o.consumer_key = configuration.api_key[0]
-      o.consumer_secret = configuration.api_key[1]
-      base_url + o.sign(parsed_url).query_string
-    end
   end
 end
diff --git a/lib/geocoder/lookups/yandex.rb b/lib/geocoder/lookups/yandex.rb
index 8d76a434..9e93d50f 100644
--- a/lib/geocoder/lookups/yandex.rb
+++ b/lib/geocoder/lookups/yandex.rb
@@ -12,6 +12,10 @@ module Geocoder::Lookup
       "http://maps.yandex.ru/?ll=#{coordinates.reverse.join(',')}"
     end
 
+    def query_url(query)
+      "#{protocol}://geocode-maps.yandex.ru/1.x/?" + url_query_string(query)
+    end
+
     private # ---------------------------------------------------------------
 
     def results(query)
@@ -46,9 +50,5 @@ module Geocoder::Lookup
         :key => configuration.api_key
       )
     end
-
-    def query_url(query)
-      "#{protocol}://geocode-maps.yandex.ru/1.x/?" + url_query_string(query)
-    end
   end
 end
diff --git a/test/https_test.rb b/test/https_test.rb
index 3a922bf4..dd6d0204 100644
--- a/test/https_test.rb
+++ b/test/https_test.rb
@@ -6,11 +6,11 @@ class HttpsTest < Test::Unit::TestCase
   def test_uses_https_for_secure_query
     Geocoder.configure(:use_https => true)
     g = Geocoder::Lookup::Google.new
-    assert_match /^https:/, g.send(:query_url, Geocoder::Query.new("test"))
+    assert_match /^https:/, g.query_url(Geocoder::Query.new("test"))
   end
 
   def test_uses_http_by_default
     g = Geocoder::Lookup::Google.new
-    assert_match /^http:/, g.send(:query_url, Geocoder::Query.new("test"))
+    assert_match /^http:/, g.query_url(Geocoder::Query.new("test"))
   end
 end
diff --git a/test/lookup_test.rb b/test/lookup_test.rb
index 3fb9373b..eeba7ba5 100644
--- a/test/lookup_test.rb
+++ b/test/lookup_test.rb
@@ -24,7 +24,7 @@ class LookupTest < Test::Unit::TestCase
     Geocoder::Lookup.all_services_except_test.each do |l|
       next if l == :freegeoip # does not use query string
       set_api_key!(l)
-      url = Geocoder::Lookup.get(l).send(:query_url, Geocoder::Query.new(
+      url = Geocoder::Lookup.get(l).query_url(Geocoder::Query.new(
         "test", :params => {:one_in_the_hand => "two in the bush"}
       ))
       # should be "+"s for all lookups except Yahoo
@@ -72,13 +72,13 @@ class LookupTest < Test::Unit::TestCase
   def test_google_api_key
     Geocoder.configure(:api_key => "MY_KEY")
     g = Geocoder::Lookup::Google.new
-    assert_match "key=MY_KEY", g.send(:query_url, Geocoder::Query.new("Madison Square Garden, New York, NY  10001, United States"))
+    assert_match "key=MY_KEY", g.query_url(Geocoder::Query.new("Madison Square Garden, New York, NY  10001, United States"))
   end
 
   def test_geocoder_ca_showpostal
     Geocoder.configure(:api_key => "MY_KEY")
     g = Geocoder::Lookup::GeocoderCa.new
-    assert_match "showpostal=1", g.send(:query_url, Geocoder::Query.new("Madison Square Garden, New York, NY  10001, United States"))
+    assert_match "showpostal=1", g.query_url(Geocoder::Query.new("Madison Square Garden, New York, NY  10001, United States"))
   end
 
   def test_raises_configuration_error_on_missing_key
diff --git a/test/services_test.rb b/test/services_test.rb
index 3e2d596b..30968707 100644
--- a/test/services_test.rb
+++ b/test/services_test.rb
@@ -35,7 +35,7 @@ class ServicesTest < Test::Unit::TestCase
 
   def test_google_query_url_contains_bounds
     lookup = Geocoder::Lookup::Google.new
-    url = lookup.send(:query_url, Geocoder::Query.new(
+    url = lookup.query_url(Geocoder::Query.new(
       "Some Intersection",
       :bounds => [[40.0, -120.0], [39.0, -121.0]]
     ))
@@ -44,7 +44,7 @@ class ServicesTest < Test::Unit::TestCase
 
   def test_google_query_url_contains_region
     lookup = Geocoder::Lookup::Google.new
-    url = lookup.send(:query_url, Geocoder::Query.new(
+    url = lookup.query_url(Geocoder::Query.new(
       "Some Intersection",
       :region => "gb"
     ))
@@ -53,7 +53,7 @@ class ServicesTest < Test::Unit::TestCase
 
   def test_google_query_url_contains_components_when_given_as_string
     lookup = Geocoder::Lookup::Google.new
-    url = lookup.send(:query_url, Geocoder::Query.new(
+    url = lookup.query_url(Geocoder::Query.new(
       "Some Intersection",
       :components => "locality:ES"
     ))
@@ -63,7 +63,7 @@ class ServicesTest < Test::Unit::TestCase
 
   def test_google_query_url_contains_components_when_given_as_array
     lookup = Geocoder::Lookup::Google.new
-    url = lookup.send(:query_url, Geocoder::Query.new(
+    url = lookup.query_url(Geocoder::Query.new(
       "Some Intersection",
       :components => ["country:ES", "locality:ES"]
     ))
@@ -84,7 +84,7 @@ class ServicesTest < Test::Unit::TestCase
   def test_google_premier_query_url
     Geocoder.configure(: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, Geocoder::Query.new("Madison Square Garden, New York, NY"))
+      Geocoder::Lookup::GooglePremier.new.query_url(Geocoder::Query.new("Madison Square Garden, New York, NY"))
   end
 
 
@@ -205,7 +205,7 @@ class ServicesTest < Test::Unit::TestCase
     Geocoder.configure(:lookup => :nominatim, :nominatim => {:host => "local.com"})
     lookup = Geocoder::Lookup::Nominatim.new
     query = Geocoder::Query.new("Bluffton, SC")
-    assert_match %r(http://local\.com), lookup.send(:query_url, query)
+    assert_match %r(http://local\.com), lookup.query_url(query)
   end
 
   # --- MapQuest ---
@@ -214,7 +214,7 @@ class ServicesTest < Test::Unit::TestCase
     Geocoder.configure(:lookup => :mapquest, :api_key => "abc123")
     lookup = Geocoder::Lookup::Mapquest.new
     query = Geocoder::Query.new("Bluffton, SC")
-    res = lookup.send(:query_url, query)
+    res = lookup.query_url(query)
     assert_equal "http://www.mapquestapi.com/geocoding/v1/address?key=abc123&location=Bluffton%2C+SC",
       res
   end
-- 
GitLab