diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fa46df..d6bb4ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.15.0 + +* Removed support for no longer accessible geocoder.us + ## 1.14.0 * Introduced NoSuchGeocoderError. If you try call a geocoder like :bogus that doesn't exist, an error will be returned. diff --git a/README.markdown b/README.markdown index 08c3673..fe27395 100644 --- a/README.markdown +++ b/README.markdown @@ -59,7 +59,6 @@ Combine this gem with the [geokit-rails](http://github.com/geokit/geokit-rails) ### IP address geocoders * IP - geocodes an IP address using hostip.info's web service. * Geoplugin.net -- another IP address geocoder -* Geobytes * RIPE * MaxMind * Ipstack @@ -150,13 +149,6 @@ If you're using this gem by itself, here are the configuration options: # You define these keys with a Hash as follows: #Geokit::Geocoders::google = { 'rubyonrails.org' => 'RUBY_ON_RAILS_API_KEY', 'ruby-docs.org' => 'RUBY_DOCS_API_KEY' } - # This is your username and password for geocoder.us. - # To use the free service, the value can be set to nil or false. For - # usage tied to an account, the value should be set to username:password. - # See http://geocoder.us - # and http://geocoder.us/user/signup - Geokit::Geocoders::UsGeocoder.key = 'username:password' - # This is your authorization key for geocoder.ca. # To use the free service, the value can be set to nil or false. For # usage tied to an account, set the value to the key obtained from @@ -177,9 +169,8 @@ If you're using this gem by itself, here are the configuration options: # This is your api key for ip-api.com. # For the free version (with rate limits), leave api_key unset. - # For the pro version, api_key must be set # See https://ip-api.com/ - Geokit::Geocoders::IpApiGeocoder.api_key = 'API_KEY' + Geokit::Geocoders::IpApiGeocoder.key = '' # Most other geocoders need either no setup or a key Geokit::Geocoders::BingGeocoder.key = '' @@ -210,7 +201,7 @@ If you're using this gem by itself, here are the configuration options: # The IP provider order. # - # Valid symbols are :ipstack, :geo_plugin, :geobytes, :ip, and :ripe. + # Valid symbols are :ipstack, :geo_plugin, :ip, and :ripe. # # As before, make sure you read up on relevant Terms of Use for each. # Geokit::Geocoders::ip_provider_order = [:external,:geo_plugin,:ip] diff --git a/lib/geokit/geocoders/ip_api_geocoder.rb b/lib/geokit/geocoders/ip_api_geocoder.rb index c3933d1..ed74101 100644 --- a/lib/geokit/geocoders/ip_api_geocoder.rb +++ b/lib/geokit/geocoders/ip_api_geocoder.rb @@ -2,7 +2,7 @@ module Geokit module Geocoders # Provides geocoding based upon an IP address. The underlying web service is ip-api.com class IpApiGeocoder < BaseIpGeocoder - config :api_key + config :key private @@ -11,10 +11,10 @@ def self.do_geocode(ip, _=nil) end def self.submit_url(ip) - if api_key.nil? + if key.nil? "http://ip-api.com/json/#{ip}" else - "http://pro.ip-api.com/json/#{ip}?key=#{api_key}" + "http://pro.ip-api.com/json/#{ip}?key=#{key}" end end diff --git a/lib/geokit/geocoders/us_geocoder.rb b/lib/geokit/geocoders/us_geocoder.rb deleted file mode 100644 index 59eb4f6..0000000 --- a/lib/geokit/geocoders/us_geocoder.rb +++ /dev/null @@ -1,37 +0,0 @@ -# Geocoder Us geocoder implementation. Requires the Geokit::Geocoders::GEOCODER_US variable to -# contain true or false based upon whether authentication is to occur. Conforms to the -# interface set by the Geocoder class. -module Geokit - module Geocoders - class UsGeocoder < Geocoder - config :key - - private - - def self.do_geocode(address, _=nil) - process :csv, submit_url(address) - end - - def self.submit_url(address) - address_str = address.is_a?(GeoLoc) ? address.to_geocodeable_s : address - query = (address_str =~ /^\d{5}(?:-\d{4})?$/ ? 'zip' : 'address') + "=#{Geokit::Inflector.url_escape(address_str)}" - base = key ? "http://#{key}@geocoder.us/member" : 'http://geocoder.us' - "#{base}/service/csv/geocode?#{query}" - end - - def self.parse_csv(array) - loc = GeoLoc.new - if array.length == 5 - loc.lat, loc.lng, loc.city, loc.state, loc.zip = array - loc.country_code = 'US' - loc.success = true - elsif array.length == 6 - loc.lat, loc.lng, loc.street_address, loc.city, loc.state, loc.zip = array - loc.country_code = 'US' - loc.success = true - end - loc - end - end - end -end diff --git a/lib/geokit/version.rb b/lib/geokit/version.rb index c29f21d..d1afb28 100644 --- a/lib/geokit/version.rb +++ b/lib/geokit/version.rb @@ -1,3 +1,3 @@ module Geokit - VERSION = '1.14.0' + VERSION = '1.15.0' end diff --git a/test/test_ip_api_geocoder.rb b/test/test_ip_api_geocoder.rb index c5c9ea3..e21ba1a 100644 --- a/test/test_ip_api_geocoder.rb +++ b/test/test_ip_api_geocoder.rb @@ -22,7 +22,7 @@ def test_ip_api_geocode end def test_ip_api_pro_geocode - geocoder_class.api_key = 'some_api_key' + geocoder_class.key = 'some_api_key' url = "http://pro.ip-api.com/json/#{@ip}?key=some_api_key" res = geocode(@ip, :ip_api_pro_geocode) assert_url url diff --git a/test/test_us_geocoder.rb b/test/test_us_geocoder.rb deleted file mode 100644 index bd3d860..0000000 --- a/test/test_us_geocoder.rb +++ /dev/null @@ -1,55 +0,0 @@ -require File.join(File.dirname(__FILE__), 'helper') - -class UsGeocoderTest < BaseGeocoderTest #:nodoc: all - GEOCODER_US_FULL = '37.792528,-122.393981,100 Spear St,San Francisco,CA,94105' - - def setup - geocoder_class.key = nil - super - @us_full_hash = {city: 'San Francisco', state: 'CA'} - @us_full_loc = Geokit::GeoLoc.new(@us_full_hash) - @base_url = 'http://geocoder.us/service/csv/geocode' - end - - def test_geocoder_us - response = MockSuccess.new - response.expects(:body).returns(GEOCODER_US_FULL) - url = "#{@base_url}?address=#{escape(@address)}" - geocoder_class.expects(:call_geocoder_service).with(url).returns(response) - verify(geocode(@address)) - end - - def test_geocoder_with_geo_loc - response = MockSuccess.new - response.expects(:body).returns(GEOCODER_US_FULL) - url = "#{@base_url}?address=#{escape(@address)}" - geocoder_class.expects(:call_geocoder_service).with(url).returns(response) - verify(geocode(@us_full_loc)) - end - - def test_service_unavailable - response = MockFailure.new - url = "#{@base_url}?address=#{escape(@address)}" - geocoder_class.expects(:call_geocoder_service).with(url).returns(response) - assert !geocode(@us_full_loc).success - end - - def test_all_method - response = MockSuccess.new - response.expects(:body).returns(GEOCODER_US_FULL) - url = "#{@base_url}?address=#{escape(@address)}" - geocoder_class.expects(:call_geocoder_service).with(url).returns(response) - res = geocode(@address) - assert_equal 1, res.all.size - end - - private - - def verify(location) - assert_equal 'CA', location.state - assert_equal 'San Francisco', location.city - assert_equal '37.792528,-122.393981', location.ll - assert location.is_us? - assert_equal '100 Spear St, San Francisco, CA, 94105, US', location.full_address # slightly different from yahoo - end -end