diff --git a/lib/geocoder/lookups/mapquest.rb b/lib/geocoder/lookups/mapquest.rb index e9df075a149f23c9669bba7946eb6b2f2b730343..1ce5e4033f257bd0a3126ef021d371c7a9304bd4 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 ba7cd96a578b524360cb25e003a6786e4f4d3cc3..70b067b6d1afe3d89bef474bdb066fc98e1527b8 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