Skip to content

dalyons/geoip2

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ruby 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 'geoip2', github: 'da4nik/geoip2'

Usage

Configuration, can be moved to rails initializer

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

Further usage:

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

city = GeoIP2::locate(<ip address>, <optional lang>)

city = GeoIP2::locate '77.93.127.33'
=> {"city"=>"Тамбов",
 "country"=>"Россия",
 "country_code"=>"RU",
 "continent"=>"Европа",
 "latitude"=>52.731700000000004,
 "longitude"=>41.4433}

city = GeoIP2::locate '77.93.127.33', 'en'
=> {"city"=>"Tambov",
 "country"=>"Russia",
 "country_code"=>"RU",
 "continent"=>"Europe",
 "latitude"=>52.731700000000004,
 "longitude"=>41.4433}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published