IP Geolocation API Library/SDK for Ruby


Overview

The official Ruby Client Library for IPGeolocation.io's set of APIs, provides a quick, developer friendly, way to access IP Location, Security, Timezone, Astronomy, ASN, Abuse Contact, and useragent data. Lookup your own IP or provide any IPv4, IPv6 or domain name to get structured results in Ruby, without the need for manual HTTP requests or response parsing.

  • IP Location API: Get all-in-one unified solution for location (city, locality, state, country, etc.), currency, network (AS number, ASN name, organization, asn type, date of allocation, company/ISP name, company type, company domain), timezone , useragent string parsing, security (threat score, is_tor, is_bot, proxy_provider, cloud_provider), and abuse contact (route/CIDR network, country, address, email, phone numbers) information.
  • IP Security API: Get security, network, location, hostname, timezone and useragent parsing.
  • ASN API: Get ASN details along with peers, upstreams, downstreams, routes, and raw WHOIS.
  • Abuse Contact API: Get abuse emails, phone numbers, kind, organization, route/CIDR network and country.
  • Astronomy API: Get sunrise, sunset, moonrise, moonset, moon phases with precise twilight period times in combination with location information.
  • Timezone API: Get timezone name, multiple time formats, daylight saving status and its details along with location information.
  • Timezone Convert API: Convert time between timezone names, geo coordinates, location addresses, IATA codes, ICAO codes, or UN/LOCODE.
  • User Agent API: Get browser, Operating System, and device info from single or multiple Useragent string parsing.

This Ruby Gem aims to empower developers to integrate threat intelligence, personalization, fraud prevention, compliance, and analytics features directly into Ruby based applications. Whether you're enriching signup forms with ip geolocation data, localizing content, embedding threat intelligence in back-end systems, or converting time zones and currencies, the library ensures seamless, scalable integration with IPGeolocation.io’s global API infrastructure.

Based on:

  • API version: 2.0.0

Official Release:


Requirements


Installation


1.From RubyGems.org

Install via command line:

gem install ipgeolocation_sdk

May be you need to run the command with root permissions. like sudo gem install ipgeolocation_sdk .

Or add to your Gemfile :

gem 'ipgeolocation_sdk', '~> 1.0.0'

Then run:

bundle install

2.From Source (Local Build)

To build and install locally:

gem build ipgeolocation_sdk.gemspec
gem install ./ipgeolocation_sdk-1.0.0.gem

3.From GitHub

To install directly from a GitHub repository:

gem 'ipgeolocation_sdk', git: 'https://github.com/IPGeolocation/ip-geolocation-ruby-sdk.git'

Then run:

bundle install

API Plan Tiers and Documentation

The documentation below corresponds to the four available API tier plans:

For a detailed comparison of what each plan offers, visit the Pricing Page.


API Endpoints

All URIs are relative to https://api.ipgeolocation.io/v2

ClassMethodHTTP requestDescription
IpgeolocationSdk::IPGeolocationApiget_ip_geolocationGET /ipgeoGet geolocation data for a single IP address
IpgeolocationSdk::IPGeolocationApiget_bulk_ip_geolocationPOST /ipgeo-bulkGet geolocation data for multiple IP addresses in a single API request
IpgeolocationSdk::IPSecurityApiget_ip_security_infoGET /securityRetrieve security threat intelligence for a single IP
IpgeolocationSdk::IPSecurityApiget_bulk_ip_security_infoPOST /security-bulkRetrieve security threat intelligence for multiple IPs
IpgeolocationSdk::ASNLookupApiget_asn_infoGET /asnGet details of any ASN number or associated IP address
IpgeolocationSdk::AbuseContactApiget_abuse_contact_infoGET /abuseRetrieve abuse reporting contact information for a given IP address
IpgeolocationSdk::AstronomyApiget_astronomy_detailsGET /astronomyGet sunrise, sunset, moonrise, moonset, and related data for a location
IpgeolocationSdk::TimezoneApiget_timezone_infoGET /timezoneTimezone information details
IpgeolocationSdk::TimeConversionApiconvert_time_between_timezonesGET /timezone/convertConvert time between two specified timezones
IpgeolocationSdk::UserAgentApiget_user_agent_detailsGET /user-agentGet details of user-agent
IpgeolocationSdk::UserAgentApiparse_bulk_user_agent_stringsPOST /user-agent-bulkHandle multiple user-agent string lookups

Fields and Methods Availability

IP Geolocation offers four plans from billing point of view: Free, Standard, Security, Advance. The availability of each method calling from the respective class, over all plans are presented below.

ClassMethodFreeStandardSecurityAdvance
IpgeolocationSdk::IPGeolocationApiget_ip_geolocationTickTickCrossTick
IpgeolocationSdk::IPGeolocationApiget_bulk_ip_geolocationCrossTickCrossTick
IpgeolocationSdk::IPSecurityApiget_ip_security_infoCrossCrossTickCross
IpgeolocationSdk::IPSecurityApiget_bulk_ip_security_infoCrossCrossTickCross
IpgeolocationSdk::ASNLookupApiget_asn_infoCrossCrossCrossTick
IpgeolocationSdk::AbuseContactApiget_abuse_contact_infoCrossCrossCrossTick
IpgeolocationSdk::AstronomyApiget_astronomy_detailsTickTickTickTick
IpgeolocationSdk::TimezoneApiget_timezone_infoTickTickTickTick
IpgeolocationSdk::TimeConversionApiconvert_time_between_timezonesTickTickTickTick
IpgeolocationSdk::UserAgentApiget_user_agent_detailsTickTickTickTick
IpgeolocationSdk::UserAgentApiparse_bulk_user_agent_stringsCrossTickTickTick
Tip

The availability of fields in every API endpoint across all API plans is provided in the Reference Table within each respective API Documentation. e.g., for IPGeolocationApi, please visit https://ipgeolocation.io/ip-location-api.html#reference-to-ipgeolocation-api-response.


Authentication Setup

To authenticate API requests, you need to get an API key from ipgeolocation.io.


1.How to Get Your API Key

  1. Sign up here: https://app.ipgeolocation.io/signup
  2. (optional) Verify your email, if you signed up using email.
  3. Log in to your account: https://app.ipgeolocation.io/login
  4. After logging in, navigate to your Dashboard to find your API key: https://app.ipgeolocation.io/dashboard


2.ApiKeyAuth

Once you've obtained the api key, configure your API client as follows:

The client must configure the authentication and authorization parameters in accordance with the API server security policy.

# Load the gem
require 'ipgeolocation_sdk'

# Setup authorization
IpgeolocationSdk.configure do |config|
  config.api_key['apiKey'] = 'YOUR API KEY'
end

Accessing API response fields

The response returned by the library can be accessed in the following ways:


1.Access a specific field

require 'ipgeolocation_sdk'

IpgeolocationSdk.configure do |config|
   config.api_key['apiKey'] = 'YOUR API KEY'
end

geo = IpgeolocationSdk::IPGeolocationApi.new
begin
   opts = { ip: "8.8.8.8"}
   result = geo.get_ip_geolocation(opts)

   # Get specific field from response with dot separated path
   puts "IP: #{result.ip}"
   puts "Country: #{result.location.country_name}"
   puts "City: #{result.location.city}"
   puts "Currency name: #{result.currency.name}"
rescue IpgeolocationSdk::ApiError => e
   puts "API Error: #{e}"
end

Sample Response:

Response
1IP: 8.8.8.8
2Country: United States
3City: Mountain View
4Currency name: US Dollar

2.Get JSON response

To get the JSON response in a pretty formatted way:

require 'ipgeolocation_sdk'

IpgeolocationSdk.configure do |config|
   config.api_key['apiKey'] = 'YOUR API KEY'
end

geo = IpgeolocationSdk::IPGeolocationApi.new

