From f9647facc9d3f0ef912f8bc96484dc39a5801da1 Mon Sep 17 00:00:00 2001 From: Alex Reisner <alex@alexreisner.com> Date: Mon, 27 Jul 2015 12:31:35 -0400 Subject: [PATCH] Partially revert "Update license for OpenStreetMap (#883)." This reverts the parts of commit 350567f548b6f74d01ef5f3b93c4b32e9c1dd573 that are outside of the README and should not have been included. --- lib/geocoder/lookups/base.rb | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb index 7a65d66a..c6332162 100644 --- a/lib/geocoder/lookups/base.rb +++ b/lib/geocoder/lookups/base.rb @@ -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) -- GitLab