diff --git a/lib/geocoder/lookups/telize.rb b/lib/geocoder/lookups/telize.rb index 7ee025fb001f470fdbfd94762b410464ffcbf9a9..89c29e8863c26fc78a87e32e5ce93f28b8fba884 100644 --- a/lib/geocoder/lookups/telize.rb +++ b/lib/geocoder/lookups/telize.rb @@ -8,13 +8,16 @@ module Geocoder::Lookup "Telize" end + def required_api_key_parts + ["key"] + end + def query_url(query) - "#{protocol}://www.telize.com/geoip/#{query.sanitized_text}" + "#{protocol}://telize-v1.p.mashape.com/geoip/#{query.sanitized_text}?mashape-key=#{api_key}" end - # currently doesn't support HTTPS def supported_protocols - [:http] + [:https] end private # --------------------------------------------------------------- @@ -36,5 +39,9 @@ module Geocoder::Lookup def reserved_result(ip) {"message" => "Input string is not a valid IP address", "code" => 401} end + + def api_key + configuration.api_key + end end end diff --git a/test/unit/lookup_test.rb b/test/unit/lookup_test.rb index 45279ddd383923cfe3e20cee0beb3bf336d0f44c..1fba832a3e2103eb42cee90f70e4c78736a6f440 100644 --- a/test/unit/lookup_test.rb +++ b/test/unit/lookup_test.rb @@ -138,6 +138,12 @@ class LookupTest < GeocoderTestCase assert_match "showpostal=1", g.query_url(Geocoder::Query.new("Madison Square Garden, New York, NY 10001, United States")) end + def test_telize_api_key + Geocoder.configure(:api_key => "MY_KEY") + g = Geocoder::Lookup::Telize.new + assert_match "mashape-key=MY_KEY", g.query_url(Geocoder::Query.new("232.65.123.94")) + end + def test_raises_configuration_error_on_missing_key [:bing, :baidu].each do |l| assert_raises Geocoder::ConfigurationError do diff --git a/test/unit/lookups/telize_test.rb b/test/unit/lookups/telize_test.rb index 01464e366b98d5ef80498a1a9e90ec9df860a5d4..aa6e4dbe54e9b2065742aadab8d0f5a9a758f88f 100644 --- a/test/unit/lookups/telize_test.rb +++ b/test/unit/lookups/telize_test.rb @@ -26,10 +26,4 @@ class TelizeTest < GeocoderTestCase results = Geocoder.search("555.555.555.555", ip_address: true) assert_equal 0, results.length end - - def test_uses_http_even_if_use_https_true - Geocoder.configure(use_https: true) - result = Geocoder.search("74.200.247.59").first - assert result.is_a?(Geocoder::Result::Telize) - end end