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

Partially revert "Update license for OpenStreetMap (#883)."

This reverts the parts of commit 350567f5
that are outside of the README and should not have been included.
parent 350567f5
No related branches found
No related tags found
No related merge requests found
......@@ -86,6 +86,15 @@ module Geocoder
@cache
end
##
# Array containing the protocols supported by the api.
# Should be set to [:http] if only HTTP is supported
# or [:https] if only HTTPS is supported.
#
def supported_protocols
[:http, :https]
end
private # -------------------------------------------------------------
##
......@@ -99,7 +108,6 @@ module Geocoder
# Object used to make HTTP requests.
#
def http_client
protocol = "http#{'s' if use_ssl?}"
proxy_name = "#{protocol}_proxy"
if proxy = configuration.send(proxy_name)
proxy_url = !!(proxy =~ /^#{protocol}/) ? proxy : protocol + '://' + proxy
......@@ -183,7 +191,7 @@ module Geocoder
JSON.parse(data)
end
rescue => err
raise_error(ResponseParseError.new(data)) or Geocoder.log(:warn, "Geocoding API's response was not valid JSON.")
raise_error(ResponseParseError.new(data)) or Geocoder.log(:warn, "Geocoding API's response was not valid JSON: #{data}")
end
##
......@@ -265,6 +273,7 @@ module Geocoder
def make_api_request(query)
timeout(configuration.timeout) do
uri = URI.parse(query_url(query))
Geocoder.log(:debug, "Geocoder: HTTP request being made for #{uri.to_s}")
http_client.start(uri.host, uri.port, use_ssl: use_ssl?) do |client|
req = Net::HTTP::Get.new(uri.request_uri, configuration.http_headers)
if configuration.basic_auth[:user] and configuration.basic_auth[:password]
......@@ -279,7 +288,13 @@ module Geocoder
end
def use_ssl?
configuration.use_https
if supported_protocols == [:https]
true
elsif supported_protocols == [:http]
false
else
configuration.use_https
end
end
def check_api_key_configuration!(query)
......
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