Freegeoip
This gem provides a simple Rails engine with an IP geolocation API that ducks with Freegeoip.
It reads MaxMindDB's open source GeoLite2 City database, with the help of maxminddb gem, a pure Ruby implementation.
You can find MaxMind's GeoLite2 City database here.
Installation
Add this line to your application's Gemfile:
gem "freegeoip-rails", require: "freegeoip"
Mount the engine in your routes file:
mount Freegeoip::Engine, at: "/json"
Add an initializer like config/initializers/freegeoip.rb
and tell the engine where it can find your GeoLite2 City database:
Freegeoip.configure do |config|
# Anything that can be opened by OpenURI
config.db_location = Rails.root.join "vendor/maxminddb/GeoLite2-City.mmdb"
end
Start your web server and point your browser to http://localhost:3000/json/www.ruby-lang.org
or http://localhost:3000/json/151.101.1.178
and you should get a response with JSON data.
Contributing
Contributions are always welcome.
Varvet
Crafted with love at Varvet digital agency. Skapad med omsorg av Varvet digital byrÄ.
License
The gem is available as open source under the terms of the MIT License.