internetdata 2.20.1 → 3.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 +4 -4
- data/README.md +30 -12
- data/lib/internetdata/api/database_v2_api.rb +1 -1
- data/lib/internetdata/api_client.rb +1 -1
- data/lib/internetdata/api_error.rb +1 -1
- data/lib/internetdata/api_model_base.rb +1 -1
- data/lib/internetdata/asn_result.rb +37 -37
- data/lib/internetdata/cache.rb +6 -6
- data/lib/internetdata/client.rb +99 -58
- data/lib/internetdata/configuration.rb +1 -1
- data/lib/internetdata/domain_result.rb +25 -34
- data/lib/internetdata/errors.rb +21 -1
- data/lib/internetdata/middleware/core.rb +61 -9
- data/lib/internetdata/models/abuse_contact.rb +9 -9
- data/lib/internetdata/models/asn.rb +2 -2
- data/lib/internetdata/models/asn_hosted_domains.rb +2 -2
- data/lib/internetdata/models/asn_lookup_response.rb +20 -30
- data/lib/internetdata/models/asn_prefix.rb +1 -1
- data/lib/internetdata/models/batch_lookup_error.rb +1 -1
- data/lib/internetdata/models/bit_torrent_detail.rb +1 -1
- data/lib/internetdata/models/bot_detail.rb +1 -1
- data/lib/internetdata/models/carrier_detail.rb +1 -1
- data/lib/internetdata/models/class_detail.rb +1 -1
- data/lib/internetdata/models/client_registration.rb +1 -1
- data/lib/internetdata/models/cohosted_domains.rb +2 -2
- data/lib/internetdata/models/company.rb +4 -4
- data/lib/internetdata/models/database.rb +1 -1
- data/lib/internetdata/models/database_checksums_response.rb +1 -1
- data/lib/internetdata/models/database_format.rb +1 -1
- data/lib/internetdata/models/database_list.rb +1 -1
- data/lib/internetdata/models/database_metadata.rb +1 -1
- data/lib/internetdata/models/database_metadata_column.rb +1 -1
- data/lib/internetdata/models/database_version.rb +1 -1
- data/lib/internetdata/models/db_checksums.rb +1 -1
- data/lib/internetdata/models/device_authorization.rb +1 -1
- data/lib/internetdata/models/disposable_detail.rb +1 -1
- data/lib/internetdata/models/dns_address_record.rb +1 -1
- data/lib/internetdata/models/dns_cname_record.rb +1 -1
- data/lib/internetdata/models/dns_mx_record.rb +1 -1
- data/lib/internetdata/models/dns_ns_record.rb +1 -1
- data/lib/internetdata/models/dns_resolver_detail.rb +1 -1
- data/lib/internetdata/models/domain_backlinks.rb +2 -2
- data/lib/internetdata/models/domain_dns.rb +2 -2
- data/lib/internetdata/models/domain_host.rb +1 -1
- data/lib/internetdata/models/domain_ip_range.rb +1 -1
- data/lib/internetdata/models/domain_ip_ranges.rb +2 -2
- data/lib/internetdata/models/domain_lookup_response.rb +6 -16
- data/lib/internetdata/models/domain_redirects.rb +2 -2
- data/lib/internetdata/models/domain_web.rb +2 -2
- data/lib/internetdata/models/domain_web_links.rb +1 -1
- data/lib/internetdata/models/download.rb +1 -1
- data/lib/internetdata/models/download_list.rb +1 -1
- data/lib/internetdata/models/entitlement.rb +1 -1
- data/lib/internetdata/models/entitlement_apikey.rb +1 -1
- data/lib/internetdata/models/entitlement_plan.rb +3 -3
- data/lib/internetdata/models/entitlement_usage.rb +4 -4
- data/lib/internetdata/models/error_envelope.rb +1 -1
- data/lib/internetdata/models/hosted_domains.rb +2 -2
- data/lib/internetdata/models/location.rb +11 -11
- data/lib/internetdata/models/lookup_response.rb +33 -77
- data/lib/internetdata/models/oauth_metadata.rb +1 -1
- data/lib/internetdata/models/proxy_detail.rb +2 -2
- data/lib/internetdata/models/pubproxy_detail.rb +1 -1
- data/lib/internetdata/models/rwhois.rb +2 -2
- data/lib/internetdata/models/satellite_detail.rb +1 -1
- data/lib/internetdata/models/smtp_detail.rb +1 -1
- data/lib/internetdata/models/ssh_detail.rb +1 -1
- data/lib/internetdata/models/standing.rb +1 -1
- data/lib/internetdata/models/token_response.rb +1 -1
- data/lib/internetdata/models/user_agent_verdict.rb +1 -1
- data/lib/internetdata/models/web_detail.rb +1 -1
- data/lib/internetdata/models/whois.rb +2 -2
- data/lib/internetdata/result.rb +72 -70
- data/lib/internetdata/transport.rb +6 -6
- data/lib/internetdata/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 126b0136f922a39d089527459ef9a1892c908f6c5cab8d596bcef8ec1dce74fe
|
|
4
|
+
data.tar.gz: 1f7960503b7b8864019b9073df1841f9dec53a5fe7de67c3ae92c0d6b5125537
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d45135ee843772f0133ae4df875b143f32fb21cc5d4e64a679716ba1bb75b87c6f76cc511f9485703ab854ca349b7ba0a8605afc8ca31caec25e72512a1bfdb1
|
|
7
|
+
data.tar.gz: c9c921c4652811409504d4d881fe88e794d281aef7ab155061d89c34db91bcdb17971c4a9277a9d04e352cfeb0d5865e122f046eee19ea7f263969c48ab54350
|
data/README.md
CHANGED
|
@@ -23,7 +23,7 @@ Requires Ruby 3.3 or newer, and libcurl at runtime, which the `curl` package bri
|
|
|
23
23
|
|
|
24
24
|
## Usage
|
|
25
25
|
|
|
26
|
-
**No API key needed to
|
|
26
|
+
**No API key needed to try it.** A lookup without one answers the basics: an address's location, network and reverse DNS, and its Tor, relay and anycast flags. The address's company and its abuse contact are not in the basics: they come with a free key's full answers or a paid plan. A free key answers every field on its organization's first lookups each UTC day, then a lookup raises `quota_exceeded` with the basics ([below](#when-the-allowance-is-used-up)).
|
|
27
27
|
|
|
28
28
|
```ruby
|
|
29
29
|
require 'internetdata'
|
|
@@ -38,7 +38,7 @@ result.is_tor # => false
|
|
|
38
38
|
|
|
39
39
|
### With an API key
|
|
40
40
|
|
|
41
|
-
A paid plan answers every field: the VPN, proxy, hosting and CDN flags as well, the detail behind each flag, and an address's city, Whois, RWHOIS and hosted domains. A free
|
|
41
|
+
A paid plan answers every field: the VPN, proxy, hosting and CDN flags as well, the detail behind each flag, and an address's city, Whois, RWHOIS and hosted domains. A free key answers every field on its organization's first lookups each UTC day, then a lookup raises `quota_exceeded` ([below](#when-the-allowance-is-used-up)). Create a key in the [console](https://app.internetdata.io), then pass it in:
|
|
42
42
|
|
|
43
43
|
```ruby
|
|
44
44
|
client = InternetData::Client.new(api_key: ENV['INTERNETDATA_API_KEY'])
|
|
@@ -49,6 +49,22 @@ result.vpn['provider_name'] # => "Mullvad", on a paid plan
|
|
|
49
49
|
result.location['city'] # => "Vienna", on a paid plan
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
+
### When the allowance is used up
|
|
53
|
+
|
|
54
|
+
A key answers every field until its organization's lookups with every field are used up: a free key's for the UTC day, a paid key's quota and then its overage cap. Past that the API keeps answering, with the basics and `cap_reached: true`, so an app reading the answer would run on without the fields it was built on and nobody would notice. From 3.0.0 that lookup raises instead: an `InternetData::Error` of kind `:quota_exceeded`, status 200, never retried, carrying the answer as `result`. No client option turns it off, and catching it is how you carry on:
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
begin
|
|
58
|
+
result = client.lookup('146.70.116.130')
|
|
59
|
+
rescue InternetData::Error => e
|
|
60
|
+
raise unless e.kind == :quota_exceeded && e.result
|
|
61
|
+
|
|
62
|
+
result = e.result # the basics, with cap_reached true
|
|
63
|
+
end
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`lookup`, `my_ip` with a key, `lookup_asn` and `lookup_domain` raise it, and so does an answer from the cache. A batch entry that is capped carries it as its value, as a failing address does, and the batch still returns. A private address and an answer to no key never raise: neither carries the flag, and a day of keyless lookups spent is a `:quota_exceeded` with status 429 and no `result`. A capped answer is cached for at most a minute, and each hit raises again.
|
|
67
|
+
|
|
52
68
|
### AS and domain lookups
|
|
53
69
|
|
|
54
70
|
```ruby
|
|
@@ -82,13 +98,13 @@ acct.usage.requests # => 580
|
|
|
82
98
|
acct.usage.window_end # => when the allowance resets
|
|
83
99
|
```
|
|
84
100
|
|
|
85
|
-
Usage counts against the anniversary of your subscription on a paid plan, not the calendar month and not the billing period, and against
|
|
101
|
+
Usage counts against the anniversary of your subscription on a paid plan, not the calendar month and not the billing period, and against the UTC day on the free plan; it is the same number a lookup is gated on. `hard_limit` is `nil` on an uncapped plan, which is not the same as zero.
|
|
86
102
|
|
|
87
103
|
Show `plan.name` and compare against `plan.key`: a plan's name can change, and its key never does. A value the API adds later to a plan's `tier`, a database's `standing` or `license_type`, a format or a download's `outcome` comes back as the string it served (from 2.20.0), so check for the values you know rather than assuming the list is complete.
|
|
88
104
|
|
|
89
105
|
### Is that crawler who it says it is?
|
|
90
106
|
|
|
91
|
-
Pass the `User-Agent` of the request you are deciding on, and with every field (a paid plan, or a free
|
|
107
|
+
Pass the `User-Agent` of the request you are deciding on, and with every field (a paid plan, or a free key's full answers) the answer says whose agent it names and whether this address bears that out:
|
|
92
108
|
|
|
93
109
|
```ruby
|
|
94
110
|
result = client.lookup('66.249.66.1', user_agent: request.user_agent)
|
|
@@ -97,7 +113,7 @@ result.user_agent # => {"agent"=>"Googlebot", "kind"=>"bot", "verdict"=>"verifi
|
|
|
97
113
|
results = client.lookup_batch(ips, user_agents: { '66.249.66.1' => request.user_agent })
|
|
98
114
|
```
|
|
99
115
|
|
|
100
|
-
`verdict` is `verified` where the agent's operator vouches for the address, `spoofed` where it does not, `unverifiable` for a bot nothing published can confirm, and `not_bot` for a browser, an app or a script. `my_ip` takes `user_agent:` too. A batch's `user_agents` is keyed by each address as you list it, and an address with no agent, or an empty one, is looked up plainly. An answer with an agent is cached apart from the address's plain answer and from another agent's.
|
|
116
|
+
`verdict` is `verified` where the agent's operator vouches for the address, `spoofed` where it does not, `unverifiable` for a bot nothing published can confirm, and `not_bot` for a browser, an app or a script. `my_ip` takes `user_agent:` too. A batch's `user_agents` is keyed by each address as you list it, and an address with no agent, or an empty one, is looked up plainly. An answer with an agent is cached apart from the address's plain answer and from another agent's. The basics, a private address's answer and a lookup that sent none carry no `user_agent` (`nil`).
|
|
101
117
|
|
|
102
118
|
### Batch lookup
|
|
103
119
|
|
|
@@ -115,7 +131,7 @@ results.each do |ip, result|
|
|
|
115
131
|
end
|
|
116
132
|
```
|
|
117
133
|
|
|
118
|
-
Results are keyed by address, in the order you first listed each one, so duplicates in your list collapse into a single entry and one address failing never loses the rest: it carries its error as its value, with the status the API would have given that address on its own.
|
|
134
|
+
Results are keyed by address, in the order you first listed each one, so duplicates in your list collapse into a single entry and one address failing never loses the rest: it carries its error as its value, with the status the API would have given that address on its own. An address whose answer is capped carries `:quota_exceeded`, and its `result` is that answer.
|
|
119
135
|
|
|
120
136
|
How many chunks are in flight at once, how many times a failed chunk is retried, and how long each chunk's request may take are configurable per call:
|
|
121
137
|
|
|
@@ -134,6 +150,8 @@ result = client.lookup('146.70.116.130') # API request
|
|
|
134
150
|
result2 = client.lookup('146.70.116.130') # no API request, result was cached
|
|
135
151
|
```
|
|
136
152
|
|
|
153
|
+
A capped answer is held for a minute at most, or your TTL when that is shorter, and each lookup of it raises `:quota_exceeded` again without a request.
|
|
154
|
+
|
|
137
155
|
You can change the default cache variables (max size, TTL in seconds) on initialization, or even disable it:
|
|
138
156
|
|
|
139
157
|
```ruby
|
|
@@ -268,7 +286,7 @@ end
|
|
|
268
286
|
|
|
269
287
|
`kind` is one of `:bad_request`, `:unauthorized`, `:forbidden`, `:rate_limited`, `:quota_exceeded`, `:server_error` or `:network`. A lookup's `message` is the API's own words; a database call's refusal also carries `rc`, the API's result code, such as `NOT_LICENSED` or `LICENSE_EXPIRED`.
|
|
270
288
|
|
|
271
|
-
Note that `:rate_limited` and `:quota_exceeded` both arrive as HTTP 429 and are not the same thing. A rate limit is when the API faces extreme traffic bursts and so retrying later works; but a 429 without `Retry-After` is `:quota_exceeded`, which the library never retries. The API
|
|
289
|
+
Note that `:rate_limited` and `:quota_exceeded` both arrive as HTTP 429 and are not the same thing. A rate limit is when the API faces extreme traffic bursts and so retrying later works; but a 429 without `Retry-After` is `:quota_exceeded`, which the library never retries. The API sends one when a source address's lookups without a key are used up for the day, and a free key answers past it; something in between, such as a proxy, may send one too. A paid key past its overage cap gets `cap_reached` instead. It waits the `Retry-After` the API sent, or its own backoff from 250 ms when that's past about 24.8 days.
|
|
272
290
|
|
|
273
291
|
### Sign in with OAuth (device flow)
|
|
274
292
|
|
|
@@ -317,14 +335,14 @@ Each redirect URI must be https on a public host name, or http on a loopback add
|
|
|
317
335
|
|
|
318
336
|
### Absent is not false
|
|
319
337
|
|
|
320
|
-
|
|
338
|
+
The basics leave out the VPN, proxy, hosting, CDN, bot, carrier, satellite, SSH, SMTP, web, DNS resolver and BitTorrent flags and their detail (`bot` names the bot behind `is_bot`), the network's type, an address's company and its abuse contact, an address's city and the rest of its paid location, its Whois, RWHOIS and hosted domains, and the paid members inside each shared object, such as `location['city']`. Every answer to a key carries `cap_reached`: false while the answer has every field, true once the organization's lookups with every field are used up, and then the call raises (above). A field is present when your plan includes it and `nil` when it does not, the flags, the network's type, `company` and `abuse` included, never `false`, `""` or `{}`. `nil` means "not in your plan"; `false` means "we checked, and no".
|
|
321
339
|
|
|
322
340
|
```ruby
|
|
323
341
|
result.vpn? # false when absent, for when you only want the flag
|
|
324
|
-
result.included?(:is_vpn) # false on
|
|
325
|
-
result.
|
|
326
|
-
result.
|
|
327
|
-
result.cap_reached
|
|
342
|
+
result.included?(:is_vpn) # false on the basics: not in your plan
|
|
343
|
+
result.company # nil on the basics, and so is result.abuse
|
|
344
|
+
result.location.key?('city') # false on the basics
|
|
345
|
+
result.cap_reached # false on an answer with every field, nil without a key
|
|
328
346
|
```
|
|
329
347
|
|
|
330
348
|
## Other Libraries
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
#The InternetData API: look up what every database InternetData publishes says about an IP address, an AS or a domain, download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
|
|
5
5
|
|
|
6
|
-
The version of the OpenAPI document: 2026.11.
|
|
6
|
+
The version of the OpenAPI document: 2026.11.29
|
|
7
7
|
Contact: support@internetdata.io
|
|
8
8
|
Generated by: https://openapi-generator.tech
|
|
9
9
|
Generator version: 7.25.0
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
#The InternetData API: look up what every database InternetData publishes says about an IP address, an AS or a domain, download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
|
|
5
5
|
|
|
6
|
-
The version of the OpenAPI document: 2026.11.
|
|
6
|
+
The version of the OpenAPI document: 2026.11.29
|
|
7
7
|
Contact: support@internetdata.io
|
|
8
8
|
Generated by: https://openapi-generator.tech
|
|
9
9
|
Generator version: 7.25.0
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
#The InternetData API: look up what every database InternetData publishes says about an IP address, an AS or a domain, download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
|
|
5
5
|
|
|
6
|
-
The version of the OpenAPI document: 2026.11.
|
|
6
|
+
The version of the OpenAPI document: 2026.11.29
|
|
7
7
|
Contact: support@internetdata.io
|
|
8
8
|
Generated by: https://openapi-generator.tech
|
|
9
9
|
Generator version: 7.25.0
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
#The InternetData API: look up what every database InternetData publishes says about an IP address, an AS or a domain, download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
|
|
5
5
|
|
|
6
|
-
The version of the OpenAPI document: 2026.11.
|
|
6
|
+
The version of the OpenAPI document: 2026.11.29
|
|
7
7
|
Contact: support@internetdata.io
|
|
8
8
|
Generated by: https://openapi-generator.tech
|
|
9
9
|
Generator version: 7.25.0
|
|
@@ -4,11 +4,11 @@ module InternetData
|
|
|
4
4
|
# What a lookup of an AS answers.
|
|
5
5
|
#
|
|
6
6
|
# As with {Result}, an absent member is one your plan does not include, and
|
|
7
|
-
# reads as `nil`, never as 0 or an empty string:
|
|
7
|
+
# reads as `nil`, never as 0 or an empty string: the basics are the AS's
|
|
8
8
|
# registration (`asn`, `name`, `country`, `registry`, `allocated`, `domain`),
|
|
9
|
-
# and paid plans and
|
|
10
|
-
# wire values with their original string keys, as are
|
|
11
|
-
# the neighbor lists.
|
|
9
|
+
# and paid plans and a free key's full answers add the rest. `whois` and
|
|
10
|
+
# `prefixes` are the wire values with their original string keys, as are
|
|
11
|
+
# `hosted_domains` and the neighbor lists.
|
|
12
12
|
class AsnResult
|
|
13
13
|
include Answer
|
|
14
14
|
|
|
@@ -43,61 +43,64 @@ module InternetData
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
# The kind of network it runs, or nil when your plan does not include it.
|
|
46
|
-
# Paid plans and
|
|
46
|
+
# Paid plans and a free key's full answers.
|
|
47
47
|
def type
|
|
48
48
|
@raw['type']
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
# IPv4 addresses it announces. Paid plans and
|
|
51
|
+
# IPv4 addresses it announces. Paid plans and a free key's full answers.
|
|
52
52
|
def num_ips
|
|
53
53
|
@raw['num_ips']
|
|
54
54
|
end
|
|
55
55
|
|
|
56
|
-
# IPv4 prefixes it announces. Paid plans and
|
|
56
|
+
# IPv4 prefixes it announces. Paid plans and a free key's full answers.
|
|
57
57
|
def num_prefixes4
|
|
58
58
|
@raw['num_prefixes4']
|
|
59
59
|
end
|
|
60
60
|
|
|
61
|
-
# IPv6 prefixes it announces. Paid plans and
|
|
61
|
+
# IPv6 prefixes it announces. Paid plans and a free key's full answers.
|
|
62
62
|
def num_prefixes6
|
|
63
63
|
@raw['num_prefixes6']
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
# Its announcements RPKI calls valid. Paid plans and
|
|
66
|
+
# Its announcements RPKI calls valid. Paid plans and a free key's full
|
|
67
|
+
# answers.
|
|
67
68
|
def rpki_valid
|
|
68
69
|
@raw['rpki_valid']
|
|
69
70
|
end
|
|
70
71
|
|
|
71
|
-
# Its announcements RPKI calls invalid. Paid plans and
|
|
72
|
+
# Its announcements RPKI calls invalid. Paid plans and a free key's full
|
|
73
|
+
# answers.
|
|
72
74
|
def rpki_invalid
|
|
73
75
|
@raw['rpki_invalid']
|
|
74
76
|
end
|
|
75
77
|
|
|
76
|
-
# Its announcements with no RPKI record. Paid plans and
|
|
78
|
+
# Its announcements with no RPKI record. Paid plans and a free key's full
|
|
79
|
+
# answers.
|
|
77
80
|
def rpki_not_found
|
|
78
81
|
@raw['rpki_not_found']
|
|
79
82
|
end
|
|
80
83
|
|
|
81
84
|
# Its ASN Whois record, every column, empty where the registry states
|
|
82
|
-
# nothing. Paid plans and
|
|
85
|
+
# nothing. Paid plans and a free key's full answers.
|
|
83
86
|
def whois
|
|
84
87
|
@raw['whois']
|
|
85
88
|
end
|
|
86
89
|
|
|
87
90
|
# What it announces, IPv4 then IPv6, up to 20000 a family, each with its
|
|
88
|
-
# RPKI status. Paid plans and
|
|
91
|
+
# RPKI status. Paid plans and a free key's full answers.
|
|
89
92
|
def prefixes
|
|
90
93
|
@raw['prefixes']
|
|
91
94
|
end
|
|
92
95
|
|
|
93
|
-
# Its rank in ASN Extended by customer cone, 1 the largest; 0 for an AS
|
|
94
|
-
#
|
|
96
|
+
# Its rank in ASN Extended by customer cone, 1 the largest; 0 for an AS seen
|
|
97
|
+
# in no AS path. Paid plans and a free key's full answers.
|
|
95
98
|
def rank
|
|
96
99
|
@raw['rank']
|
|
97
100
|
end
|
|
98
101
|
|
|
99
102
|
# Whether it is one of the transit-free networks at the top of the
|
|
100
|
-
# hierarchy. Paid plans and
|
|
103
|
+
# hierarchy. Paid plans and a free key's full answers.
|
|
101
104
|
def tier1
|
|
102
105
|
@raw['tier1']
|
|
103
106
|
end
|
|
@@ -107,57 +110,54 @@ module InternetData
|
|
|
107
110
|
@raw['tier1'] == true
|
|
108
111
|
end
|
|
109
112
|
|
|
110
|
-
# How many AS numbers it gets transit from. Paid plans and
|
|
113
|
+
# How many AS numbers it gets transit from. Paid plans and a free key's full
|
|
114
|
+
# answers.
|
|
111
115
|
def num_upstreams
|
|
112
116
|
@raw['num_upstreams']
|
|
113
117
|
end
|
|
114
118
|
|
|
115
|
-
# Those AS numbers, ascending, up to 20000. Paid plans and
|
|
119
|
+
# Those AS numbers, ascending, up to 20000. Paid plans and a free key's full
|
|
120
|
+
# answers.
|
|
116
121
|
def upstreams
|
|
117
122
|
@raw['upstreams']
|
|
118
123
|
end
|
|
119
124
|
|
|
120
125
|
# How many AS numbers it exchanges its own and its customers' routes with.
|
|
121
|
-
# Paid plans and
|
|
126
|
+
# Paid plans and a free key's full answers.
|
|
122
127
|
def num_peers
|
|
123
128
|
@raw['num_peers']
|
|
124
129
|
end
|
|
125
130
|
|
|
126
|
-
# Those AS numbers, ascending, up to 20000. Paid plans and
|
|
131
|
+
# Those AS numbers, ascending, up to 20000. Paid plans and a free key's full
|
|
132
|
+
# answers.
|
|
127
133
|
def peers
|
|
128
134
|
@raw['peers']
|
|
129
135
|
end
|
|
130
136
|
|
|
131
|
-
# How many AS numbers it provides transit to. Paid plans and
|
|
137
|
+
# How many AS numbers it provides transit to. Paid plans and a free key's
|
|
138
|
+
# full answers.
|
|
132
139
|
def num_downstreams
|
|
133
140
|
@raw['num_downstreams']
|
|
134
141
|
end
|
|
135
142
|
|
|
136
|
-
# Those AS numbers, ascending, up to 20000. Paid plans and
|
|
143
|
+
# Those AS numbers, ascending, up to 20000. Paid plans and a free key's full
|
|
144
|
+
# answers.
|
|
137
145
|
def downstreams
|
|
138
146
|
@raw['downstreams']
|
|
139
147
|
end
|
|
140
148
|
|
|
141
149
|
# How many registered domains it hosts (`total`) and the 10 most popular
|
|
142
|
-
# (`domains`), with the wire's string keys. Paid plans and
|
|
150
|
+
# (`domains`), with the wire's string keys. Paid plans and a free key's full
|
|
151
|
+
# answers.
|
|
143
152
|
def hosted_domains
|
|
144
153
|
@raw['hosted_domains']
|
|
145
154
|
end
|
|
146
155
|
|
|
147
|
-
# On
|
|
148
|
-
#
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
# `trial_expired` with an absent member read as false.
|
|
154
|
-
def trial_expired?
|
|
155
|
-
@raw['trial_expired'] == true
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
# On answers to a key on a paid plan only: false while the answer has every
|
|
159
|
-
# field, true once its organization's overage cap is reached and the answer
|
|
160
|
-
# has Unlimited's, which is not billed; nil on any other.
|
|
156
|
+
# On every answer to a key: false while the answer has every field, true
|
|
157
|
+
# once its organization's lookups with every field are used up (a free key's
|
|
158
|
+
# for the UTC day, a paid key's quota or overage cap) and the answer has the
|
|
159
|
+
# basics; nil on an answer to no key. A true one is never returned: the call
|
|
160
|
+
# raises `:quota_exceeded` carrying it as {Error#result}.
|
|
161
161
|
def cap_reached
|
|
162
162
|
@raw['cap_reached']
|
|
163
163
|
end
|
data/lib/internetdata/cache.rb
CHANGED
|
@@ -10,12 +10,13 @@ module InternetData
|
|
|
10
10
|
# serve one of them the other's shape. Errors are never stored and bogons
|
|
11
11
|
# never reach it.
|
|
12
12
|
#
|
|
13
|
-
# A
|
|
14
|
-
#
|
|
13
|
+
# A capped answer, one whose `cap_reached` is true (past a free key's full
|
|
14
|
+
# answers for the day, or a paid key's quota or overage cap), ends with the
|
|
15
|
+
# allowance's window (on the free plan, the UTC day) or a raised cap, so it
|
|
15
16
|
# stays a minute at most rather than the TTL. It is still cached, or a busy
|
|
16
|
-
# process would send every repeat to the API.
|
|
17
|
+
# process would send every repeat to the API; the client raises on each hit.
|
|
17
18
|
class Cache
|
|
18
|
-
# The longest a
|
|
19
|
+
# The longest a capped answer is held, in seconds.
|
|
19
20
|
REDUCED_TTL = 60
|
|
20
21
|
|
|
21
22
|
def initialize(max_size:, ttl:)
|
|
@@ -54,8 +55,7 @@ module InternetData
|
|
|
54
55
|
private
|
|
55
56
|
|
|
56
57
|
def life_of(value)
|
|
57
|
-
|
|
58
|
-
reduced ? [@ttl, REDUCED_TTL].min : @ttl
|
|
58
|
+
value.respond_to?(:cap_reached?) && value.cap_reached? ? [@ttl, REDUCED_TTL].min : @ttl
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def now
|
data/lib/internetdata/client.rb
CHANGED
|
@@ -23,12 +23,14 @@ module InternetData
|
|
|
23
23
|
# Signing a person in with OAuth, which needs no API key at all.
|
|
24
24
|
attr_reader :oauth
|
|
25
25
|
|
|
26
|
-
# @param api_key [String, nil] without one a lookup
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
26
|
+
# @param api_key [String, nil] without one a lookup answers the basics: an
|
|
27
|
+
# address's location, network, reverse DNS and its Tor, relay and anycast
|
|
28
|
+
# flags, an AS's registration and a domain's. A free key answers every
|
|
29
|
+
# field on its organization's first lookups each UTC day, then raises
|
|
30
|
+
# `:quota_exceeded` carrying the basics as {Error#result}, as a paid key
|
|
31
|
+
# past its quota or overage cap does. A batch needs a key on a paid plan,
|
|
32
|
+
# and the databases a key carrying the `db.download` scope. It is trimmed,
|
|
33
|
+
# and a key of blanks alone is no key.
|
|
32
34
|
# @param base_url [String] the API; {#oauth} signs in at its apex, `api.`
|
|
33
35
|
# dropped and `api-<env>.` becoming `<env>.`, and at any other URL as given.
|
|
34
36
|
# @param cache [Boolean] pass false to disable caching.
|
|
@@ -86,54 +88,27 @@ module InternetData
|
|
|
86
88
|
# A bogon is answered locally and never reaches the network. Everything else
|
|
87
89
|
# is served, then cached for this instance.
|
|
88
90
|
#
|
|
91
|
+
# An answer with `cap_reached` true, the basics alone because the
|
|
92
|
+
# organization's lookups with every field are used up, is raised as
|
|
93
|
+
# `:quota_exceeded`, status 200, never retried, fresh or from the cache (which
|
|
94
|
+
# holds it a minute at most). Catch it to carry on: {Error#result} is the
|
|
95
|
+
# answer, with the basics. No option turns the raise off.
|
|
96
|
+
#
|
|
89
97
|
# @param retries [Integer, nil] extra attempts, for THIS call only.
|
|
90
98
|
# @param timeout [Numeric, nil] seconds each attempt may take, for THIS call only.
|
|
91
99
|
# @param user_agent [String, nil] the `User-Agent` of the request you are
|
|
92
|
-
# deciding on. With every field (a paid plan, or
|
|
93
|
-
# carries {Result#user_agent}: the agent it names,
|
|
94
|
-
# bears that out. An empty one is none. An answer
|
|
95
|
-
# from the address's plain answer and from another
|
|
96
|
-
# answered locally, with no `user_agent`.
|
|
100
|
+
# deciding on. With every field (a paid plan, or a free key's full
|
|
101
|
+
# answers) the answer then carries {Result#user_agent}: the agent it names,
|
|
102
|
+
# and whether this address bears that out. An empty one is none. An answer
|
|
103
|
+
# with one is cached apart from the address's plain answer and from another
|
|
104
|
+
# agent's. A bogon is still answered locally, with no `user_agent`.
|
|
97
105
|
# @raise [Error] `:bad_request`, before any request, for anything but an IP
|
|
98
106
|
# address: {#lookup_asn} and {#lookup_domain} look an AS and a domain up.
|
|
107
|
+
# @raise [Error] `:quota_exceeded` for a capped answer, whose `result` is it.
|
|
99
108
|
# @raise [ArgumentError] for a `user_agent` that is not a String.
|
|
100
109
|
# @return [Result]
|
|
101
110
|
def lookup(ip, retries: nil, timeout: nil, user_agent: nil)
|
|
102
|
-
|
|
103
|
-
Transport.checked_timeout(timeout) unless timeout.nil?
|
|
104
|
-
Retries.checked_count(retries) unless retries.nil?
|
|
105
|
-
agent = Transport.checked_user_agent(user_agent)
|
|
106
|
-
# Judged, cached and sent as the IPv4 address it carries, if it is mapped.
|
|
107
|
-
ip = Bogon.unmapped(ip)
|
|
108
|
-
# The API answers an AS or a domain at this path too, as an answer this call
|
|
109
|
-
# cannot read, so one is refused unsent rather than retried as unreadable.
|
|
110
|
-
unless Bogon.address?(ip)
|
|
111
|
-
raise Error.new(:bad_request, "'#{ip}' is not an IP address: look up an AS with lookup_asn, " \
|
|
112
|
-
'and a domain with lookup_domain')
|
|
113
|
-
end
|
|
114
|
-
return Bogon.result(ip) if Bogon.bogon?(ip)
|
|
115
|
-
|
|
116
|
-
key = key_of(ip, agent)
|
|
117
|
-
loop do
|
|
118
|
-
hit = @cache&.get(key)
|
|
119
|
-
return hit unless hit.nil?
|
|
120
|
-
|
|
121
|
-
flight, leader = board(key)
|
|
122
|
-
return fetch(ip, agent, retries, timeout) if flight.nil?
|
|
123
|
-
|
|
124
|
-
if leader
|
|
125
|
-
# Read once more now the address is boarded: a leader that landed
|
|
126
|
-
# between the miss above and boarding has already cached its answer.
|
|
127
|
-
hit = @cache.get(key)
|
|
128
|
-
return unboard(key, flight, :served, hit) unless hit.nil?
|
|
129
|
-
|
|
130
|
-
return lead(key, flight) { fetch(ip, agent, retries, timeout) }
|
|
131
|
-
end
|
|
132
|
-
state, value = flight.wait
|
|
133
|
-
return value if state == :served
|
|
134
|
-
raise value if state == :failed
|
|
135
|
-
# :abandoned - its leader never finished, so this caller asks again.
|
|
136
|
-
end
|
|
111
|
+
uncapped(answer_for(ip, retries, timeout, user_agent))
|
|
137
112
|
end
|
|
138
113
|
|
|
139
114
|
# What every database says about one AS. Sent as given, so `9009` and
|
|
@@ -142,12 +117,15 @@ module InternetData
|
|
|
142
117
|
#
|
|
143
118
|
# @param retries [Integer, nil] extra attempts, for THIS call only.
|
|
144
119
|
# @param timeout [Numeric, nil] seconds each attempt may take, for THIS call only.
|
|
120
|
+
# @raise [Error] `:quota_exceeded` for a capped answer, as {#lookup} raises it.
|
|
145
121
|
# @return [AsnResult]
|
|
146
122
|
def lookup_asn(asn, retries: nil, timeout: nil)
|
|
147
123
|
Retries.checked_count(retries) unless retries.nil?
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
124
|
+
uncapped(
|
|
125
|
+
Retries.with_retries(retries || @retries) do
|
|
126
|
+
Transport.asn_result(@transport.asn_request(asn, timeout: timeout).run)
|
|
127
|
+
end,
|
|
128
|
+
)
|
|
151
129
|
end
|
|
152
130
|
|
|
153
131
|
# What every database says about one domain. Sent as given: the API reads it
|
|
@@ -156,12 +134,15 @@ module InternetData
|
|
|
156
134
|
#
|
|
157
135
|
# @param retries [Integer, nil] extra attempts, for THIS call only.
|
|
158
136
|
# @param timeout [Numeric, nil] seconds each attempt may take, for THIS call only.
|
|
137
|
+
# @raise [Error] `:quota_exceeded` for a capped answer, as {#lookup} raises it.
|
|
159
138
|
# @return [DomainResult]
|
|
160
139
|
def lookup_domain(domain, retries: nil, timeout: nil)
|
|
161
140
|
Retries.checked_count(retries) unless retries.nil?
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
141
|
+
uncapped(
|
|
142
|
+
Retries.with_retries(retries || @retries) do
|
|
143
|
+
Transport.domain_result(@transport.domain_request(domain, timeout: timeout).run)
|
|
144
|
+
end,
|
|
145
|
+
)
|
|
165
146
|
end
|
|
166
147
|
|
|
167
148
|
# What every database says about the address this client is calling from.
|
|
@@ -176,13 +157,16 @@ module InternetData
|
|
|
176
157
|
# otherwise be told where it used to be.
|
|
177
158
|
#
|
|
178
159
|
# @param user_agent [String, nil] as {#lookup} takes it.
|
|
160
|
+
# @raise [Error] `:quota_exceeded` for a capped answer, as {#lookup} raises it.
|
|
179
161
|
# @return [Result]
|
|
180
162
|
def my_ip(retries: nil, timeout: nil, user_agent: nil)
|
|
181
163
|
Retries.checked_count(retries) unless retries.nil?
|
|
182
164
|
agent = Transport.checked_user_agent(user_agent)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
165
|
+
uncapped(
|
|
166
|
+
Retries.with_retries(retries || @retries) do
|
|
167
|
+
Transport.lookup_result(@transport.myip_request(timeout: timeout, user_agent: agent).run)
|
|
168
|
+
end,
|
|
169
|
+
)
|
|
186
170
|
end
|
|
187
171
|
|
|
188
172
|
# What this client's key is entitled to, and how much of it has been used.
|
|
@@ -197,7 +181,7 @@ module InternetData
|
|
|
197
181
|
#
|
|
198
182
|
# Usage counts against the ALLOWANCE WINDOW - on a paid plan the
|
|
199
183
|
# anniversary of the subscription, not the calendar month and not the
|
|
200
|
-
# billing period, and on the free plan
|
|
184
|
+
# billing period, and on the free plan the UTC day - and it is the same
|
|
201
185
|
# number a lookup is gated on. It can lag by a few seconds, because
|
|
202
186
|
# requests are counted in memory and flushed in aggregate.
|
|
203
187
|
#
|
|
@@ -225,7 +209,10 @@ module InternetData
|
|
|
225
209
|
# endpoint needs a paid plan: without a key every address in a request of
|
|
226
210
|
# two or more carries an `:unauthorized` error, and a free-plan key's
|
|
227
211
|
# request of two or more a `:bad_request` (HTTP 402). A request of one
|
|
228
|
-
# address is answered as its lookup would be.
|
|
212
|
+
# address is answered as its lookup would be. An address whose answer has
|
|
213
|
+
# `cap_reached` true carries `:quota_exceeded`, with that answer as its
|
|
214
|
+
# {Error#result}, as {#lookup} raises it, fresh or from the cache; the batch
|
|
215
|
+
# still returns.
|
|
229
216
|
#
|
|
230
217
|
# @param concurrency [Integer, nil] chunks in flight, for THIS batch only.
|
|
231
218
|
# Anything but an Integer from 1 is refused as `:bad_request` before any
|
|
@@ -291,11 +278,59 @@ module InternetData
|
|
|
291
278
|
|
|
292
279
|
# Reinstated in input order: a hydra settles in completion order, and a
|
|
293
280
|
# caller iterating the hash should see what they passed in.
|
|
294
|
-
asked.to_h { |ip| [ip, answers[Bogon.unmapped(ip)]] }
|
|
281
|
+
asked.to_h { |ip| [ip, entry_of(answers[Bogon.unmapped(ip)])] }
|
|
295
282
|
end
|
|
296
283
|
|
|
297
284
|
private
|
|
298
285
|
|
|
286
|
+
# A lookup's answer, or the `:quota_exceeded` it is when `cap_reached` is true,
|
|
287
|
+
# holding it. Raised outside the retries: a capped answer is a 200 and is
|
|
288
|
+
# never asked for again.
|
|
289
|
+
def uncapped(answer)
|
|
290
|
+
raise Error.capped(answer) if answer.cap_reached?
|
|
291
|
+
|
|
292
|
+
answer
|
|
293
|
+
end
|
|
294
|
+
|
|
295
|
+
# The address lookup before the raise: a cached answer, one a concurrent call
|
|
296
|
+
# fetched, or one fetched here, capped or not.
|
|
297
|
+
def answer_for(ip, retries, timeout, user_agent)
|
|
298
|
+
Transport.checked_timeout(timeout) unless timeout.nil?
|
|
299
|
+
Retries.checked_count(retries) unless retries.nil?
|
|
300
|
+
agent = Transport.checked_user_agent(user_agent)
|
|
301
|
+
# Judged, cached and sent as the IPv4 address it carries, if it is mapped.
|
|
302
|
+
ip = Bogon.unmapped(ip)
|
|
303
|
+
# The API answers an AS or a domain at this path too, as an answer this call
|
|
304
|
+
# cannot read, so one is refused unsent rather than retried as unreadable.
|
|
305
|
+
unless Bogon.address?(ip)
|
|
306
|
+
raise Error.new(:bad_request, "'#{ip}' is not an IP address: look up an AS with lookup_asn, " \
|
|
307
|
+
'and a domain with lookup_domain')
|
|
308
|
+
end
|
|
309
|
+
return Bogon.result(ip) if Bogon.bogon?(ip)
|
|
310
|
+
|
|
311
|
+
key = key_of(ip, agent)
|
|
312
|
+
loop do
|
|
313
|
+
hit = @cache&.get(key)
|
|
314
|
+
return hit unless hit.nil?
|
|
315
|
+
|
|
316
|
+
flight, leader = board(key)
|
|
317
|
+
return fetch(ip, agent, retries, timeout) if flight.nil?
|
|
318
|
+
|
|
319
|
+
if leader
|
|
320
|
+
# Read once more now the address is boarded: a leader that landed
|
|
321
|
+
# between the miss above and boarding has already cached its answer.
|
|
322
|
+
hit = @cache.get(key)
|
|
323
|
+
return unboard(key, flight, :served, hit) unless hit.nil?
|
|
324
|
+
|
|
325
|
+
return lead(key, flight) { fetch(ip, agent, retries, timeout) }
|
|
326
|
+
end
|
|
327
|
+
state, value = flight.wait
|
|
328
|
+
return value if state == :served
|
|
329
|
+
raise value if state == :failed
|
|
330
|
+
# :abandoned - its leader never finished, so this caller asks again.
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
|
|
299
334
|
# Whether `value` can be a batch's concurrency: chunks in flight are counted
|
|
300
335
|
# whole, and a hydra allowed fewer than one runs nothing.
|
|
301
336
|
def concurrency?(value)
|
|
@@ -431,6 +466,12 @@ module InternetData
|
|
|
431
466
|
nil
|
|
432
467
|
end
|
|
433
468
|
|
|
469
|
+
# A batch entry as the caller gets it: a capped answer is the error a lookup of
|
|
470
|
+
# it raises, one per address, and any other answer or error as it is.
|
|
471
|
+
def entry_of(answer)
|
|
472
|
+
answer.is_a?(Result) && answer.cap_reached? ? Error.capped(answer) : answer
|
|
473
|
+
end
|
|
474
|
+
|
|
434
475
|
# What a batch takes for an address another call was fetching: that call's
|
|
435
476
|
# answer or error, or, when its leader never finished, its own lookup.
|
|
436
477
|
def joined_answer(ip, agent, flight, retries, timeout)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
#The InternetData API: look up what every database InternetData publishes says about an IP address, an AS or a domain, download the databases your organization is licensed for, and manage the account behind them. See https://docs.internetdata.io for guides and https://github.com/internetdata for the official client libraries.
|
|
5
5
|
|
|
6
|
-
The version of the OpenAPI document: 2026.11.
|
|
6
|
+
The version of the OpenAPI document: 2026.11.29
|
|
7
7
|
Contact: support@internetdata.io
|
|
8
8
|
Generated by: https://openapi-generator.tech
|
|
9
9
|
Generator version: 7.25.0
|