diff --git a/README.md b/README.md index fd62749022aa57329280640258749bbc40ff4782..7405f9e8864ce027e8d86b72d46baac9c18d651b 100644 --- a/README.md +++ b/README.md @@ -709,11 +709,11 @@ You can replace `city` with `country` in any of the above tasks, generators, and * **Limitations**: Only good for non-commercial use. For commercial usage please check http://developer.baidu.com/map/question.htm#qa0013 * **Notes**: To use Baidu set `Geocoder.configure(:lookup => :baidu_ip, :api_key => "your_api_key")`. -#### GeoLite2 (`:geolite2`) - EXPERIMENTAL +#### GeoLite2 (`:geoip2`) - EXPERIMENTAL This lookup provides methods for geocoding IP addresses without making a call to a remote API (improves speed and availability). It works, but support is new and should not be considered production-ready. Please [report any bugs](https://github.com/alexreisner/geocoder/issues) you encounter. -* **API key**: none (requires the free GeoLite2 City or Country MaxMind DB binary database which can be downloaded from [MaxMind](http://dev.maxmind.com/geoip/geoip2/geolite2/)) +* **API key**: none (requires the free GeoLite2 City or Country MaxMind DB binary database which can be downloaded from [MaxMind](http://dev.maxmind.com/geoip/geoip2/geoip2/)) * **Quota**: none * **Region**: world * **SSL support**: N/A @@ -726,11 +726,11 @@ This lookup provides methods for geocoding IP addresses without making a call to **To use the binary database** you must add either the *[hive_geoip2](https://rubygems.org/gems/hive_geoip2)* gem (native extension that relies on libmaxminddb) or the *[maxminddb](http://rubygems.org/gems/maxminddb)* gem (pure Ruby implementation) to your Gemfile or have it installed in your system. Then specify which gem to use with the `:maxminddb_gem` configuration option, and specify the path of the MaxMind database in your configuration. The pure Ruby gem (maxminddb) will be used as default. For example to use the maxminddb gem: - Geocoder.configure(ip_lookup: :geolite2, geolite2: { file: File.join('folder', 'GeoLite2-City.mmdb') }) + Geocoder.configure(ip_lookup: :geoip2, geoip2: { file: File.join('folder', 'GeoLite2-City.mmdb') }) To use the hive_geoip2 gem: - Geocoder.configure(ip_lookup: :geolite2, geolite2: { maxminddb_gem: 'hive_geoip2', file: File.join('folder', 'GeoLite2-City.mmdb') }) + Geocoder.configure(ip_lookup: :geoip2, geoip2: { maxminddb_gem: 'hive_geoip2', file: File.join('folder', 'GeoLite2-City.mmdb') }) Caching ------- diff --git a/lib/geocoder/lookup.rb b/lib/geocoder/lookup.rb index 3a6e7a782b8bba25bdf4f4516dc99d4bd3f9a3f8..651cb5b83ce6e9cdb0facf6f3310906db32fd323 100644 --- a/lib/geocoder/lookup.rb +++ b/lib/geocoder/lookup.rb @@ -52,7 +52,7 @@ module Geocoder [ :baidu_ip, :freegeoip, - :geolite2, + :geoip2, :maxmind, :maxmind_local, :telize, diff --git a/lib/geocoder/lookups/geolite2.rb b/lib/geocoder/lookups/geoip2.rb similarity index 81% rename from lib/geocoder/lookups/geolite2.rb rename to lib/geocoder/lookups/geoip2.rb index 5733d2be0fcb6954206659458c875c7cc4b7422a..acfdfe40c2c4ef01eb97400b2ce556d871925405 100644 --- a/lib/geocoder/lookups/geolite2.rb +++ b/lib/geocoder/lookups/geoip2.rb @@ -1,23 +1,23 @@ require 'geocoder/lookups/base' -require 'geocoder/results/geolite2' +require 'geocoder/results/geoip2' module Geocoder module Lookup - class Geolite2 < Base + class Geoip2 < Base def initialize unless configuration[:file].nil? begin @gem_name = configuration[:maxminddb_gem] || 'maxminddb' require @gem_name rescue LoadError - raise "Could not load Maxmind DB dependency. To use GeoLite2 lookup you must add the #{@gem_name} gem to your Gemfile or have it installed in your system." + raise "Could not load Maxmind DB dependency. To use the GeoIP2 lookup you must add the #{@gem_name} gem to your Gemfile or have it installed in your system." end end super end def name - 'GeoLite2' + 'GeoIP2' end def required_api_key_parts diff --git a/lib/geocoder/results/geolite2.rb b/lib/geocoder/results/geoip2.rb similarity index 98% rename from lib/geocoder/results/geolite2.rb rename to lib/geocoder/results/geoip2.rb index 3f3d027ce468b06b885556073fe5f2723f858082..928514c44651368a475f28bf500c7624cabef505 100644 --- a/lib/geocoder/results/geolite2.rb +++ b/lib/geocoder/results/geoip2.rb @@ -2,7 +2,7 @@ require 'geocoder/results/base' module Geocoder module Result - class Geolite2 < Base + class Geoip2 < Base def address(format = :full) s = state.to_s == '' ? '' : ", #{state_code}" "#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, '') diff --git a/test/test_helper.rb b/test/test_helper.rb index b447cf21b097383e5d626d597e688d262b1ac533..bcd31d215297a51bbd6087cf8a2adba8ecb3f273 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -150,7 +150,7 @@ module Geocoder end end - class Geolite2 + class Geoip2 private remove_method(:results) @@ -165,7 +165,7 @@ module Geocoder end def default_fixture_filename - 'geolite2_74_200_247_59' + 'geoip2_74_200_247_59' end end diff --git a/test/unit/cache_test.rb b/test/unit/cache_test.rb index 6ad4a11e6457beae4b317a1c7e74a692b807bce4..43fa9c2fb8a95ff9ef08d14e8a12ce107ec98b55 100644 --- a/test/unit/cache_test.rb +++ b/test/unit/cache_test.rb @@ -7,7 +7,7 @@ class CacheTest < GeocoderTestCase def test_second_occurrence_of_request_is_cache_hit Geocoder.configure(:cache => {}) Geocoder::Lookup.all_services_except_test.each do |l| - next if l == :maxmind_local || l == :geolite2 # local, does not use cache + next if l == :maxmind_local || l == :geoip2 # local, does not use cache Geocoder.configure(:lookup => l) set_api_key!(l) results = Geocoder.search("Madison Square Garden") diff --git a/test/unit/error_handling_test.rb b/test/unit/error_handling_test.rb index 63d6346159fa5b0374107ed5b365371fddbf7158..493d0ba0e937c21f9526bb14849df04a624123f1 100644 --- a/test/unit/error_handling_test.rb +++ b/test/unit/error_handling_test.rb @@ -21,7 +21,7 @@ class ErrorHandlingTest < GeocoderTestCase def test_always_raise_timeout_error Geocoder.configure(:always_raise => [TimeoutError]) Geocoder::Lookup.all_services_except_test.each do |l| - next if l == :maxmind_local || l == :geolite2 # local, does not use cache + next if l == :maxmind_local || l == :geoip2 # local, does not use cache lookup = Geocoder::Lookup.get(l) set_api_key!(l) assert_raises TimeoutError do @@ -33,7 +33,7 @@ class ErrorHandlingTest < GeocoderTestCase def test_always_raise_socket_error Geocoder.configure(:always_raise => [SocketError]) Geocoder::Lookup.all_services_except_test.each do |l| - next if l == :maxmind_local || l == :geolite2 # local, does not use cache + next if l == :maxmind_local || l == :geoip2 # local, does not use cache lookup = Geocoder::Lookup.get(l) set_api_key!(l) assert_raises SocketError do @@ -45,7 +45,7 @@ class ErrorHandlingTest < GeocoderTestCase def test_always_raise_connection_refused_error Geocoder.configure(:always_raise => [Errno::ECONNREFUSED]) Geocoder::Lookup.all_services_except_test.each do |l| - next if l == :maxmind_local || l == :geolite2 # local, does not use cache + next if l == :maxmind_local || l == :geoip2 # local, does not use cache lookup = Geocoder::Lookup.get(l) set_api_key!(l) assert_raises Errno::ECONNREFUSED do diff --git a/test/unit/lookup_test.rb b/test/unit/lookup_test.rb index 4b36713f94432427a8d9cad3ca5699181077589e..489d5db37b00b126e0f3cf5ebb6eed729594e332 100644 --- a/test/unit/lookup_test.rb +++ b/test/unit/lookup_test.rb @@ -23,7 +23,7 @@ class LookupTest < GeocoderTestCase def test_query_url_contains_values_in_params_hash Geocoder::Lookup.all_services_except_test.each do |l| - next if [:freegeoip, :maxmind_local, :telize, :pointpin, :geolite2].include? l # does not use query string + next if [:freegeoip, :maxmind_local, :telize, :pointpin, :geoip2].include? l # does not use query string set_api_key!(l) url = Geocoder::Lookup.get(l).query_url(Geocoder::Query.new( "test", :params => {:one_in_the_hand => "two in the bush"} diff --git a/test/unit/lookups/geolite2_test.rb b/test/unit/lookups/geoip2_test.rb similarity index 88% rename from test/unit/lookups/geolite2_test.rb rename to test/unit/lookups/geoip2_test.rb index ac9267aaaa3302d95c92c8c3316222fd4a8f3ef7..3345c81a7b22ee8365d277c98932b3c93f8b1fa4 100644 --- a/test/unit/lookups/geolite2_test.rb +++ b/test/unit/lookups/geoip2_test.rb @@ -1,9 +1,9 @@ # encoding: utf-8 require 'test_helper' -class Geolite2Test < GeocoderTestCase +class Geoip2Test < GeocoderTestCase def setup - Geocoder.configure(ip_lookup: :geolite2, file: 'test_file') + Geocoder.configure(ip_lookup: :geoip2, file: 'test_file') end def test_result_attributes