Skip to content
Snippets Groups Projects
Commit 26643bee authored by Alex Reisner's avatar Alex Reisner
Browse files

Don't require ActiveSupport's Object#to_query.

parent a5ec2625
No related branches found
No related tags found
No related merge requests found
......@@ -88,6 +88,14 @@ module Geocoder
Net::HTTP.get_response(URI.parse(url)).body
end
end
##
# Simulate ActiveSupport's Object#to_query.
#
def hash_to_query(hash)
require 'cgi' unless defined?(CGI) && defined?(CGI.escape)
hash.collect{ |p| p.map{ |i| CGI.escape i.to_s } * '=' }.sort * '&'
end
end
end
end
......@@ -24,7 +24,7 @@ module Geocoder::Lookup
(reverse ? :latlng : :address) => query,
:sensor => "false"
}
"http://maps.google.com/maps/api/geocode/json?" + params.to_query
"http://maps.google.com/maps/api/geocode/json?" + hash_to_query(params)
end
end
end
......
......@@ -22,7 +22,7 @@ module Geocoder::Lookup
:gflags => "AC#{'R' if reverse}",
:appid => Geocoder::Configuration.yahoo_appid
}
"http://where.yahooapis.com/geocode?" + params.to_query
"http://where.yahooapis.com/geocode?" + hash_to_query(params)
end
end
end
......
......@@ -110,6 +110,11 @@ class GeocoderTest < Test::Unit::TestCase
assert !Geocoder.send(:blank_query?, "a")
end
def test_hash_to_query
g = Geocoder::Lookup::Google.new
assert_equal "a=1&b=2", g.send(:hash_to_query, {:a => 1, :b => 2})
end
private # ------------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment