public
Description: ruby binding to maxmind geoip library
Homepage: http://geoip-city.rubyforge.org
Clone URL: git://github.com/ry/geoip-city.git
Search Repo:
Ryan Dahl (author)
Tue Mar 04 15:10:33 -0800 2008
commit  45255461f65d5980a7f3fb5886dadff4a667ea7c
tree    5101c34d7d74b14251132742d5c5f63bea0c06fc
parent  94e8ce6f3da3a23f2a9e35102e7e797276b7e54c
name age message
folder README Tue Mar 04 14:58:58 -0800 2008 updates to readme [Ryan Dahl]
folder Rakefile Tue Mar 04 14:42:18 -0800 2008 added options for database loading [Ryan Dahl]
folder extconf.rb Tue Mar 04 15:10:33 -0800 2008 fix install script [Ryan Dahl]
folder geoip_city.c Tue Mar 04 14:42:18 -0800 2008 added options for database loading [Ryan Dahl]
folder test.rb Tue Mar 04 15:10:33 -0800 2008 fix install script [Ryan Dahl]
README
= What?
This is a library which provides a single function. The function takes as
input an IP address and it outputs a hash containing best-guess geographical
information (like city, country, latitude, and longitude).

Actually this is only a Ruby binding to a C library which provides this
function. Also, you must download a large binary database with all this
mapping information. It is kindly provided free of charge by MaxMind.com. 

= Usage
   require 'geoip_city'
   db = GeoIPCity::Database.new('/opt/GeoIP/share/GeoIP/GeoLiteCity.dat')
   result = db.look_up('24.24.24.24')
   p result 
   # => {:city=>"Ithaca", 
   #     :latitude=>42.4277992248535, 
   #     :longitude=>-76.4981994628906, 
   #     :country_code3=>"USA", 
   #     :country_code=>"US",
   #     :country_name=>"United States", 
   #     :dma_code=>555,
   #     :area_code=>607, 
   #     :region=>"NY" }

There are two optional arguments to database initializer.
The first argument is the filename of the GeoIPCity.dat file 
The second argument (optional) is to specify how GeoIP should
keep the database in memory. There are three possibilities
* :filesystem -- read database from filesystem, uses least memory.
* :index -- the most frequently accessed index portion of the database, resulting in faster lookups than :filesystem, 
but less memory usage than :memory.
* :memory -- load database into memory, faster performance but uses more memory.
  (default)

The third argument is boolean and decides whether the system should reload the database if changes are made to the dat 
file. (You probably don't need this. Default: false.)

For example 

  GeoIPCity::Database.new(dbfile, :filesystem, true)

= Install
Some variation of the following should work.

1. Install the GeoCity C library. You can get it from here  
   http://www.maxmind.com/app/c
   For example, I like to install mine in /opt/GeoIP
   so I do this:
     tar -zxvf GeoIP-1.4.3.tar.gz 
     cd GeoIP-1.4.3
     ./configure --prefix=/opt/GeoIP
     make && sudo make install

2. Now install the geoip_city gem 
     sudo gem install geoip_city -- --with-geoip-dir=/opt/GeoIP

3. Download the GeoLite City database file in binary format from:
   http://www.maxmind.com/app/geolitecity
   Maybe this direct link will work:
   http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
   I put this file in 
   /opt/GeoIP/share/GeoIP/GeoLiteCity.dat

4. Use it!

= License 
Copyright (C) 2007 Ryan Dahl (ry@tinyclouds.org)

I give permission for you to do whatever you'd like to do with this software.