Skip to content
Snippets Groups Projects
Commit 19437aad authored by Alex Reisner's avatar Alex Reisner
Browse files

Rename from :geolite2 to :geoip2.

GeoLite2 is a free version of a product called GeoIP2. Both use the same
format.
parent cb6a9598
No related branches found
No related tags found
No related merge requests found
......@@ -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
-------
......
......@@ -52,7 +52,7 @@ module Geocoder
[
:baidu_ip,
:freegeoip,
:geolite2,
:geoip2,
:maxmind,
:maxmind_local,
:telize,
......
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
......
......@@ -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(/^[ ,]*/, '')
......
......@@ -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
......
......@@ -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")
......
......@@ -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
......
......@@ -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"}
......
# 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment