Skip to content
Snippets Groups Projects
Commit 8164a931 authored by Scott Vesely's avatar Scott Vesely Committed by Alex Reisner
Browse files

Add :use_https config option.

parent 568a2363
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,10 @@ module Geocoder
# cache object (must respond to #[], #[]=, and #keys
def self.cache_prefix; @@cache_prefix; end
def self.cache_prefix=(obj); @@cache_prefix = obj; end
# use HTTPS for lookup requests? (true or false)
def self.use_https; @@use_https; end
def self.use_https=(obj); @@use_https = obj; end
end
end
......@@ -33,3 +37,4 @@ Geocoder::Configuration.language = :en
Geocoder::Configuration.yahoo_appid = nil
Geocoder::Configuration.cache = nil
Geocoder::Configuration.cache_prefix = "geocoder:"
Geocoder::Configuration.use_https = false
......@@ -78,6 +78,14 @@ module Geocoder
end
end
##
# Protocol to use for communication with geocoding services.
# Set in configuration but not available for every service.
#
def protocol
"http" + (Geocoder::Configuration.use_https ? "s" : "")
end
##
# Fetches a raw search result (JSON string).
#
......
......@@ -25,7 +25,7 @@ module Geocoder::Lookup
:sensor => "false",
:language => Geocoder::Configuration.language
}
"http://maps.google.com/maps/api/geocode/json?" + hash_to_query(params)
"#{protocol}://maps.google.com/maps/api/geocode/json?" + hash_to_query(params)
end
end
end
......
......@@ -4,6 +4,7 @@ class GeocoderTest < Test::Unit::TestCase
def setup
Geocoder::Configuration.lookup = :google
Geocoder::Configuration.use_https = false
end
......@@ -53,6 +54,17 @@ class GeocoderTest < Test::Unit::TestCase
$VERBOSE = orig
end
def test_uses_https_for_secure_query
Geocoder::Configuration.use_https = true
g = Geocoder::Lookup::Google.new
assert_match /^https:/, g.send(:query_url, {:a => 1, :b => 2})
end
def test_uses_http_by_default
g = Geocoder::Lookup::Google.new
assert_match /^http:/, g.send(:query_url, {:a => 1, :b => 2})
end
def test_distance_to_returns_float
v = Venue.new(*venue_params(:msg))
v.latitude, v.longitude = [40.750354, -73.993371]
......
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