begin
   opts = { ip: "8.8.8.8"}
   result = geo.get_ip_geolocation(opts)

   # Get pretty JSON response proper formatted
   puts JSON.pretty_generate(result.to_hash)
rescue IpgeolocationSdk::ApiError => e
   puts "API Error: #{e}"
end

Or without the JSON module

require 'ipgeolocation_sdk'

IpgeolocationSdk.configure do |config|
   config.api_key['apiKey'] = 'YOUR API KEY'
end

geo = IpgeolocationSdk::IPGeolocationApi.new

begin
   opts = { ip: "8.8.8.8"}
   result = geo.get_ip_geolocation(opts)

   # Use sdk's to_json method instead
   puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
   puts "API Error: #{e}"
end

Sample Response:

Response
1{
2   "ip": "8.8.8.8",
3   "location": {
4      "continent_code": "NA",
5      "continent_name": "North America",
6      "country_code2": "US",
7      "country_code3": "USA",
8      "country_name": "United States",
9      "country_name_official": "United States of America",
10      "country_capital": "Washington, D.C.",
11      "state_prov": "California",
12      "state_code": "US-CA",
13      "district": "Santa Clara",
14      "city": "Mountain View",
15      "zipcode": "94043-1351",
16      "latitude": "37.42240",
17      "longitude": "-122.08421",
18      "is_eu": false,
19      "country_flag": "https://ipgeolocation.io/static/flags/us_64.png",
20      "geoname_id": "6301403",
21      "country_emoji": "🇺🇸"
22   },
23   "country_metadata": {
24      "calling_code": "+1",
25      "tld": ".us",
26      "languages": [
27         "en-US",
28         "es-US",
29         "haw",
30         "fr"
31      ]
32   },
33   "currency": {
34      "code": "USD",
35      "name": "US Dollar",
36      "symbol": "$"
37   }
38}

IP Geolocation Examples

This section provides usage examples of the get_ip_geolocation() method from the SDK across Free, Standard, and Advanced subscription tiers. Each example highlights different combinations of parameters: fields , include , and excludes .

Parameters

  • fields : Use this parameter to include specific fields in the response.
  • excludes : Use this parameter to omit specific fields from the response.
  • include : Use this parameter to add optional modules to the response, such as:
    • security
    • user_agent
    • hostname
    • liveHostname
    • hostnameFallbackLive
    • abuse
    • dma
    • time_zone

For complete details, refer to the official documentation: IP Geolocation API Documentation

The ip parameter in the SDK can accept any valid IPv4 address, IPv6 address, or domain name. If the ip option is not used or the parameter is omitted, the library will return information about the public IP address of the device or server where the library is executed.


1.Developer Plan Examples

I.Get Default Fields

geolocation_instance = IpgeolocationSdk::IPGeolocationApi.new
begin
   get_geolocation_opts = {
      ip: "8.8.8.8"
   }
   result = geolocation_instance.get_ip_geolocation(get_geolocation_opts)
   puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
   puts "Error calling GeolocationApi: #{e}"
end

Sample Response:

Response
1{
2   "ip": "8.8.8.8",
3   "location": {
4      "continent_code": "NA",
5      "continent_name": "North America",
6      "country_code2": "US",
7      "country_code3": "USA",
8      "country_name": "United States",
9      "country_name_official": "United States of America",
10      "country_capital": "Washington, D.C.",
11      "state_prov": "California",
12      "state_code": "US-CA",
13      "district": "Santa Clara",
14      "city": "Mountain View",
15      "zipcode": "94043-1351",
16      "latitude": "37.42240",
17      "longitude": "-122.08421",
18      "is_eu": false,
19      "country_flag": "https://ipgeolocation.io/static/flags/us_64.png",
20      "geoname_id": "6301403",
21      "country_emoji": "🇺🇸"
22   },
23   "country_metadata": {
24      "calling_code": "+1",
25      "tld": ".us",
26      "languages": [
27         "en-US",
28         "es-US",
29         "haw",
30         "fr"
31      ]
32   },
33   "currency": {
34      "code": "USD",
35      "name": "US Dollar",
36      "symbol": "$"
37   }
38}

Filtering Specific Fields from the Response (Use of exclude and fields )

