Grails GeoIP Plugin (based on MaxMind library)
Groovy
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
_old/scripts
gradle/wrapper
grails-app
src/main/groovy/grails/plugins/geoip
.gitignore
.travis.yml
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

grails-geoip

Build Status Analytics

Grails GeoIP Plugin (based on MaxMind library)

Summary

This plugin facilitates grails integration with the opensource GeoIP framework offered by MaxMind. Using its straightforward API one can find out the country, area, city, geographical coordinates and others based on an IP.

Installation

Add the following plugin definition to your BuildConfig:

…
plugins {
…
	compile ':geoip:0.3.3'
…
}

Then run script to download and install free GeoLite database:

grails install-geo-data

Usage

The plugin adds a dynamic method to your controllers to determine location of client is accessing the app:

isInCountry(String countryCode) (where countryCode is ISO 3166 Country Code) will be true if the client use IP from this country.

def list() {
	...
	if (isInCountry('US')) {
		render(view: 'usa')
	} else {
		render(view: 'default')
	}
}

Additionally, you can run code conditionally, with access to the current com.maxmind.geoip.Location instance, with this method:

withLocation(Closure closure)

def list() {
	...
	def view = 'list'
	withLocation { location ->
		view = "list_${location.countryCode}"
	}
	render(view: view, model: [list: listInstance])
}

Copyright and license

Copyright 2009-2013 Radu Andrei Tanasa, Alexey Zhokhov under the GNU Lesser General Public License, version 2.1. Supported by AZ.

This product includes GeoLite data created by MaxMind, available from www.maxmind.com.