diff --git a/lib/geocoder/lookups/baidu.rb b/lib/geocoder/lookups/baidu.rb index b69cd7545b02c0fd3581fd40f227ad5151ffe8a8..f2d499a69cd6618b7fd677658e67c5a9a764d0c8 100644 --- a/lib/geocoder/lookups/baidu.rb +++ b/lib/geocoder/lookups/baidu.rb @@ -16,6 +16,11 @@ module Geocoder::Lookup "http://api.map.baidu.com/geocoder/v2/?" + url_query_string(query) end + # HTTP only + def supported_protocols + [:http] + end + private # --------------------------------------------------------------- def results(query, reverse = false) @@ -52,4 +57,3 @@ module Geocoder::Lookup end end - diff --git a/lib/geocoder/lookups/baidu_ip.rb b/lib/geocoder/lookups/baidu_ip.rb index 53193506c9f6365e1ced9078f2fa245914ed898f..8ae9a527ab806c3f8287e8a11cb95d7dbb62cbc2 100644 --- a/lib/geocoder/lookups/baidu_ip.rb +++ b/lib/geocoder/lookups/baidu_ip.rb @@ -16,6 +16,11 @@ module Geocoder::Lookup "http://api.map.baidu.com/location/ip?" + url_query_string(query) end + # HTTP only + def supported_protocols + [:http] + end + private # --------------------------------------------------------------- def results(query, reverse = false) diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb index 5ac00379c33f2c1e40d60729c751c2cbdbf18015..11ea78b4f2aa31ec457464e69ee22b1f8b95870b 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 # ------------------------------------------------------------- ## @@ -279,6 +288,9 @@ module Geocoder end def use_ssl? + return true if supported_protocols == [:https] + return false if supported_protocols == [:http] + configuration.use_https end diff --git a/lib/geocoder/lookups/google_places_details.rb b/lib/geocoder/lookups/google_places_details.rb index 38b3bb84c5ecd79b552d6d1f7c572d2c4807f1df..c4825f81e7387fdca22a83966fcc433c4fc1dc06 100644 --- a/lib/geocoder/lookups/google_places_details.rb +++ b/lib/geocoder/lookups/google_places_details.rb @@ -12,8 +12,8 @@ module Geocoder ["key"] end - def use_ssl? - true + def supported_protocols + [:https] end def query_url(query) diff --git a/lib/geocoder/lookups/maxmind_geoip2.rb b/lib/geocoder/lookups/maxmind_geoip2.rb index 761be9b66bd0b44ed3851e8fd65bcd6d2c73224a..8ada99d3db89c4d3665d2bb626c8b906a9ff1b40 100644 --- a/lib/geocoder/lookups/maxmind_geoip2.rb +++ b/lib/geocoder/lookups/maxmind_geoip2.rb @@ -8,10 +8,10 @@ module Geocoder::Lookup "MaxMind GeoIP2" end - def use_ssl? - # Maxmind's GeoIP2 Precision Services only supports HTTPS, - # otherwise a `404 Not Found` HTTP response will be returned - true + # Maxmind's GeoIP2 Precision Services only supports HTTPS, + # otherwise a `404 Not Found` HTTP response will be returned + def supported_protocols + [:https] end def query_url(query) diff --git a/lib/geocoder/lookups/smarty_streets.rb b/lib/geocoder/lookups/smarty_streets.rb index 2aebf07a1c71b6260af98846a39c24604883f783..92065d61196a8c8bb5de88c5f47c947842cf2938 100644 --- a/lib/geocoder/lookups/smarty_streets.rb +++ b/lib/geocoder/lookups/smarty_streets.rb @@ -16,12 +16,13 @@ module Geocoder::Lookup "#{protocol}://api.smartystreets.com/#{path}?#{url_query_string(query)}" end - private # --------------------------------------------------------------- - - def protocol - "https" # required by API as of 26 March 2015 + # required by API as of 26 March 2015 + def supported_protocols + [:https] end + private # --------------------------------------------------------------- + def zipcode_only?(query) !query.text.is_a?(Array) and query.to_s.strip =~ /\A\d{5}(-\d{4})?\Z/ end diff --git a/lib/geocoder/lookups/telize.rb b/lib/geocoder/lookups/telize.rb index 43b1de404968f3120dea1258246338bf51e5ee8a..85fb668d6ab5088df5575f7bdf4da09ede5a3548 100644 --- a/lib/geocoder/lookups/telize.rb +++ b/lib/geocoder/lookups/telize.rb @@ -9,16 +9,16 @@ module Geocoder::Lookup end def query_url(query) - #currently doesn't support HTTPS "http://www.telize.com/geoip/#{query.sanitized_text}" end - private # --------------------------------------------------------------- - - def use_ssl? - false + # currently doesn't support HTTPS + def supported_protocols + [:http] end + private # --------------------------------------------------------------- + def results(query) # don't look up a loopback address, just return the stored result return [reserved_result(query.text)] if query.loopback_ip_address?