From a4a8d26003422c076516b7a1998bb121cfe42548 Mon Sep 17 00:00:00 2001 From: Jeff Fredrickson <jeff.fredrickson@gmail.com> Date: Wed, 25 Nov 2015 15:21:39 -0500 Subject: [PATCH] use new Telize endpoint --- lib/geocoder/lookups/telize.rb | 13 ++++++++++--- test/unit/lookup_test.rb | 6 ++++++ test/unit/lookups/telize_test.rb | 6 ------ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/geocoder/lookups/telize.rb b/lib/geocoder/lookups/telize.rb index 7ee025fb..89c29e88 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 45279ddd..1fba832a 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 01464e36..aa6e4dbe 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 -- GitLab