Project

rack-geoip

0.0
No commit activity in last 3 years
No release in over 3 years
A rack middleware component that handles simple geoip lookups.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

>= 0
>= 0

Runtime

>= 2.0.2
>= 0
>= 0
 Project Readme
= Rack::Geoip

A rack middleware component that handles simple geoip lookups.

== Installation

First you must have a GeoIP database installed. Currently the only backend support is the free one from
MaxMind (http://www.maxmind.com). So you must first install the C api bindings.

    $ wget http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz
    $ tar xzf GeoIP.tar.gz
    $ cd GeoIP-1.4.6
    $ ./configure && make && sudo make install

To download the actual GeoLiteCity (free) database you can currently find it here (I like to place it in
a data sub-directory).

    $ cd data
    $ wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
    $ gunzip GeoLiteCity.dat.gz

And finally install the gem

    $ gem install rack-geoip
    
== Usage

=== Basic Usage

    require 'rack/geoip'
    use Rack::Geoip
    run app

=== Using with Rails

Add this to your config/environment.rb

    config.gem 'rack-geoip'

And then in an initializer block

    config.middleware.use "Rack::Geoip",
      :db => 'data/GeoLiteCity.dat',
      :path => '/geoip/info',
      :db_lookup => :memory
    
=== Sample output

    $ curl http://localhost:9292/lookup?ip=8.8.8.8
    
    { "area_code":650,
      "city":"Mountain View",
      "postal_code":"94043",
      "country_code":"US",
      "latitude":37.4192008972168,
      "country_code3":"USA",
      "longitude":-122.057403564453,
      "country_name":"United States",
      "dma_code":807,
      "region":"CA" }

== Note on Patches/Pull Requests
 
* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
  future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
  (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.

== Credits

I want to acknowledge the work done by Geoffrey Grosenbach (http://peepcode.com) on the sinatra-geoip gem which was the
inspiration for this.

== License

Rack::Geoip is Copyright (c) 2010 by Chris Kraybill and is provided under the MIT license. See COPYING for details.