/geoip2

Primary LanguageC

Ruby Maxmind GeoIP2 Bindings

Description

Searches city by ip address in local database from maxmind.com.

Use it with rails. For now, I think.

Installation

libmaxminddb must be installed.

gem 'maxmind_geoip2'

Usage

Configuration, can be moved to rails initializer

MaxmindGeoIP2.file '<local_db_file.mmdb>' # default: GeoLite2-City.mmdb
MaxmindGeoIP2.locale 'ru' # default: 'ru'

Further usage:

Returns nil if nothing found and raises exception if file not opened or not found

city = MaxmindGeoIP2.locate(<ip address>, <optional lang>)

city = MaxmindGeoIP2.locate '77.93.127.33'
=> {"city"=>"Тамбов",
"city_geoname_id"=>484646,
"country"=>"Россия",
"country_geoname_id"=>2017370,
"country_code"=>"RU",
"continent"=>"Европа",
"continent_code"=>"EU",
"continent_geoname_id"=>6255148,
"subdivision"=>"Тамбовская область",
"subdivision_code"=>"TAM",
"postal_code"=>nil,
"latitude"=>52.731700000000004,
"longitude"=>41.4433,
"time_zone"=>"Europe/Moscow"}

city = MaxmindGeoIP2.locate '77.93.127.33', 'en'
=> {"city"=>"Tambov",
"city_geoname_id"=>484646,
"country"=>"Russia",
"country_geoname_id"=>2017370,
"country_code"=>"RU",
"continent"=>"Europe",
"continent_code"=>"EU",
"continent_geoname_id"=>6255148,
"subdivision"=>"Tambovskaya Oblast'",
"subdivision_code"=>"TAM",
"postal_code"=>nil,
"latitude"=>52.731700000000004,
"longitude"=>41.4433,
"time_zone"=>"Europe/Moscow"}