IP2Location.io Ruby on Rails Library
This IP2Location.io Ruby on Rails library enables user to query for an enriched data set, such as country, region, district, city, latitude & longitude, ZIP code, time zone, ASN, ISP, domain, net speed, IDD code, area code, weather station data, MNC, MCC, mobile brand, elevation, usage type, address type, advertisement category and proxy data with an IP address. It supports both IPv4 and IPv6 address lookup.
This module requires API key to function. You may sign up for a free API key at https://www.ip2location.io/pricing.
INSTALLATION
- Add this lines to your application's Gemfile:
gem 'ip2location_io_ruby'
gem 'ip2location_io_rails'
- Then execute it
$ bundle install
- Open the preferred file in the
config/environments
directory. Add the following code to the chosen configuration file after the Rails.application.configure do
line.
config.ip2location_io_key = 'YOUR_API_KEY'
USAGE
- Create a TestController using the below command line
bin/rails generate controller Test index --skip-routes
- Open the app/controllers/test_controller.rb in any text editor.
- Add the below lines into the controller file.
require 'ip2location_io_rails'
class TestController < ApplicationController
def index
location_service = Ip2locationIORails.new('8.8.8.8')
@location = location_service.location.body
end
end
- Open the app/views/test/index.html.erb in any text editor and add the below lines into it.
<p>IP2Location.io data for IP 8.8.8.8: <%= @location %></p>
- Add the following line into the config/routes.rb file after the
Rails.application.routes.draw do
line.
get "/test", to: "test#index"
- Restart your development server.
$ bin/rails server
- Enter the URL /test and run. You should see the proxy information of 8.8.8.8 IP address.
Support
Email: support@ip2location.com
URL: https://www.ip2location.com