Sypex Geo IP database adapter for Ruby.
Ruby
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.editorconfig
.gitignore
.rspec
.travis.yml
Gemfile
README.md
Rakefile
sypex_geo.gemspec

README.md

Gem Version Build Status Code Climate Test Coverage

SypexGeo

Sypex Geo IP database adapter for Ruby.

Installation

Add this line to your application's Gemfile:

gem 'sypex_geo'

And then execute:

$ bundle

Usage

require 'sypex_geo'

db = SypexGeo::Database.new('./SxGeoCity.dat')
location = db.query('<IPv4 address>')

location.city
# => {
#   id: 524901,
#   lat: 55.75222,
#   lon: 37.61556,
#   name_ru: 'Москва',
#   name_en: 'Moscow'
# }

location.region
# => {
#   id: 524894,
#   iso: 'RU-MOW',
#   name_ru: 'Москва',
#   name_en: 'Moskva'
# }

location.country
# => {
#   id: 185,
#   iso: 'RU',
#   lat: 60.0,
#   lon: 100.0,
#   name_ru: 'Россия',
#   name_en: 'Russia'
# }

location.country_code
# => 'RU'

Testing

$ wget http://sypexgeo.net/files/SxGeoCountry.zip && unzip SxGeoCountry.zip
$ wget http://sypexgeo.net/files/SxGeoCity_utf8.zip && unzip SxGeoCity_utf8.zip
$ SXGEO_DB=./SxGeo.dat SXGEO_CITY_DB=./SxGeoCity.dat rspec

License

MIT