get_geolocation_opts = {
  ip: "8.8.4.4",
  fields: "location",
  excludes: "location.continent_code,location.continent_name"
}
geolocation_instance = IpgeolocationSdk::IPGeolocationApi.new
begin
    result = geolocation_instance.get_ip_geolocation(get_geolocation_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling GeolocationApi: #{e}"
end

Sample Response:

Response
1{
2   "ip": "8.8.4.4",
3   "location": {
4      "country_code2": "US",
5      "country_code3": "USA",
6      "country_name": "United States",
7      "country_name_official": "United States of America",
8      "country_capital": "Washington, D.C.",
9      "state_prov": "California",
10      "state_code": "US-CA",
11      "district": "Santa Clara",
12      "city": "Mountain View",
13      "zipcode": "94043-1351",
14      "latitude": "37.42240",
15      "longitude": "-122.08421",
16      "is_eu": false,
17      "country_flag": "https://ipgeolocation.io/static/flags/us_64.png",
18      "geoname_id": "6301403",
19      "country_emoji": "🇺🇸"
20   }
21}

2.Standard Plan Examples

I.Get Standard plan default Fields

get_geolocation_opts = {
  ip: "8.8.8.8"
}
geolocation_instance = IpgeolocationSdk::IPGeolocationApi.new
begin
    result = geolocation_instance.get_ip_geolocation(get_geolocation_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling GeolocationApi: #{e}"
end

Sample Response:

Response
1{
2   "ip": "8.8.8.8",
3   "location": {
4      "continent_code": "NA",
5      "continent_name": "North America",
6      "country_code2": "US",
7      "country_code3": "USA",
8      "country_name": "United States",
9      "country_name_official": "United States of America",
10      "country_capital": "Washington, D.C.",
11      "state_prov": "California",
12      "state_code": "US-CA",
13      "district": "Santa Clara",
14      "city": "Mountain View",
15      "zipcode": "94043-1351",
16      "latitude": "37.42240",
17      "longitude": "-122.08421",
18      "is_eu": false,
19      "country_flag": "https://ipgeolocation.io/static/flags/us_64.png",
20      "geoname_id": "6301403",
21      "country_emoji": "🇺🇸"
22   },
23   "country_metadata": {
24      "calling_code": "+1",
25      "tld": ".us",
26      "languages": [
27         "en-US",
28         "es-US",
29         "haw",
30         "fr"
31      ]
32   },
33   "network": {
34      "asn": {
35         "as_number": "AS15169",
36         "organization": "Google LLC",
37         "country": "US"
38      },
39      "company": {
40         "name": "Google LLC"
41      }
42   },
43   "currency": {
44      "code": "USD",
45      "name": "US Dollar",
46      "symbol": "$"
47   }
48}

II.Retrieving Geolocation Data in Multiple Languages

Here is an example to get the geolocation data for IP address '2001:4230:4890::1' in French language:

get_geolocation_opts = {
  ip: "2001:4230:4890::1",
  lang: "fr"
}
geolocation_instance = IpgeolocationSdk::IPGeolocationApi.new
begin
    result = geolocation_instance.get_ip_geolocation(get_geolocation_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling GeolocationApi: #{e}"
end

Sample Response

Response
1{
2  "ip": "2001:4230:4890:0:0:0:0:1",
3  "location": {
4    "continent_code": "AF",
5    "continent_name": "Afrique",
6    "country_code2": "MU",
7    "country_code3": "MUS",
8    "country_name": "Maurice",
9    "country_name_official": "",
10    "country_capital": "Port Louis",
11    "state_prov": "Wilhems des plaines",
12    "state_code": "MU-PW",
13    "district": "Quatre Bornes",
14    "city": "Quatre Bornes",
15    "zipcode": "72201",
16    "latitude": "-20.24304",
17    "longitude": "57.49631",
18    "is_eu": false,
19    "country_flag": "https://ipgeolocation.io/static/flags/mu_64.png",
20    "geoname_id": "1106777",
21    "country_emoji": "🇲🇺"
22  },
23  "country_metadata": {
24    "calling_code": "+230",
25    "tld": ".mu",
26    "languages": [
27      "en-MU",
28      "bho",
29      "fr"
30    ]
31  },
32  "network": {
33    "asn": {
34      "as_number": "AS52095",
35      "organization": "Netassist International s.r.o.",
36      "country": "CZ"
37    },
38    "company": {
39      "name": "African Network Information Center AfriNIC Ltd"
40    }
41  },
42  "currency": {
43    "code": "MUR",
44    "name": "Mauritius Rupee",
45    "symbol": "₨"
46  }
47}

III.Include HostName, Timezone and User-Agent

get_geolocation_opts = {
  ip: "4.5.6.7",
  include: "hostname,time_zone,user_agent"
}
geolocation_instance = IpgeolocationSdk::IPGeolocationApi.new
begin
    result = geolocation_instance.get_ip_geolocation(get_geolocation_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling GeolocationApi: #{e}"
end

Sample Response

Response
1{
2  "ip": "4.5.6.7",
3  "hostname": "4.5.6.7",
4  "location": {
5    "continent_code": "NA",
6    "continent_name": "North America",
7    "country_code2": "US",
8    "country_code3": "USA",
9    "country_name": "United States",
10    "country_name_official": "United States of America",
11    "country_capital": "Washington, D.C.",
12    "state_prov": "Louisiana",
13    "state_code": "US-LA",
14    "district": "Ouachita",
15    "city": "Monroe",
16    "zipcode": "71203-2041",
17    "latitude": "32.58997",
18    "longitude": "-92.06862",
19    "is_eu": false,
20    "country_flag": "https://ipgeolocation.io/static/flags/us_64.png",
21    "geoname_id": "4343811",
22    "country_emoji": "🇺🇸"
23  },
24  "country_metadata": {
25    "calling_code": "+1",
26    "tld": ".us",
27    "languages": [
28      "en-US",
29      "es-US",
30      "haw",
31      "fr"
32    ]
33  },
34  "network": {
35    "asn": {
36      "as_number": "AS3356",
37      "organization": "Level 3 Parent, LLC",
38      "country": "US"
39    },
40    "company": {
41      "name": "Level 3 Parent, LLC"
42    }
43  },
44  "currency": {
45    "code": "USD",
46    "name": "US Dollar",
47    "symbol": "$"
48  },
49  "time_zone": {
50    "name": "America/Chicago",
51    "offset": -6,
52    "offset_with_dst": -6,
53    "current_time": "2025-12-24 01:54:01.954-0600",
54    "current_time_unix": 1766562841.954,
55    "is_dst": false,
56    "dst_savings": 0,
57    "dst_exists": true,
58    "dst_start": {
59      "utc_time": "2025-03-09 TIME 08",
60      "duration": "+1H",
61      "gap": true,
62      "date_time_after": "2025-03-09 TIME 03",
63      "date_time_before": "2025-03-09 TIME 02",
64      "overlap": false
65    },
66    "dst_end": {
67      "utc_time": "2025-11-02 TIME 07",
68      "duration": "-1H",
69      "gap": false,
70      "date_time_after": "2025-11-02 TIME 01",
71      "date_time_before": "2025-11-02 TIME 02",
72      "overlap": true
73    }
74  },
75  "user_agent": {
76    "user_agent_string": "OpenAPI-Generator/1.0.0/ruby",
77    "name": "OpenAPI-Generator",
78    "type": "Special",
79    "version": "1.0.0",
80    "version_major": "1",
81    "device": {
82      "name": "Unknown",
83      "type": "Unknown",
84      "brand": "Unknown",
85      "cpu": "Unknown"
86    },
87    "engine": {
88      "name": "Unknown",
89      "type": "Unknown",
90      "version": "??",
91      "version_major": "??"
92    },
93    "operating_system": {
94      "name": "Unknown",
95      "type": "Unknown",
96      "version": "??",
97      "version_major": "??",
98      "build": "??"
99    }
100  }
101}
Note

The IP Geolocation API supports hostname lookup for all paid subscriptions. However, this is not included by default. To enable hostname resolution, use the include parameter with one of the following options:

  • hostname : Performs a quick lookup using the internal hostname database. If no match is found, the IP is returned as-is. This is fast but may produce incomplete results.
  • liveHostname : Queries live sources for accurate hostname resolution. This may increase response time.
  • hostnameFallbackLive : Attempts the internal database first, and falls back to live sources if no result is found. This option provides a balance of speed and reliability.

3.Advanced Plan Examples

I.Include DMA, Abuse and Security

get_geolocation_opts = {
  ip: "8.8.8.8",
  include: "dma,abuse,security",
  excludes: "location.country_flag,location.country_emoji"
}
geolocation_instance = IpgeolocationSdk::IPGeolocationApi.new
begin
    result = geolocation_instance.get_ip_geolocation(get_geolocation_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling GeolocationApi: #{e}"
end

Sample Response:

Response
1{
2  "ip": "8.8.8.8",
3  "location": {
4    "continent_code": "NA",
5    "continent_name": "North America",
6    "country_code2": "US",
7    "country_code3": "USA",
8    "country_name": "United States",
9    "country_name_official": "United States of America",
10    "country_capital": "Washington, D.C.",
11    "state_prov": "California",
12    "state_code": "US-CA",
13    "district": "Santa Clara",
14    "city": "Mountain View",
15    "zipcode": "94043-1351",
16    "latitude": "37.42240",
17    "longitude": "-122.08421",
18    "is_eu": false,
19    "geoname_id": "6301403",
20    "accuracy_radius": "21.485",
21    "locality": "Mountain View",
22    "dma_code": "807"
23  },
24  "country_metadata": {
25    "calling_code": "+1",
26    "tld": ".us",
27    "languages": [
28      "en-US",
29      "es-US",
30      "haw",
31      "fr"
32    ]
33  },
34  "network": {
35    "asn": {
36      "as_number": "AS15169",
37      "organization": "Google LLC",
38      "country": "US",
39      "asn_name": "GOOGLE",
40      "type": "BUSINESS",
41      "domain": "google.com",
42      "date_allocated": "2012-02-24T00:00",
43      "allocation_status": "",
44      "num_of_ipv4_routes": "1008",
45      "num_of_ipv6_routes": "136",
46      "rir": "ARIN"
47    },
48    "connection_type": "",
49    "company": {
50      "name": "Google LLC",
51      "type": "Hosting",
52      "domain": "google.com"
53    }
54  },
55  "currency": {
56    "code": "USD",
57    "name": "US Dollar",
58    "symbol": "$"
59  },
60  "security": {
61    "threat_score": 0,
62    "is_tor": false,
63    "is_proxy": false,
64    "proxy_type": "",
65    "proxy_provider": "",
66    "is_anonymous": false,
67    "is_known_attacker": false,
68    "is_spam": false,
69    "is_bot": false,
70    "is_cloud_provider": false,
71    "cloud_provider": ""
72  },
73  "abuse": {
74    "route": "8.8.8.0/24",
75    "country": "",
76    "handle": "ABUSE5250-ARIN",
77    "name": "Abuse",
78    "organization": "Abuse",
79    "role": "abuse",
80    "kind": "group",
81    "address": "1600 Amphitheatre Parkway\nMountain View\nCA\n94043\nUnited States",
82    "emails": [
83      "network-abuse@google.com"
84    ],
85    "phone_numbers": [
86      "+1-650-253-0000"
87    ]
88  }
89}

These examples demonstrate typical usage of the IP Geolocation API with different subscription tiers. Use fields to specify exactly which data to receive, include for optional data like security and user agent, and excludes to omit specific keys from the response.

Note

All features available in the Free plan are also included in the Standard and Advanced plans. Similarly, all features of the Standard plan are available in the Advanced plan.


4.Bulk IP Geolocation Example

The SDK also supports bulk IP geolocation requests using the get_bulk_ip_geolocation() method. All parameters like fields , include , and excludes can also be used in bulk requests.

post_geolocation_opts = {
    ips: ["8.8.8.8", "asdasd"],
    include: "security",
    excludes: "location.country_flag,location.country_emoji"
}
geolocation_instance = IpgeolocationSdk::IPGeolocationApi.new
begin
    result = geolocation_instance.get_bulk_ip_geolocation(post_geolocation_opts)
    result.each do |item|
        if IpgeolocationSdk::BulkIPGeolocation.is_success?(item) # GeolocationResponse
            p item.ip
        elsif IpgeolocationSdk::BulkIPGeolocation.is_error?(item) # ErrorResponse
            p item.message
        end
    end
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling GeolocationApi: #{e}"
end

IP Security Examples

This section provides usage examples of the get_ip_security_info() method from the SDK across various subscription tiers. Each example demonstrates different ways to query threat intelligence and risk metadata using parameters like fields, excludes, and optional modules.

For full API specifications, refer to the official IP Security API documentation.


1.Get Default Security Fields

get_ip_security_opts = {
    ip: "2.56.188.34"
}
security_instance = IpgeolocationSdk::IPSecurityApi.new
begin
    result = security_instance.get_ip_security_info(get_ip_security_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling GeolocationApi: #{e}"
end

Sample Response

Response
1{
2  "ip": "2.56.188.34",
3  "security": {
4    "threat_score": 80,
5    "is_tor": false,
6    "is_proxy": true,
7    "proxy_type": "PROXY",
8    "proxy_provider": "Zyte Proxy",
9    "is_anonymous": true,
10    "is_known_attacker": true,
11    "is_spam": false,
12    "is_bot": false,
13    "is_cloud_provider": false,
14    "cloud_provider": ""
15  }
16}

2.Include Multiple Optional Fields

get_ip_security_opts = {
    ip: "2.56.188.34",
    include: "location,network,currency,time_zone,user_agent,country_metadata,hostname"
}
security_instance = IpgeolocationSdk::IPSecurityApi.new
begin
    result = security_instance.get_ip_security_info(get_ip_security_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling GeolocationApi: #{e}"
end
Note

You can get all the available fields in standard plan in combination with security data, when subscribed to security plan.


3.Request with Field Filtering

get_ip_security_opts = {
    ip: "195.154.221.54",
    fields: "security.is_tor,security.is_proxy,security.is_bot,security.is_spam"
}
security_instance = IpgeolocationSdk::IPSecurityApi.new
begin
    result = security_instance.get_ip_security_info(get_ip_security_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling SecurityApi: #{e}"
end

Sample Response

Response
1{
2  "ip": "195.154.221.54",
3  "security": {
4    "is_tor": false,
5    "is_proxy": true,
6    "is_spam": false,
7    "is_bot": false
8  }
9}

4.Bulk IP Security Request

The SDK also supports bulk IP Security requests using the get_bulk_ip_security_info() method. All parameters like fields , include , and excludes can also be used in bulk requests.

post_ip_security_opts = {
  ips: ["2.56.188.34","2.56.188.35"],
  include: "location,network",
  fields: "security.threat_score,location.country_name"
}

security_instance = IpgeolocationSdk::IPSecurityApi.new
begin
  result = security_instance.get_bulk_ip_security_info(post_ip_security_opts)
  result.each do |item|
    if IpgeolocationSdk::BulkIPSecurity.is_success?(item) # SecurityAPIResponse
      p item.security.threat_score
    elsif IpgeolocationSdk::BulkIPSecurity.is_error?(item) # ErrorResponse
      p item.message
    end
  end
rescue IpgeolocationSdk::ApiError => e
  puts "Error calling SecurityApi: #{e}"
end

ASN API Examples

This section provides usage examples of the get_asn_info() method from the SDK. These methods allow developers to retrieve detailed ASN-level network data either by ASN number or by IP address.

Note

ASN API is only available in the Advanced Plan.

Refer to the ASN API documentation for a detailed list of supported fields and behaviors.


1.Get ASN Information by IP Address

asn_opts = {
  ip: '8.8.8.8',
}
asn_instance = IpgeolocationSdk::ASNLookupApi.new
begin
  result = asn_instance.get_asn_info(asn_opts)
  puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
  puts "Error calling ASNLookupApi: #{e}"
end

Sample Response

Response
1{
2  "ip": "8.8.8.8",
3  "asn": {
4    "as_number": "AS15169",
5    "organization": "Google LLC",
6    "country": "US",
7    "asn_name": "GOOGLE",
8    "type": "BUSINESS",
9    "domain": "google.com",
10    "date_allocated": "2012-02-24T00:00",
11    "allocation_status": "",
12    "num_of_ipv4_routes": "1020",
13    "num_of_ipv6_routes": "136",
14    "rir": "ARIN"
15  }
16}

2.Get ASN Information by ASN Number

asn_opts = {
  asn: 15169,
}
asn_instance = IpgeolocationSdk::ASNLookupApi.new
begin
  result = asn_instance.get_asn_info(asn_opts)
  puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
  puts "Error calling ASNLookupApi: #{e}"
end

Sample Response

Response
1{
2  "asn": {
3    "as_number": "AS15169",
4    "organization": "Google LLC",
5    "country": "US",
6    "asn_name": "GOOGLE",
7    "type": "BUSINESS",
8    "domain": "google.com",
9    "date_allocated": "2012-02-24T00:00",
10    "allocation_status": "",
11    "num_of_ipv4_routes": "1020",
12    "num_of_ipv6_routes": "136",
13    "rir": "ARIN"
14  }
15}

3.Combine All objects using Include

asn_opts = {
    asn: 12,
    include: "peers,downstreams,upstreams,routes,whois_response"
}
asn_instance = IpgeolocationSdk::ASNLookupApi.new
begin
  result = asn_instance.get_asn_info(asn_opts)
  p result
rescue IpgeolocationSdk::ApiError => e
  puts "Error calling ASNLookupApi: #{e}"
end

Sample Response

Response
1{
2  "asn": {
3    "as_number": "AS12",
4    "organization": "New York University",
5    "country": "US",
6    "asn_name": "NYU-DOMAIN",
7    "type": "EDUCATION",
8    "domain": "nyu.edu",
9    "date_allocated": "2023-05-25T00:00",
10    "allocation_status": "",
11    "num_of_ipv4_routes": "11",
12    "num_of_ipv6_routes": "1",
13    "rir": "ARIN",
14    "routes": [
15      "192.76.177.0/24",
16      "...",
17      "216.165.103.0/24"
18    ],
19    "upstreams": [
20      {
21        "as_number": "AS3269",
22        "description": "Telecom Italia S.p.A.",
23        "country": "IT"
24      },
25      "...",
26      {
27        "as_number": "AS137",
28        "description": "Consortium GARR",
29        "country": "IT"
30      }
31    ],
32    "downstreams": [
33      {
34        "as_number": "AS394666",
35        "description": "NYU Langone Health",
36        "country": "US"
37      },
38      {
39        "as_number": "AS54965",
40        "description": "Polytechnic Institute of NYU",
41        "country": "US"
42      }
43    ],
44    "peers": [
45      {
46        "as_number": "AS3269",
47        "description": "Telecom Italia S.p.A.",
48        "country": "IT"
49      },
50      "...",
51      {
52        "as_number": "AS54965",
53        "description": "Polytechnic Institute of NYU",
54        "country": "US"
55      }
56    ],
57    "whois_response": "<raw-whois-response>"
58  }
59}

Abuse Contact API Examples

This section demonstrates how to use the get_abuse_contact_info() method of the AbuseContact API. This API helps security teams, hosting providers, and compliance professionals quickly identify the correct abuse reporting contacts for any IPv4 or IPv6 address. You can retrieve data like the responsible organization, role, contact emails, phone numbers, and address to take appropriate mitigation action against abusive or malicious activity.

Note

Abuse Contact API is only available in Advanced Plan.

Refer to the official Abuse Contact API documentation for details on all available fields.


1.Lookup Abuse Contact by IP

abuse_opts = {
  ip: '1.0.0.0',
}
abuse_instance = IpgeolocationSdk::AbuseContactApi.new
begin
    result = abuse_instance.get_abuse_contact_info(abuse_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling AbuseContactApi: #{e}"
end

Sample Response:

Response
1{
2  "ip": "1.0.0.0",
3  "abuse": {
4    "route": "1.0.0.0/24",
5    "country": "AU",
6    "handle": "IRT-APNICRANDNET-AU",
7    "name": "IRT-APNICRANDNET-AU",
8    "organization": "",
9    "role": "abuse",
10    "kind": "group",
11    "address": "PO Box 3646\nSouth Brisbane, QLD 4101\nAustralia",
12    "emails": [
13      "helpdesk@apnic.net"
14    ],
15    "phone_numbers": [
16      "+61 7 3858 3100"
17    ]
18  }
19}

2.Lookup Abuse Contact with Specific Fields

abuse_opts = {
  ip: '1.2.3.4',
  fields: 'abuse.role,abuse.emails',
}
abuse_instance = IpgeolocationSdk::AbuseContactApi.new
begin
    result = abuse_instance.get_abuse_contact_info(abuse_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling AbuseContactApi: #{e}"
end

Sample Response:

Response
1{
2  "ip": "1.2.3.4",
3  "abuse": {
4    "role": "abuse",
5    "emails": [
6      "helpdesk@apnic.net"
7    ]
8  }
9}

3.Lookup Abuse Contact while Excluding Fields

abuse_opts = {
  ip: '9.9.9.9',
  excludes: 'abuse.handle,abuse.emails',
}
abuse_instance = IpgeolocationSdk::AbuseContactApi.new
begin
    result = abuse_instance.get_abuse_contact_info(abuse_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling AbuseContactApi: #{e}"
end

Sample Response:

Response
1{
2  "ip": "9.9.9.9",
3  "abuse": {
4    "route": "9.9.9.0/24",
5    "country": "",
6    "name": "Quad9 Abuse",
7    "organization": "Quad9 Abuse",
8    "role": "abuse",
9    "kind": "group",
10    "address": "1442 A Walnut Street Ste 501\nBerkeley\nCA\n94709\nUnited States",
11    "phone_numbers": [
12      "+1-415-831-3129"
13    ]
14  }
15}

Timezone API Examples

This section provides usage examples of the get_timezone_info() method from the SDK, showcasing how to fetch timezone and time-related data using different query types — IP address, latitude/longitude, and timezone ID.

For full API specifications, refer to the Timezone API documentation.


1.Get Timezone by IP Address

time_zone_opts = {
    ip: "8.8.8.8"
}
time_zone_instance = IpgeolocationSdk::TimezoneApi.new
begin
    result = time_zone_instance.get_timezone_info(time_zone_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling TimezoneApi: #{e}"
end

Sample Response

Response
1{
2  "ip": "8.8.8.8",
3  "location": {
4    "continent_code": "NA",
5    "continent_name": "North America",
6    "country_code2": "US",
7    "country_code3": "USA",
8    "country_name": "United States",
9    "country_name_official": "United States of America",
10    "is_eu": false,
11    "state_prov": "California",
12    "state_code": "US-CA",
13    "district": "Santa Clara",
14    "city": "Mountain View",
15    "zipcode": "94043-1351",
16    "latitude": "37.42240",
17    "longitude": "-122.08421"
18  },
19  "time_zone": {
20    "name": "America/Los_Angeles",
21    "offset": -8,
22    "offset_with_dst": -8,
23    "date": "2025-12-24",
24    "date_time": "2025-12-24 02:45:59",
25    "date_time_txt": "Wednesday, December 24, 2025 02:45:59",
26    "date_time_wti": "Wed, 24 Dec 2025 02:45:59 -0800",
27    "date_time_ymd": "2025-12-24 02:45:59 -0800",
28    "date_time_unix": 1766573159.034,
29    "time_24": "02:45:59",
30    "time_12": "02:45:59 AM",
31    "week": 52,
32    "month": 12,
33    "year": 2025,
34    "year_abbr": "25",
35    "is_dst": false,
36    "dst_savings": 0,
37    "dst_exists": true,
38    "dst_start": {
39      "utc_time": "2025-03-09 TIME 10",
40      "duration": "+1H",
41      "gap": true,
42      "date_time_after": "2025-03-09 TIME 03",
43      "date_time_before": "2025-03-09 TIME 02",
44      "overlap": false
45    },
46    "dst_end": {
47      "utc_time": "2025-11-02 TIME 09",
48      "duration": "-1H",
49      "gap": false,
50      "date_time_after": "2025-11-02 TIME 01",
51      "date_time_before": "2025-11-02 TIME 02",
52      "overlap": true
53    }
54  }
55}

2.Get Timezone by Timezone Name

time_zone_opts = {
    tz: "Europe/London"
}
time_zone_instance = IpgeolocationSdk::TimezoneApi.new
begin
    result = time_zone_instance.get_timezone_info(time_zone_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling TimezoneApi: #{e}"
end

Sample Response

Response
1{
2  "time_zone": {
3    "name": "Europe/London",
4    "offset": 0,
5    "offset_with_dst": 0,
6    "date": "2025-12-24",
7    "date_time": "2025-12-24 10:46:56",
8    "date_time_txt": "Wednesday, December 24, 2025 10:46:56",
9    "date_time_wti": "Wed, 24 Dec 2025 10:46:56 +0000",
10    "date_time_ymd": "2025-12-24 10:46:56 +0000",
11    "date_time_unix": 1766573216.682,
12    "time_24": "10:46:56",
13    "time_12": "10:46:56 AM",
14    "week": 52,
15    "month": 12,
16    "year": 2025,
17    "year_abbr": "25",
18    "is_dst": false,
19    "dst_savings": 0,
20    "dst_exists": true,
21    "dst_start": {
22      "utc_time": "2025-03-30 TIME 01",
23      "duration": "+1H",
24      "gap": true,
25      "date_time_after": "2025-03-30 TIME 02",
26      "date_time_before": "2025-03-30 TIME 01",
27      "overlap": false
28    },
29    "dst_end": {
30      "utc_time": "2025-10-26 TIME 01",
31      "duration": "-1H",
32      "gap": false,
33      "date_time_after": "2025-10-26 TIME 01",
34      "date_time_before": "2025-10-26 TIME 02",
35      "overlap": true
36    }
37  }
38}

3.Get Timezone from Any Address

time_zone_opts = {
    location: "Munich, Germany"
}
time_zone_instance = IpgeolocationSdk::TimezoneApi.new
begin
    result = time_zone_instance.get_timezone_info(time_zone_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling TimezoneApi: #{e}"
end

Sample Response

Response
1{
2  "location": {
3    "location_string": "Munich, Germany",
4    "country_name": "Germany",
5    "state_prov": "Bavaria",
6    "city": "Munich",
7    "locality": "",
8    "latitude": "48.13711",
9    "longitude": "11.57538"
10  },
11  "time_zone": {
12    "name": "Europe/Berlin",
13    "offset": 1,
14    "offset_with_dst": 1,
15    "date": "2025-12-24",
16    "date_time": "2025-12-24 11:47:59",
17    "date_time_txt": "Wednesday, December 24, 2025 11:47:59",
18    "date_time_wti": "Wed, 24 Dec 2025 11:47:59 +0100",
19    "date_time_ymd": "2025-12-24 11:47:59 +0100",
20    "date_time_unix": 1766573279.493,
21    "time_24": "11:47:59",
22    "time_12": "11:47:59 AM",
23    "week": 52,
24    "month": 12,
25    "year": 2025,
26    "year_abbr": "25",
27    "is_dst": false,
28    "dst_savings": 0,
29    "dst_exists": true,
30    "dst_start": {
31      "utc_time": "2025-03-30 TIME 01",
32      "duration": "+1H",
33      "gap": true,
34      "date_time_after": "2025-03-30 TIME 03",
35      "date_time_before": "2025-03-30 TIME 02",
36      "overlap": false
37    },
38    "dst_end": {
39      "utc_time": "2025-10-26 TIME 01",
40      "duration": "-1H",
41      "gap": false,
42      "date_time_after": "2025-10-26 TIME 02",
43      "date_time_before": "2025-10-26 TIME 03",
44      "overlap": true
45    }
46  }
47}

4.Get Timezone from Location Coordinates

time_zone_opts = {
    lat: 48.13711,
    long: 11.57538
}
time_zone_instance = IpgeolocationSdk::TimezoneApi.new
begin
    result = time_zone_instance.get_timezone_info(time_zone_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling TimezoneApi: #{e}"
end

Sample Response

Response
1{
2  "time_zone": {
3    "name": "Europe/Berlin",
4    "offset": 1,
5    "offset_with_dst": 1,
6    "date": "2025-12-24",
7    "date_time": "2025-12-24 11:48:52",
8    "date_time_txt": "Wednesday, December 24, 2025 11:48:52",
9    "date_time_wti": "Wed, 24 Dec 2025 11:48:52 +0100",
10    "date_time_ymd": "2025-12-24 11:48:52 +0100",
11    "date_time_unix": 1766573332.887,
12    "time_24": "11:48:52",
13    "time_12": "11:48:52 AM",
14    "week": 52,
15    "month": 12,
16    "year": 2025,
17    "year_abbr": "25",
18    "is_dst": false,
19    "dst_savings": 0,
20    "dst_exists": true,
21    "dst_start": {
22      "utc_time": "2025-03-30 TIME 01",
23      "duration": "+1H",
24      "gap": true,
25      "date_time_after": "2025-03-30 TIME 03",
26      "date_time_before": "2025-03-30 TIME 02",
27      "overlap": false
28    },
29    "dst_end": {
30      "utc_time": "2025-10-26 TIME 01",
31      "duration": "-1H",
32      "gap": false,
33      "date_time_after": "2025-10-26 TIME 02",
34      "date_time_before": "2025-10-26 TIME 03",
35      "overlap": true
36    }
37  }
38}

5.Get Timezone and Airport Details from IATA Code

time_zone_opts = {
    iata_code: "ZRH"
}
time_zone_instance = IpgeolocationSdk::TimezoneApi.new
begin
    result = time_zone_instance.get_timezone_info(time_zone_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling TimezoneApi: #{e}"
end

Sample Response

Response
1{
2  "airport_details": {
3    "type": "large_airport",
4    "name": "Zurich Airport",
5    "latitude": "47.45806",
6    "longitude": "8.54806",
7    "elevation_ft": 1417,
8    "continent_code": "EU",
9    "country_code": "CH",
10    "state_code": "CH-ZH",
11    "city": "Zurich",
12    "iata_code": "ZRH",
13    "icao_code": "LSZH",
14    "faa_code": ""
15  },
16  "time_zone": {
17    "name": "Europe/Zurich",
18    "offset": 1,
19    "offset_with_dst": 1,
20    "date": "2025-12-24",
21    "date_time": "2025-12-24 11:49:56",
22    "date_time_txt": "Wednesday, December 24, 2025 11:49:56",
23    "date_time_wti": "Wed, 24 Dec 2025 11:49:56 +0100",
24    "date_time_ymd": "2025-12-24 11:49:56 +0100",
25    "date_time_unix": 1766573396.338,
26    "time_24": "11:49:56",
27    "time_12": "11:49:56 AM",
28    "week": 52,
29    "month": 12,
30    "year": 2025,
31    "year_abbr": "25",
32    "is_dst": false,
33    "dst_savings": 0,
34    "dst_exists": true,
35    "dst_start": {
36      "utc_time": "2025-03-30 TIME 01",
37      "duration": "+1H",
38      "gap": true,
39      "date_time_after": "2025-03-30 TIME 03",
40      "date_time_before": "2025-03-30 TIME 02",
41      "overlap": false
42    },
43    "dst_end": {
44      "utc_time": "2025-10-26 TIME 01",
45      "duration": "-1H",
46      "gap": false,
47      "date_time_after": "2025-10-26 TIME 02",
48      "date_time_before": "2025-10-26 TIME 03",
49      "overlap": true
50    }
51  }
52}

Similarly, you can fetch Airport Details and Timezone from using any ICAO code ( icao_code ) as well.


6.Get Timezone and City Details from UN/LOCODE

time_zone_opts = {
    lo_code: "ESBCN"
}
time_zone_instance = IpgeolocationSdk::TimezoneApi.new
begin
    result = time_zone_instance.get_timezone_info(time_zone_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling TimezoneApi: #{e}"
end

Sample Response

Response
1{
2  "lo_code_details": {
3    "lo_code": "ESBCN",
4    "city": "Barcelona",
5    "state_code": "",
6    "country_code": "ES",
7    "country_name": "",
8    "location_type": "Port, Rail Terminal, Road Terminal, Airport, Postal Exchange",
9    "latitude": "41.38289",
10    "longitude": "2.17743"
11  },
12  "time_zone": {
13    "name": "Europe/Madrid",
14    "offset": 1,
15    "offset_with_dst": 1,
16    "date": "2025-12-24",
17    "date_time": "2025-12-24 11:51:22",
18    "date_time_txt": "Wednesday, December 24, 2025 11:51:22",
19    "date_time_wti": "Wed, 24 Dec 2025 11:51:22 +0100",
20    "date_time_ymd": "2025-12-24 11:51:22 +0100",
21    "date_time_unix": 1766573482.037,
22    "time_24": "11:51:22",
23    "time_12": "11:51:22 AM",
24    "week": 52,
25    "month": 12,
26    "year": 2025,
27    "year_abbr": "25",
28    "is_dst": false,
29    "dst_savings": 0,
30    "dst_exists": true,
31    "dst_start": {
32      "utc_time": "2025-03-30 TIME 01",
33      "duration": "+1H",
34      "gap": true,
35      "date_time_after": "2025-03-30 TIME 03",
36      "date_time_before": "2025-03-30 TIME 02",
37      "overlap": false
38    },
39    "dst_end": {
40      "utc_time": "2025-10-26 TIME 01",
41      "duration": "-1H",
42      "gap": false,
43      "date_time_after": "2025-10-26 TIME 02",
44      "date_time_before": "2025-10-26 TIME 03",
45      "overlap": true
46    }
47  }
48}

Timezone Converter Examples

This section provides usage examples of the convert_time_between_timezones() method from the SDK. The Timezone Converter API allows you to convert a specific time from one timezone to another using timezone identifiers and optional date/time inputs.

For more details, refer to official documentation: Timezone Converter API.


1.Convert Current Time from One Timezone to Another

time_conversion_opts = {
    tz_to: 'Asia/Tokyo',
    tz_from: 'America/New_York',
    # lat_from: 24.8607,
    # long_from: 67.0011,
    # lat_to: 40.7128,
    # long_to: -74.0060,
    # location_from: 'Karachi',
    # location_to: 'New York',
    # icao_from: 'OPKC',
    # icao_to: 'KJFK',
    # iata_from: 'KHI',
    # iata_to: 'JFK',
    # locode_from: 'PKKHI',
    # locode_to: 'USNYC'
}
time_conversion_instance = IpgeolocationSdk::TimeConversionApi.new
begin
  result = time_conversion_instance.convert_time_between_timezones(time_conversion_opts)
  puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
  puts "Error calling TimeConversionApi: #{e}"
end

Sample Response

Response
1{
2  "original_time": "2025-12-24 05:52:21 +0500",
3  "converted_time": "2025-12-24 19:52:21 +0500",
4  "diff_hour": 14.0,
5  "diff_min": 840
6}

Similarly, you can convert time from any timezone to another timezone using location coordinates (Latitude and Longitude), location addresses, IATA codes, ICAO codes and UN/LOCODE.


User Agent API Examples

This section provides usage examples of the get_user_agent_details() method from the SDK. The User Agent API extracts and classifies information from user agent strings, including browser, engine, device, OS, and type metadata.

For full explanation, visit the User Agent API documentation.


1.Parse a Basic User Agent String

get_user_agent_opts = {
    user_agent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/237.84.2.178 Safari/537.36'
}
user_agent_instance = IpgeolocationSdk::UserAgentApi.new
begin
    result = user_agent_instance.get_user_agent_details(get_user_agent_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling UserAgentApi: #{e}"
end

Sample Response

Response
1{
2  "user_agent_string": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/237.84.2.178 Safari/537.36",
3  "name": "Chrome",
4  "type": "Browser",
5  "version": "237.84.2.178",
6  "version_major": "237",
7  "device": {
8    "name": "Desktop",
9    "type": "Desktop",
10    "brand": "Unknown",
11    "cpu": "Intel x86_64"
12  },
13  "engine": {
14    "name": "Blink",
15    "type": "Browser",
16    "version": "237.84",
17    "version_major": "237"
18  },
19  "operating_system": {
20    "name": "Windows NT",
21    "type": "Desktop",
22    "version": ">=10",
23    "version_major": ">=10",
24    "build": "??"
25  }
26}

If you don't pass any userAgentString, the API will return the data of device's user agent.


2.Bulk User Agent Parsing Example

The SDK also supports bulk User Agent parsing using the parse_bulk_user_agent_strings() method. This allows parsing multiple user agent strings in a single request. All fields available in single-user-agent parsing are returned per entry.

post_user_agent_opts = {
  user_agents: [
    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/237.84.2.178 Safari/537.36",
    "Mozilla/5.0 (Linux; U; en-US) AppleWebKit/528.5+ (KHTML, like Gecko, Safari/528.5+) Version/4.0 Kindle/3.0 (screen 600x800; rotate)"
  ]
}
user_agent_instance = IpgeolocationSdk::UserAgentApi.new
begin
  result = user_agent_instance.parse_bulk_user_agent_strings(post_user_agent_opts)
  result.each do |item|
    puts item.to_hash.to_json
  end
rescue IpgeolocationSdk::ApiError => e
  puts "Error calling UserAgentApi: #{e}"
end

Astronomy API Examples

This section provides usage examples of the get_astronomy_details() method from the SDK, allowing developers to fetch sun and moon timings and position data based on coordinates, IP, or location string.

Refer to the official Astronomy API documentation for more details.


1.Lookup Astronomy API by Coordinates

get_astronomy_opts = {
    lat: "40.7128",
    long: "-74.0060"
}
astronomy_instance = IpgeolocationSdk::AstronomyApi.new
begin
    result = astronomy_instance.get_astronomy_details(get_astronomy_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling AstronomyApi: #{e}"
end

Sample Response

Response
1{
2  "location": {
3    "country_name": "United States",
4    "state_prov": "New York",
5    "city": "New York City",
6    "locality": "",
7    "latitude": "40.71280",
8    "longitude": "-74.00600",
9    "elevation": "6"
10  },
11  "astronomy": {
12    "date": "2025-12-24",
13    "current_time": "07:56:54.527",
14    "mid_night": "23:56",
15    "night_end": "05:39",
16    "morning": {
17      "astronomical_twilight_begin": "05:39",
18      "astronomical_twilight_end": "06:12",
19      "nautical_twilight_begin": "06:12",
20      "nautical_twilight_end": "06:47",
21      "civil_twilight_begin": "06:47",
22      "civil_twilight_end": "07:17",
23      "blue_hour_begin": "06:35",
24      "blue_hour_end": "06:58",
25      "golden_hour_begin": "06:58",
26      "golden_hour_end": "08:01"
27    },
28    "sunrise": "07:17",
29    "sunset": "16:34",
30    "evening": {
31      "golden_hour_begin": "15:50",
32      "golden_hour_end": "16:52",
33      "blue_hour_begin": "16:52",
34      "blue_hour_end": "17:16",
35      "civil_twilight_begin": "16:34",
36      "civil_twilight_end": "17:04",
37      "nautical_twilight_begin": "17:04",
38      "nautical_twilight_end": "17:39",
39      "astronomical_twilight_begin": "17:39",
40      "astronomical_twilight_end": "18:12"
41    },
42    "night_begin": "18:12",
43    "sun_status": "-",
44    "solar_noon": "11:55",
45    "day_length": "09:16",
46    "sun_altitude": 5.265772362659565,
47    "sun_distance": 147152401.29833597,
48    "sun_azimuth": 127.26720409145577,
49    "moon_phase": "WAXING_CRESCENT",
50    "moonrise": "10:24",
51    "moonset": "21:09",
52    "moon_status": "-",
53    "moon_altitude": -27.021042229442685,
54    "moon_distance": 390396.0648657473,
55    "moon_azimuth": 87.02257245596411,
56    "moon_parallactic_angle": -51.64698459434443,
57    "moon_illumination_percentage": "18.22",
58    "moon_angle": 50.53259996734376
59  }
60}

2.Lookup Astronomy API by IP Address

get_astronomy_opts = {
    ip: "8.8.8.8"
}
astronomy_instance = IpgeolocationSdk::AstronomyApi.new
begin
    result = astronomy_instance.get_astronomy_details(get_astronomy_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling AstronomyApi: #{e}"
end

Sample Response

Response
1{
2  "ip": "8.8.8.8",
3  "location": {
4    "continent_code": "NA",
5    "continent_name": "North America",
6    "country_code2": "US",
7    "country_code3": "USA",
8    "country_name": "United States",
9    "country_name_official": "United States of America",
10    "is_eu": false,
11    "state_prov": "California",
12    "state_code": "US-CA",
13    "district": "Santa Clara",
14    "city": "Mountain View",
15    "locality": "Charleston Terrace",
16    "zipcode": "94043-1351",
17    "latitude": "37.42240",
18    "longitude": "-122.08421",
19    "elevation": "3"
20  },
21  "astronomy": {
22    "date": "2025-12-24",
23    "current_time": "04:58:05.179",
24    "mid_night": "00:07",
25    "night_end": "05:46",
26    "morning": {
27      "astronomical_twilight_begin": "05:46",
28      "astronomical_twilight_end": "06:18",
29      "nautical_twilight_begin": "06:18",
30      "nautical_twilight_end": "06:51",
31      "civil_twilight_begin": "06:51",
32      "civil_twilight_end": "07:20",
33      "blue_hour_begin": "06:40",
34      "blue_hour_end": "07:02",
35      "golden_hour_begin": "07:02",
36      "golden_hour_end": "08:01"
37    },
38    "sunrise": "07:20",
39    "sunset": "16:56",
40    "evening": {
41      "golden_hour_begin": "16:15",
42      "golden_hour_end": "17:13",
43      "blue_hour_begin": "17:13",
44      "blue_hour_end": "17:36",
45      "civil_twilight_begin": "16:56",
46      "civil_twilight_end": "17:25",
47      "nautical_twilight_begin": "17:25",
48      "nautical_twilight_end": "17:57",
49      "astronomical_twilight_begin": "17:57",
50      "astronomical_twilight_end": "18:29"
51    },
52    "night_begin": "18:29",
53    "sun_status": "-",
54    "solar_noon": "12:08",
55    "day_length": "09:35",
56    "sun_altitude": -27.417802893936713,
57    "sun_distance": 147152401.298336,
58    "sun_azimuth": 99.58317083105555,
59    "moon_phase": "WAXING_CRESCENT",
60    "moonrise": "10:34",
61    "moonset": "21:35",
62    "moon_status": "-",
63    "moon_altitude": -61.87418215314708,
64    "moon_distance": 390392.88359927345,
65    "moon_azimuth": 42.79081112532475,
66    "moon_parallactic_angle": -33.98006664201916,
67    "moon_illumination_percentage": "18.22",
68    "moon_angle": 50.54213695165953
69  }
70}

3.Lookup Astronomy API by Location String

get_astronomy_opts = {
    location: "Milan, Italy"
}
astronomy_instance = IpgeolocationSdk::AstronomyApi.new
begin
    result = astronomy_instance.get_astronomy_details(get_astronomy_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling AstronomyApi: #{e}"
end

Sample Response

Response
1{
2  "location": {
3    "location_string": "Milan, Italy",
4    "country_name": "Italy",
5    "state_prov": "Lombardy",
6    "city": "Milan",
7    "locality": "",
8    "latitude": "45.46419",
9    "longitude": "9.18963",
10    "elevation": "122"
11  },
12  "astronomy": {
13    "date": "2025-12-24",
14    "current_time": "13:59:22.914",
15    "mid_night": "00:22",
16    "night_end": "06:13",
17    "morning": {
18      "astronomical_twilight_begin": "06:13",
19      "astronomical_twilight_end": "06:49",
20      "nautical_twilight_begin": "06:49",
21      "nautical_twilight_end": "07:27",
22      "civil_twilight_begin": "07:27",
23      "civil_twilight_end": "07:59",
24      "blue_hour_begin": "07:14",
25      "blue_hour_end": "07:40",
26      "golden_hour_begin": "07:40",
27      "golden_hour_end": "08:51"
28    },
29    "sunrise": "07:59",
30    "sunset": "16:47",
31    "evening": {
32      "golden_hour_begin": "15:54",
33      "golden_hour_end": "17:05",
34      "blue_hour_begin": "17:05",
35      "blue_hour_end": "17:31",
36      "civil_twilight_begin": "16:47",
37      "civil_twilight_end": "17:18",
38      "nautical_twilight_begin": "17:18",
39      "nautical_twilight_end": "17:56",
40      "astronomical_twilight_begin": "17:56",
41      "astronomical_twilight_end": "18:32"
42    },
43    "night_begin": "18:32",
44    "sun_status": "-",
45    "solar_noon": "12:22",
46    "day_length": "08:47",
47    "sun_altitude": 17.723499498755025,
48    "sun_distance": 147152401.298336,
49    "sun_azimuth": 203.16933384107605,
50    "moon_phase": "WAXING_CRESCENT",
51    "moonrise": "10:55",
52    "moonset": "21:13",
53    "moon_status": "-",
54    "moon_altitude": 23.979142365657644,
55    "moon_distance": 390389.38303958566,
56    "moon_azimuth": 149.16011529114445,
57    "moon_parallactic_angle": -21.867682703140048,
58    "moon_illumination_percentage": "18.23",
59    "moon_angle": 50.55263020105739
60  }
61}

4.Lookup Astronomy API for a Specific Date

get_astronomy_opts = {
    date: "2025-01-01",
    lat: "-27.47000",
    long: "153.02000"
}
astronomy_instance = IpgeolocationSdk::AstronomyApi.new
begin
    result = astronomy_instance.get_astronomy_details(get_astronomy_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling AstronomyApi: #{e}"
end

Sample Response

Response
1{
2  "location": {
3    "country_name": "Australia",
4    "state_prov": "Queensland",
5    "city": "Brisbane",
6    "locality": "Brisbane",
7    "latitude": "-27.47000",
8    "longitude": "153.02000",
9    "elevation": ""
10  },
11  "astronomy": {
12    "date": "2025-01-01",
13    "current_time": "23:00:08.526",
14    "mid_night": "23:51",
15    "night_end": "03:24",
16    "morning": {
17      "astronomical_twilight_begin": "03:24",
18      "astronomical_twilight_end": "03:57",
19      "nautical_twilight_begin": "03:57",
20      "nautical_twilight_end": "04:29",
21      "civil_twilight_begin": "04:29",
22      "civil_twilight_end": "04:56",
23      "blue_hour_begin": "04:19",
24      "blue_hour_end": "04:40",
25      "golden_hour_begin": "04:40",
26      "golden_hour_end": "05:30"
27    },
28    "sunrise": "04:56",
29    "sunset": "18:46",
30    "evening": {
31      "golden_hour_begin": "18:12",
32      "golden_hour_end": "19:02",
33      "blue_hour_begin": "19:02",
34      "blue_hour_end": "19:23",
35      "civil_twilight_begin": "18:46",
36      "civil_twilight_end": "19:13",
37      "nautical_twilight_begin": "19:13",
38      "nautical_twilight_end": "19:45",
39      "astronomical_twilight_begin": "19:45",
40      "astronomical_twilight_end": "20:18"
41    },
42    "night_begin": "20:18",
43    "sun_status": "-",
44    "solar_noon": "11:51",
45    "day_length": "13:50",
46    "sun_altitude": -38.0693479495629,
47    "sun_distance": 147102938.88036567,
48    "sun_azimuth": 195.11207186624287,
49    "moon_phase": "NEW_MOON",
50    "moonrise": "05:42",
51    "moonset": "20:08",
52    "moon_status": "-",
53    "moon_altitude": -28.36071812453645,
54    "moon_distance": 380161.8657228659,
55    "moon_azimuth": 216.5169650698993,
56    "moon_parallactic_angle": 144.6623797008263,
57    "moon_illumination_percentage": "2.97",
58    "moon_angle": 19.851650971629937
59  }
60}

5.Lookup Location info in Different Language

You can also get Astronomy Data in other languages as well. Only paid subscriptions can access this feature.

get_astronomy_opts = {
    ip: "1.1.1.1",
    lang: "fr"
}
astronomy_instance = IpgeolocationSdk::AstronomyApi.new
begin
    result = astronomy_instance.get_astronomy_details(get_astronomy_opts)
    puts result.to_hash.to_json
rescue IpgeolocationSdk::ApiError => e
    puts "Error calling AstronomyApi: #{e}"
end

Sample Response

Response
1{
2  "ip": "1.1.1.1",
3  "location": {
4    "continent_code": "AS",
5    "continent_name": "Asie",
6    "country_code2": "HK",
7    "country_code3": "HKG",
8    "country_name": "Hong Kong",
9    "country_name_official": "",
10    "is_eu": false,
11    "state_prov": "Hong Kong Island",
12    "state_code": "",
13    "district": "",
14    "city": "Hong Kong",
15    "locality": "Soho",
16    "zipcode": "",
17    "latitude": "22.27683",
18    "longitude": "114.17612",
19    "elevation": ""
20  },
21  "astronomy": {
22    "date": "2025-12-24",
23    "mid_night": "00:22",
24    "...": "...",
25    "moon_angle": 50.57019974247744
26  }
27}

Documentation for Models

Subscribe Our Newsletter

Get the latest in geolocation tech, straight to your inbox.