From 85f0f9f88242dd24b758b517676291c65556daea Mon Sep 17 00:00:00 2001
From: Jed Schneider <jed.schneider@modeset.com>
Date: Tue, 16 Oct 2012 16:24:55 -0400
Subject: [PATCH] reverting to CGI and letting base class do the work

---
 lib/geocoder/lookups/mapquest.rb | 10 ++--------
 test/services_test.rb            |  8 ++------
 2 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/lib/geocoder/lookups/mapquest.rb b/lib/geocoder/lookups/mapquest.rb
index e9df075a..1ce5e403 100644
--- a/lib/geocoder/lookups/mapquest.rb
+++ b/lib/geocoder/lookups/mapquest.rb
@@ -1,4 +1,4 @@
-require 'uri'
+require 'cgi'
 require 'geocoder/lookups/base'
 require "geocoder/results/mapquest"
 
@@ -22,7 +22,7 @@ module Geocoder::Lookup
       key = Geocoder::Configuration.api_key
       params = { :location => query.sanitized_text }
       if key
-        params[:key] = URI.unescape(key)
+        params[:key] = CGI.unescape(key)
       end
       super.merge(params)
     end
@@ -32,11 +32,5 @@ module Geocoder::Lookup
       doc["results"][0]['locations']
     end
 
-    def hash_to_query(hash)
-      require 'uri' unless defined?(URI) && defined?(URI.escape)
-      hash.collect{ |p|
-        p[1].nil? ? nil : p.map{ |i| URI.escape i.to_s } * '='
-      }.compact.sort * '&'
-    end
   end
 end
diff --git a/test/services_test.rb b/test/services_test.rb
index ba7cd96a..70b067b6 100644
--- a/test/services_test.rb
+++ b/test/services_test.rb
@@ -9,11 +9,7 @@ class ServicesTest < Test::Unit::TestCase
       next if l == :google_premier # TODO: need to set keys to test
       next if l == :freegeoip # does not use query string
       # mapquest seems to like URI instead of CGI escaping
-      regex = if l == :mapquest
-        /one_in_the_hand=two%20in%20the%20bush/
-      else
-        /one_in_the_hand=two\+in\+the\+bush/
-      end
+      regex = /one_in_the_hand=two\+in\+the\+bush/
       url = Geocoder::Lookup.get(l).send(:query_url, Geocoder::Query.new(
         "test", :params => {:one_in_the_hand => "two in the bush"}
       ))
@@ -181,7 +177,7 @@ class ServicesTest < Test::Unit::TestCase
     lookup = Geocoder::Lookup::Mapquest.new
     query = Geocoder::Query.new("Bluffton, SC")
     res = lookup.send(:query_url, query)
-    assert_equal "http://www.mapquestapi.com/geocoding/v1/address?key=abc123&location=Bluffton,%20SC",
+    assert_equal "http://www.mapquestapi.com/geocoding/v1/address?key=abc123&location=Bluffton%2C+SC",
       res
   end
 
-- 
GitLab