0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
IpToCountry is a simple rails tool to determine the origin (ISO country code or country name) of an IP address. The gem uses data from GeoLite by MaxMind.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

< 5.0, >= 3.2.12
 Project Readme

IpToCountry Gem Version Build Status Dependency Status Code Climate Coverage Status

IpToCountry is a simple rails extension to find the origin (ISO country code or country name) of an IP address.

IpToCountry only supports ruby 1.9.3+, rails 3.2+ and only works with a postgresql database. Support mysql is planned.

Installation

Add the following line to your gemfile:

gem 'ip_to_country'

and run command

bundle install

Generate migration

rails generate geoip
rake db:migrate
rake ip_to_country:populate

Geoip model

All logic takes place in IpToCountry::Geoip model

You can find detail of an IP address, using:

IpToCountry::Geoip.by_ip('192.168.1.34')

Request location

The gem add an extension to Rack::Request to quickly get the country code/name origin of a request.

In your controller, you can do:

request.geoip.country_name
request.geoip.country_code

Development

Pull requests and bug reports are welcome!

Author

Vincent Pochet (@vin100pochet)

GeoLite Data

This product includes GeoLite data created by MaxMind, available from (http://www.maxmind.com).