ip-api-io 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 76f9eb0fbe4f73944dc67a95f4ab308518ec21ddc45a42d339d262c3d06a3e2d
4
+ data.tar.gz: 77b408c2f71dd4353a8a7f92188e5bd1ddfb593039c8932d952313d2b9bfb634
5
+ SHA512:
6
+ metadata.gz: e282e89c5e72ee6c4e8bbbd9d65a4d98c507f0782924d8b223f0630858d28ea6e900083121d0350c160f76770540b39057dc69e2d4c25520ad4cd92f8928220e
7
+ data.tar.gz: 5d28ce14fd0bcf17a009a09a3917df78bec8e8bae124dc5648f9ffd767a7fce47db659bf1699e8f46dc8b3cc8f3d6a167473dae2fe8ece3d72a386208a268277
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
5
+
6
+ ## [1.0.0] - 2026-06-12
7
+
8
+ ### Added
9
+ - Initial release: full client for the ip-api.io v1 API — IP geolocation and
10
+ threat intelligence (single + batch), email validation (basic, advanced,
11
+ batch), risk scoring, IP reputation, Tor detection, ASN lookup, WHOIS,
12
+ reverse/forward DNS, MX records, domain age (single + batch), rate limit
13
+ and usage info.
14
+ - Typed errors (`AuthenticationError`, `RateLimitError` with x-ratelimit
15
+ header values, `InvalidRequestError`, `ServerError`).
16
+ - Zero runtime dependencies (stdlib `net/http`).
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ip-api.io
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # ip-api-io — Official Ruby client for [ip-api.io](https://ip-api.io)
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/ip-api-io)](https://rubygems.org/gems/ip-api-io)
4
+ [![test](https://github.com/ip-api-io/ipapi-ruby/actions/workflows/test.yml/badge.svg)](https://github.com/ip-api-io/ipapi-ruby/actions/workflows/test.yml)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
6
+
7
+ The official Ruby client for the [ip-api.io](https://ip-api.io) IP intelligence
8
+ platform. One client covers [IP geolocation](https://ip-api.io/what-is-my-ip),
9
+ [email validation](https://ip-api.io/email-validation) and [verification](https://ip-api.io/email-verification-api)
10
+ (syntax, MX, SMTP deliverability), [fraud detection](https://ip-api.io/fraud-detection-api)
11
+ and [risk scoring](https://ip-api.io/risk-score),
12
+ [VPN](https://ip-api.io/vpn-detection-api)/[proxy](https://ip-api.io/proxy-detection-api)/[Tor detection](https://ip-api.io/tor-detection),
13
+ [disposable email detection](https://ip-api.io/disposable-email-checker), [ASN lookup](https://ip-api.io/asn-lookup),
14
+ [WHOIS](https://ip-api.io/whois-lookup), [reverse DNS](https://ip-api.io/reverse-dns-lookup),
15
+ [MX records](https://ip-api.io/mx-record-lookup) and [domain age](https://ip-api.io/domain-age-checker).
16
+
17
+ Zero runtime dependencies — pure standard library.
18
+
19
+ ## Install
20
+
21
+ ```bash
22
+ gem install ip-api-io
23
+ ```
24
+
25
+ or in your Gemfile:
26
+
27
+ ```ruby
28
+ gem "ip-api-io"
29
+ ```
30
+
31
+ ## Quickstart
32
+
33
+ ```ruby
34
+ require "ip-api-io"
35
+
36
+ client = IpApiIo::Client.new(api_key: "YOUR_API_KEY") # free key at https://ip-api.io
37
+
38
+ # Where is this IP, and is it risky?
39
+ info = client.lookup("8.8.8.8")
40
+ puts info["location"]["country"] # "United States"
41
+ puts info["suspicious_factors"]["is_vpn"] # false
42
+
43
+ risk = client.risk_score("8.8.8.8")
44
+ puts "#{risk['score']} #{risk['risk_level']}" # 0 low
45
+
46
+ email = client.validate_email("user@example.com")
47
+ puts "#{email['reachable']} #{email['disposable']}" # yes false
48
+ ```
49
+
50
+ An API key is required — the API rejects keyless requests with `401`. Sign up at
51
+ [ip-api.io](https://ip-api.io) for a free key.
52
+
53
+ ## Documentation
54
+
55
+ Each guide documents the methods for one capability, with runnable examples and a link
56
+ to the matching ip-api.io product page:
57
+
58
+ - **[IP geolocation & bulk lookup](docs/ip-geolocation.md)** — `lookup`, `lookup_batch`
59
+ - **[Email validation & verification](docs/email-validation.md)** — `email_info`, `validate_email`, `validate_email_batch`
60
+ - **[Fraud detection & risk scoring](docs/fraud-risk-scoring.md)** — `risk_score`, `email_risk_score`, `ip_reputation`
61
+ - **[VPN, proxy & Tor detection](docs/vpn-proxy-tor.md)** — `tor_check`, `suspicious_factors`
62
+ - **[ASN & DNS lookups](docs/asn-and-dns.md)** — `asn`, `whois`, `reverse_dns`, `forward_dns`, `mx_records`
63
+ - **[Domain age checker](docs/domain-age.md)** — `domain_age`, `domain_age_batch`
64
+ - **[Errors, rate limits & usage](docs/error-handling.md)** — error types, `rate_limit`, `usage_summary`
65
+
66
+ ## Methods
67
+
68
+ Every method maps to one ip-api.io endpoint and its product page:
69
+
70
+ | Method | Endpoint | Product page |
71
+ |---|---|---|
72
+ | `lookup(ip = nil)` | `GET /api/v1/ip[/{ip}]` | [IP geolocation](https://ip-api.io/what-is-my-ip) |
73
+ | `lookup_batch(ips)` | `POST /api/v1/ip/batch` (≤100 IPs) | [Bulk IP lookup](https://ip-api.io/bulk-ip-lookup) |
74
+ | `email_info(email)` | `GET /api/v1/email/{email}` | [Email validation](https://ip-api.io/email-validation) |
75
+ | `validate_email(email)` | `GET /api/v1/email/advanced/{email}` | [Advanced email validation](https://ip-api.io/advanced-email-validation) |
76
+ | `validate_email_batch(emails)` | `POST /api/v1/email/advanced/batch` (≤100) | [Email list cleaning](https://ip-api.io/email-list-cleaning) |
77
+ | `risk_score(ip = nil)` | `GET /api/v1/risk-score[/{ip}]` | [Risk score](https://ip-api.io/risk-score) |
78
+ | `email_risk_score(email)` | `GET /api/v1/risk-score/email/{email}` | [Fraud detection](https://ip-api.io/fraud-detection-api) |
79
+ | `ip_reputation(ip)` | `GET /api/v1/ip-reputation/{ip}` | [IP reputation](https://ip-api.io/ip-reputation) |
80
+ | `tor_check(ip)` | `GET /api/v1/tor/{ip}` | [Tor detection](https://ip-api.io/tor-detection) |
81
+ | `asn(ip)` | `GET /api/v1/asn/{ip}` | [ASN lookup](https://ip-api.io/asn-lookup) |
82
+ | `whois(domain)` | `GET /api/v1/dns/whois/{domain}` | [WHOIS lookup](https://ip-api.io/whois-lookup) |
83
+ | `reverse_dns(ip)` | `GET /api/v1/dns/reverse/{ip}` | [Reverse DNS](https://ip-api.io/reverse-dns-lookup) |
84
+ | `forward_dns(hostname)` | `GET /api/v1/dns/forward/{hostname}` | — |
85
+ | `mx_records(domain)` | `GET /api/v1/dns/mx/{domain}` | [MX record lookup](https://ip-api.io/mx-record-lookup) |
86
+ | `domain_age(domain)` | `GET /api/v1/domain/age/{domain}` | [Domain age checker](https://ip-api.io/domain-age-checker) |
87
+ | `domain_age_batch(domains)` | `POST /api/v1/domain/age/batch` | [Domain age checker](https://ip-api.io/domain-age-checker) |
88
+ | `rate_limit` | `GET /api/v1/ratelimit` | — |
89
+ | `usage_summary` | `GET /api/v1/usage/summary` | — |
90
+
91
+ All methods return parsed JSON as plain Hashes.
92
+
93
+ ## Error handling
94
+
95
+ The client raises typed errors and **never retries** — on `429`,
96
+ `RateLimitError#reset` tells you when your quota renews:
97
+
98
+ ```ruby
99
+ begin
100
+ client.lookup("8.8.8.8")
101
+ rescue IpApiIo::RateLimitError => e
102
+ puts "limit=#{e.limit} remaining=#{e.remaining} resets_at=#{e.reset}"
103
+ rescue IpApiIo::AuthenticationError
104
+ puts "invalid API key"
105
+ end
106
+ ```
107
+
108
+ See [docs/error-handling.md](docs/error-handling.md) for the full error taxonomy.
109
+
110
+ ## Links
111
+
112
+ - Website: https://ip-api.io
113
+ - API reference: https://ip-api.io/api-docs.html
114
+ - OpenAPI spec: https://ip-api.io/openapi.json
115
+ - Get a free API key: https://ip-api.io
116
+
117
+ ---
118
+
119
+ `ip-api-io` is the official client for [ip-api.io](https://ip-api.io).
120
+ It is not affiliated with ip-api.com or ipapi.com.
data/lib/ip-api-io.rb ADDED
@@ -0,0 +1,3 @@
1
+ require_relative "ipapi_io/version"
2
+ require_relative "ipapi_io/errors"
3
+ require_relative "ipapi_io/client"
@@ -0,0 +1,194 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "uri"
4
+
5
+ require_relative "errors"
6
+ require_relative "version"
7
+
8
+ module IpApiIo
9
+ # Client for the ip-api.io IP intelligence and email validation API.
10
+ #
11
+ # client = IpApiIo::Client.new(api_key: "YOUR_API_KEY")
12
+ # client.lookup("8.8.8.8") #=> { "ip" => "8.8.8.8", "location" => {...}, ... }
13
+ #
14
+ # An API key is required by the live API — get a free key at https://ip-api.io.
15
+ class Client
16
+ BASE_URL = "https://ip-api.io".freeze
17
+ MAX_BATCH_SIZE = 100
18
+
19
+ def initialize(api_key: nil, base_url: BASE_URL, timeout: 10)
20
+ @api_key = api_key
21
+ @base_url = base_url.sub(%r{/+\z}, "")
22
+ @timeout = timeout
23
+ end
24
+
25
+ # -- IP intelligence ------------------------------------------------------
26
+
27
+ # Geolocation + threat intelligence for an IP (or the caller's IP when nil).
28
+ def lookup(ip = nil)
29
+ request(:get, ip ? "/api/v1/ip/#{encode(ip)}" : "/api/v1/ip")
30
+ end
31
+
32
+ # Look up to 100 IP addresses in a single request.
33
+ def lookup_batch(ips)
34
+ check_batch!(ips, "ips")
35
+ request(:post, "/api/v1/ip/batch", body: { ips: ips })
36
+ end
37
+
38
+ def ip_reputation(ip)
39
+ request(:get, "/api/v1/ip-reputation/#{encode(ip)}")
40
+ end
41
+
42
+ def tor_check(ip)
43
+ request(:get, "/api/v1/tor/#{encode(ip)}")
44
+ end
45
+
46
+ def asn(ip)
47
+ request(:get, "/api/v1/asn/#{encode(ip)}")
48
+ end
49
+
50
+ # -- Email validation -------------------------------------------------------
51
+
52
+ # Syntax, disposability and MX analysis of an email address.
53
+ def email_info(email)
54
+ request(:get, "/api/v1/email/#{encode(email)}")
55
+ end
56
+
57
+ # Advanced validation including SMTP deliverability checks.
58
+ def validate_email(email)
59
+ request(:get, "/api/v1/email/advanced/#{encode(email)}")
60
+ end
61
+
62
+ # Advanced-validate up to 100 email addresses in a single request.
63
+ def validate_email_batch(emails)
64
+ check_batch!(emails, "emails")
65
+ request(:post, "/api/v1/email/advanced/batch", body: { emails: emails })
66
+ end
67
+
68
+ # -- Risk scoring -----------------------------------------------------------
69
+
70
+ # Fraud risk score for an IP (or the caller's IP when nil).
71
+ def risk_score(ip = nil)
72
+ request(:get, ip ? "/api/v1/risk-score/#{encode(ip)}" : "/api/v1/risk-score")
73
+ end
74
+
75
+ def email_risk_score(email)
76
+ request(:get, "/api/v1/risk-score/email/#{encode(email)}")
77
+ end
78
+
79
+ # -- DNS & domains ----------------------------------------------------------
80
+
81
+ def whois(domain)
82
+ request(:get, "/api/v1/dns/whois/#{encode(domain)}")
83
+ end
84
+
85
+ def reverse_dns(ip)
86
+ request(:get, "/api/v1/dns/reverse/#{encode(ip)}")
87
+ end
88
+
89
+ def forward_dns(hostname)
90
+ request(:get, "/api/v1/dns/forward/#{encode(hostname)}")
91
+ end
92
+
93
+ def mx_records(domain)
94
+ request(:get, "/api/v1/dns/mx/#{encode(domain)}")
95
+ end
96
+
97
+ def domain_age(domain)
98
+ request(:get, "/api/v1/domain/age/#{encode(domain)}")
99
+ end
100
+
101
+ def domain_age_batch(domains)
102
+ raise ArgumentError, "domains must not be empty" if domains.empty?
103
+
104
+ request(:post, "/api/v1/domain/age/batch", body: { domains: domains })
105
+ end
106
+
107
+ # -- Account ----------------------------------------------------------------
108
+
109
+ def rate_limit
110
+ request(:get, "/api/v1/ratelimit")
111
+ end
112
+
113
+ def usage_summary
114
+ request(:get, "/api/v1/usage/summary")
115
+ end
116
+
117
+ private
118
+
119
+ def encode(value)
120
+ URI.encode_uri_component(value.to_s)
121
+ end
122
+
123
+ def check_batch!(items, name)
124
+ raise ArgumentError, "#{name} must not be empty" if items.empty?
125
+ raise ArgumentError, "#{name} must contain at most #{MAX_BATCH_SIZE} items" if items.size > MAX_BATCH_SIZE
126
+ end
127
+
128
+ def request(method, path, body: nil)
129
+ uri = URI("#{@base_url}#{path}")
130
+ uri.query = URI.encode_www_form(api_key: @api_key) if @api_key
131
+
132
+ http = Net::HTTP.new(uri.host, uri.port)
133
+ http.use_ssl = uri.scheme == "https"
134
+ http.open_timeout = @timeout
135
+ http.read_timeout = @timeout
136
+
137
+ klass = method == :post ? Net::HTTP::Post : Net::HTTP::Get
138
+ req = klass.new(uri)
139
+ req["User-Agent"] = USER_AGENT
140
+ req["Accept"] = "application/json"
141
+ if body
142
+ req["Content-Type"] = "application/json"
143
+ req.body = JSON.generate(body)
144
+ end
145
+
146
+ response = http.request(req)
147
+ return parse_body(response.body) if response.is_a?(Net::HTTPSuccess)
148
+
149
+ raise error_for(response)
150
+ end
151
+
152
+ def parse_body(raw)
153
+ raw.nil? || raw.empty? ? nil : JSON.parse(raw)
154
+ end
155
+
156
+ def error_for(response)
157
+ status = response.code.to_i
158
+ raw = response.body.to_s
159
+ message = begin
160
+ parsed = JSON.parse(raw)
161
+ parsed.is_a?(Hash) ? (parsed["message"] || parsed["error"]).to_s : ""
162
+ rescue JSON::ParserError
163
+ raw.strip[0, 200]
164
+ end
165
+ message = "HTTP #{status} from ip-api.io" if message.empty?
166
+
167
+ case status
168
+ when 401, 403
169
+ AuthenticationError.new(message, status_code: status, body: raw)
170
+ when 429
171
+ RateLimitError.new(
172
+ message,
173
+ body: raw,
174
+ limit: header_int(response, "x-ratelimit-limit"),
175
+ remaining: header_int(response, "x-ratelimit-remaining"),
176
+ reset: header_int(response, "x-ratelimit-reset")
177
+ )
178
+ when 400, 404, 422
179
+ InvalidRequestError.new(message, status_code: status, body: raw)
180
+ when 500..599
181
+ ServerError.new(message, status_code: status, body: raw)
182
+ else
183
+ Error.new(message, status_code: status, body: raw)
184
+ end
185
+ end
186
+
187
+ def header_int(response, name)
188
+ value = response[name]
189
+ Integer(value, 10)
190
+ rescue ArgumentError, TypeError
191
+ nil
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,34 @@
1
+ module IpApiIo
2
+ # Base error for all ip-api.io client failures.
3
+ class Error < StandardError
4
+ attr_reader :status_code, :body
5
+
6
+ def initialize(message, status_code: nil, body: nil)
7
+ super(message)
8
+ @status_code = status_code
9
+ @body = body
10
+ end
11
+ end
12
+
13
+ # HTTP 401/403 — missing or invalid API key.
14
+ class AuthenticationError < Error; end
15
+
16
+ # HTTP 429 — quota exhausted. Exposes the x-ratelimit-* response headers;
17
+ # +reset+ is the unix timestamp when the quota renews. The client never retries.
18
+ class RateLimitError < Error
19
+ attr_reader :limit, :remaining, :reset
20
+
21
+ def initialize(message, status_code: 429, body: nil, limit: nil, remaining: nil, reset: nil)
22
+ super(message, status_code: status_code, body: body)
23
+ @limit = limit
24
+ @remaining = remaining
25
+ @reset = reset
26
+ end
27
+ end
28
+
29
+ # HTTP 400/404/422 — malformed input or unknown resource.
30
+ class InvalidRequestError < Error; end
31
+
32
+ # HTTP 5xx — ip-api.io server-side failure.
33
+ class ServerError < Error; end
34
+ end
@@ -0,0 +1,4 @@
1
+ module IpApiIo
2
+ VERSION = "1.0.0".freeze
3
+ USER_AGENT = "ip-api-io-ruby/#{VERSION}".freeze
4
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ip-api-io
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ip-api.io
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: minitest
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '5.25'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '5.25'
26
+ - !ruby/object:Gem::Dependency
27
+ name: rake
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '13.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '13.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: webmock
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '3.24'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.24'
54
+ description: 'Ruby client for the ip-api.io IP intelligence platform: IP geolocation,
55
+ email validation (syntax, MX, SMTP deliverability), fraud detection and risk scoring,
56
+ VPN/proxy/Tor detection, ASN lookup, WHOIS, reverse/forward DNS and domain age.
57
+ Zero runtime dependencies.'
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - CHANGELOG.md
63
+ - LICENSE
64
+ - README.md
65
+ - lib/ip-api-io.rb
66
+ - lib/ipapi_io/client.rb
67
+ - lib/ipapi_io/errors.rb
68
+ - lib/ipapi_io/version.rb
69
+ homepage: https://ip-api.io
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ homepage_uri: https://ip-api.io
74
+ documentation_uri: https://ip-api.io/docs
75
+ source_code_uri: https://github.com/ip-api-io/ipapi-ruby
76
+ changelog_uri: https://github.com/ip-api-io/ipapi-ruby/blob/main/CHANGELOG.md
77
+ bug_tracker_uri: https://github.com/ip-api-io/ipapi-ruby/issues
78
+ rubygems_mfa_required: 'true'
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '3.1'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubygems_version: 4.0.3
94
+ specification_version: 4
95
+ summary: Official Ruby client for ip-api.io — IP geolocation, email validation, fraud
96
+ detection and risk scoring API
97
+ test_files: []