A wrapper to MaxMind’s GeoIP services, that can work with both free and paid versions. Also provides geo-location methods to Active Record and Sequel Models.
This product includes GeoLite data created by MaxMind, available from www.maxmind.com.
It is quite fast, simple and hackable, and it doesn’t require any change to your application schema – unless you want to. Plus, the ruby bindings available from MaxMind are quite crap to use.
- While you are installing the MaxMind binaries on Linux systems, you may get an error similar to this:
libGeoIP.so.1: cannot open shared object file: No such file or directory
If you do, do the following:
$ vim /etc/ld.so.conf (and add /var/shared/lib) $ ldconfig
And rerun the installer.
Autometal::Geoip provides a standalone GeoIP service:
require "rubygems" require "geoip" @geo = Autometal::Geoip.new("18.104.22.168") @geo.country => US
You can also pass it a domain instead of an IP address
@geo = Autometal::Geoip.new("www.google.com") @geo.country => US
If you have purchased the Organization edition of the GeoIP database, you can also do this:
@geo.organization => Google
Currently, the gem does not support installing the file itself, you will need to make sure that GeoIPOrg.dat is located in /usr/local/shared/
You can make any object Geo-location aware, as long as it has an IP or a domain attribute:
require "rubygems" require "geoip" class Site include Autometal::Geolocatable end Site.new(:domain => "google.com") site.country => "US" site.organization # if GeoIPOrg.dat is not installed, this will return nil
The above will work if your class has a domain attribute. You can override the attribute used to geolocate by overriding geo_attr
require "rubygems" require "geoip" class Site include Autometal::Geolocatable def geo_attr; self.weird_ip_field_name; end end Site.new(:weird_ip_field_name => "22.214.171.124") site.country => "US"
- GeoIP C bindings (installed along with the Gem)
sudo gem install autometal-geoip sudo install_geoip (unless already installed)
- 0.4 Ruby 1.9.* support. Previous version of this gem would product encoding errors in some instances due to the different way Ruby 1.9+ deals with source and text encodings.
- 0.3.7 Installation now checks for sudo command, and runs accordingly. Bear in mind that if you are not root and sudo does not exist, the installation will fail as it will not have enough permissions to install binaries.
- 0.3.5 Documentation fixes
- 0.3.4 Changed bin_installed detection
- 0.3.3 Removed active_support dependency
- 0.2.2 Reworked class hierarchy, added support for GeoIP’s Organization database
- 0.1.3 Installer bugfix, fixes datafile install crash
- 0.1.1 Initial release
Copyright © 2010 – 2011 Achillefs Charmpilas, Humbucker Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.