lib/geocoder/lookups/base.rb in geocoder-1.2.3 vs lib/geocoder/lookups/base.rb in geocoder-1.2.4

- old
+ new

@@ -97,11 +97,11 @@ ## # Object used to make HTTP requests. # def http_client - protocol = "http#{'s' if configuration.use_https}" + protocol = "http#{'s' if use_ssl?}" proxy_name = "#{protocol}_proxy" if proxy = configuration.send(proxy_name) proxy_url = !!(proxy =~ /^#{protocol}/) ? proxy : protocol + '://' + proxy begin uri = URI.parse(proxy_url) @@ -196,11 +196,11 @@ ## # Protocol to use for communication with geocoding services. # Set in configuration but not available for every service. # def protocol - "http" + (configuration.use_https ? "s" : "") + "http" + (use_ssl? ? "s" : "") end def valid_response?(response) (200..399).include?(response.code.to_i) end @@ -247,10 +247,13 @@ raise_error(Geocoder::RequestDenied) || warn("Geocoding API error: 401 Unauthorized") elsif response.code.to_i == 402 raise_error(Geocoder::OverQueryLimitError) || warn("Geocoding API error: 402 Payment Required") + elsif response.code.to_i == 429 + raise_error(Geocoder::OverQueryLimitError) || + warn("Geocoding API error: 429 Too Many Requests") end end ## # Make an HTTP(S) request to a geocoding API and @@ -260,15 +263,19 @@ timeout(configuration.timeout) do uri = URI.parse(query_url(query)) args = [uri.host, uri.port] args = args.push(uri.user, uri.password) unless uri.user.nil? or uri.password.nil? opts = {} - opts[:use_ssl] = true if configuration.use_https + opts[:use_ssl] = use_ssl? http_client.start(*args, opts) do |client| client.get(uri.request_uri, configuration.http_headers) end end + end + + def use_ssl? + configuration.use_https end def check_api_key_configuration!(query) key_parts = query.lookup.required_api_key_parts if key_parts.size > Array(configuration.api_key).size