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

Merge pull request #864 from matthewrudy/supported-protocols

Add `supported_protocols` to lookups.
parents 4f8b5390 a09bce79
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,11 @@ module Geocoder::Lookup ...@@ -16,6 +16,11 @@ module Geocoder::Lookup
"http://api.map.baidu.com/geocoder/v2/?" + url_query_string(query) "http://api.map.baidu.com/geocoder/v2/?" + url_query_string(query)
end end
# HTTP only
def supported_protocols
[:http]
end
private # --------------------------------------------------------------- private # ---------------------------------------------------------------
def results(query, reverse = false) def results(query, reverse = false)
...@@ -52,4 +57,3 @@ module Geocoder::Lookup ...@@ -52,4 +57,3 @@ module Geocoder::Lookup
end end
end end
...@@ -16,6 +16,11 @@ module Geocoder::Lookup ...@@ -16,6 +16,11 @@ module Geocoder::Lookup
"http://api.map.baidu.com/location/ip?" + url_query_string(query) "http://api.map.baidu.com/location/ip?" + url_query_string(query)
end end
# HTTP only
def supported_protocols
[:http]
end
private # --------------------------------------------------------------- private # ---------------------------------------------------------------
def results(query, reverse = false) def results(query, reverse = false)
......
...@@ -86,6 +86,15 @@ module Geocoder ...@@ -86,6 +86,15 @@ module Geocoder
@cache @cache
end 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 # ------------------------------------------------------------- private # -------------------------------------------------------------
## ##
...@@ -279,6 +288,9 @@ module Geocoder ...@@ -279,6 +288,9 @@ module Geocoder
end end
def use_ssl? def use_ssl?
return true if supported_protocols == [:https]
return false if supported_protocols == [:http]
configuration.use_https configuration.use_https
end end
......
...@@ -12,8 +12,8 @@ module Geocoder ...@@ -12,8 +12,8 @@ module Geocoder
["key"] ["key"]
end end
def use_ssl? def supported_protocols
true [:https]
end end
def query_url(query) def query_url(query)
......
...@@ -8,10 +8,10 @@ module Geocoder::Lookup ...@@ -8,10 +8,10 @@ module Geocoder::Lookup
"MaxMind GeoIP2" "MaxMind GeoIP2"
end end
def use_ssl? # Maxmind's GeoIP2 Precision Services only supports HTTPS,
# Maxmind's GeoIP2 Precision Services only supports HTTPS, # otherwise a `404 Not Found` HTTP response will be returned
# otherwise a `404 Not Found` HTTP response will be returned def supported_protocols
true [:https]
end end
def query_url(query) def query_url(query)
......
...@@ -16,12 +16,13 @@ module Geocoder::Lookup ...@@ -16,12 +16,13 @@ module Geocoder::Lookup
"#{protocol}://api.smartystreets.com/#{path}?#{url_query_string(query)}" "#{protocol}://api.smartystreets.com/#{path}?#{url_query_string(query)}"
end end
private # --------------------------------------------------------------- # required by API as of 26 March 2015
def supported_protocols
def protocol [:https]
"https" # required by API as of 26 March 2015
end end
private # ---------------------------------------------------------------
def zipcode_only?(query) def zipcode_only?(query)
!query.text.is_a?(Array) and query.to_s.strip =~ /\A\d{5}(-\d{4})?\Z/ !query.text.is_a?(Array) and query.to_s.strip =~ /\A\d{5}(-\d{4})?\Z/
end end
......
...@@ -9,16 +9,16 @@ module Geocoder::Lookup ...@@ -9,16 +9,16 @@ module Geocoder::Lookup
end end
def query_url(query) def query_url(query)
#currently doesn't support HTTPS
"http://www.telize.com/geoip/#{query.sanitized_text}" "http://www.telize.com/geoip/#{query.sanitized_text}"
end end
private # --------------------------------------------------------------- # currently doesn't support HTTPS
def supported_protocols
def use_ssl? [:http]
false
end end
private # ---------------------------------------------------------------
def results(query) def results(query)
# don't look up a loopback address, just return the stored result # don't look up a loopback address, just return the stored result
return [reserved_result(query.text)] if query.loopback_ip_address? return [reserved_result(query.text)] if query.loopback_ip_address?
......
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