/sypex_geo

Sypex Geo IP database adapter for Ruby.

Primary LanguageRuby

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