Ip2Geo Logo

Your go-to IP-to-Geo cloud service — fast, accurate, and built for developers. Start free with 1,000 monthly stored conversions.

Website Dashboard Documentation Services Status


Intro to the Ruby Gem

This gem provides a lightweight way to integrate Ip2Geo into your Ruby applications.

Installing

gem install ip2geo

Initializing

require 'ip2geo'

Ip2Geo.init(ENV['IP2GEO_API_KEY'])

Using

converted_ip = Ip2Geo.convert_ip(ip: '8.8.8.8')

converted_ips = Ip2Geo.convert_ips(
  ips: [
    '8.8.8.8',
    '1.1.1.1',
    '9.9.9.9',
    '64.6.64.6'
  ]
)

# {
#     'success' => true,
#     'code' => 200,
#     'message' => 'Success',
#     'data' => { ... },
#     '_req' => {
#          'reqId' => 'string',
#          'resTime' => 123
#     }
# }

# {
#     'success' => true,
#     'code' => 200,
#     'message' => 'Success',
#     'data' => [
#         {
#             'ip' => '8.8.8.8',
#             'conversion' => { ... }
#         }
#     ],
#     '_req' => {
#          'reqId' => 'string',
#          'resTime' => 123
#     }
# }