ipscope 1.0.0 → 1.1.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/CHANGELOG.md +85 -0
- data/README.md +40 -10
- data/lib/ipscope/client.rb +42 -13
- data/lib/ipscope/models.rb +505 -317
- data/lib/ipscope/transport.rb +7 -8
- data/lib/ipscope/validator.rb +1 -1
- data/lib/ipscope/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 15110c69d51859a9c83923b4dcc753c502add92f796cb11a06bbea196f2451c9
|
|
4
|
+
data.tar.gz: 9b61ca555e6f8d471990251c42af94275fdfef4dd9e56f9e7ed3b59338d1c3fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c0e15645a6c4afd6859fc45f3b08fff575ef7b784f92224b9cd7489ba28f5437ba97f4a564c1af7d0427e307e9f530599c1792010e5d871a618a9c0fb5337939
|
|
7
|
+
data.tar.gz: da83b10ca45b09a8b7ca9ea33b52b89a184064a5844c09b74c0b9cbbc3f5576be4a117890d9a26eede89e1c710b6b34c2556339cd8541fb51a1202fa4b46ce86
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the `ipscope` gem are documented here.
|
|
4
|
+
The project follows [Semantic Versioning](https://semver.org/).
|
|
5
|
+
|
|
6
|
+
## [1.1.0] - 2026-11-10
|
|
7
|
+
|
|
8
|
+
1.0.0 did not match the live IPScope API. Several methods called URLs that do not
|
|
9
|
+
exist, and the response models were built around field names the API never sends,
|
|
10
|
+
so most fields came back as `nil`/`false` even when the request worked. 1.1.0 fixes
|
|
11
|
+
the gem against the real API at `https://api.ipscope.io`.
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
- **Endpoint paths** (each returned HTTP 404 in 1.0.0):
|
|
16
|
+
- `lookup_caller_ip` now calls `GET /v1/ip/me` (was `GET /v1/ip`).
|
|
17
|
+
- `lookup_network` now calls `GET /v1/networks/{address}/{length}` (was `/v1/network/...`).
|
|
18
|
+
- `get_datasets_metadata` now calls `GET /v1/metadata/datasets` (was `/v1/datasets/metadata`).
|
|
19
|
+
- **Response models rebuilt from the API's response contract.**
|
|
20
|
+
- `IpLookupResponse`: `ip_version`, `matched_network`, `dataset_version`, and `updated_at` (may be `nil`).
|
|
21
|
+
- `GeoBlock`: `country_code`, `subdivision`, `city`, `postal_code`, `latitude`, `longitude`,
|
|
22
|
+
`timezone`, `location_type`, `confidence`, `accuracy_radius_km`, `declared_country_code`,
|
|
23
|
+
`physical_country_code`, `is_virtual_location`.
|
|
24
|
+
- `NetworkBlock`: `asn`, `organization`.
|
|
25
|
+
- `SecurityBlock`: `is_vpn`, `is_hosting`, `is_tor_exit`, `is_proxy`, `is_relay`,
|
|
26
|
+
`anonymizer_type`, `confidence`, `reason_codes`. The booleans can now be `nil`: `nil` means
|
|
27
|
+
the API did not have enough evidence, which is different from `false`.
|
|
28
|
+
- `ConnectionBlock`: `connection_type`, `is_residential`, `is_mobile`, `is_business`, `is_hosting`.
|
|
29
|
+
- `SecurityExtensionsBlock`: `abuse_velocity_score`, `is_known_scanner`, `observation_recency_hours`.
|
|
30
|
+
`abuse_velocity_score` is passed through unchanged. The API contract defines it as an
|
|
31
|
+
Integer 0–100 (higher is worse). API releases from before that change serve a Float in
|
|
32
|
+
0.0–1.0, so code written against both should check which form it got.
|
|
33
|
+
- `connection` and `security_extensions` are `nil` when your plan does not license those
|
|
34
|
+
field families (the API leaves those blocks out).
|
|
35
|
+
- `BatchLookupResponse` gains `dataset_version`.
|
|
36
|
+
- `NetworkPrefixLookupResponse` is now `queried_cidr`, `matched_network`, `family`,
|
|
37
|
+
`bgp_prefix_length`, `dataset_version`, `record` (a `CanonicalNetworkPrefixRecord` with the
|
|
38
|
+
snapshot's own fields in snake_case, or `nil`), and `lookup` (a full `IpLookupResponse`).
|
|
39
|
+
New supporting classes: `SeparatedLocations`, `LocationAssertion`.
|
|
40
|
+
- `DatasetsMetadataResponse` is now `active_version`, `previous_version`, `snapshots`
|
|
41
|
+
(`snapshot_version`, `digest`, `ruleset_version`, `published_at`, `ipv4_prefix_count`, `ipv6_prefix_count`).
|
|
42
|
+
- `ServiceStatusResponse` is now `status` plus `snapshot` (`ServiceSnapshotInfo` with
|
|
43
|
+
`current_version`/`previous_version`), with `current_version`/`previous_version` helpers.
|
|
44
|
+
- **`submit_feedback` sends the body the API accepts:** `prefix_or_ip`, `role`
|
|
45
|
+
(`network_owner`|`user`|`researcher`), `issue_type` (`wrong_country`|`wrong_city`|
|
|
46
|
+
`false_positive_vpn`|`false_positive_hosting`|`false_positive_tor`|`virtual_location_mismatch`|`other`),
|
|
47
|
+
`requested_correction` (Hash), and optionally `evidence_url`, `contact_consent`, `contact_email`.
|
|
48
|
+
The gem checks role, issue type, URL, and email before sending the request.
|
|
49
|
+
`FeedbackSubmissionResponse` reads the API's `createdAt` (and still accepts `created_at`).
|
|
50
|
+
- **Rate-limit headers:** the gem now parses `X-RateLimit-Limit`, `-Remaining`, `-Reset`, and `-Scope`.
|
|
51
|
+
`X-RateLimit-Reset` is the number of **seconds until the window resets**, exposed as
|
|
52
|
+
`RateLimitMetadata#reset_after_seconds`; `#scope` is new (e.g. `"user"`). The gem no longer
|
|
53
|
+
parses `X-RateLimit-Credits-Remaining` or `X-RateLimit-Tier`, which the API never sends.
|
|
54
|
+
- The README examples now use the real API fields.
|
|
55
|
+
|
|
56
|
+
### Deprecated
|
|
57
|
+
|
|
58
|
+
These still work in 1.1.x and will be removed in 2.0. The model accessors print a deprecation
|
|
59
|
+
warning (silenced by `ruby -W0`).
|
|
60
|
+
|
|
61
|
+
- `RateLimitMetadata#reset_epoch_seconds` (and the `reset_epoch_seconds:` constructor keyword):
|
|
62
|
+
the name was wrong. It returns the **same seconds-until-reset value** as `#reset_after_seconds`,
|
|
63
|
+
not an epoch timestamp. Use `#reset_after_seconds`.
|
|
64
|
+
- `RateLimitMetadata#credits_remaining`, `RateLimitMetadata#plan_tier`: always `nil` (no such headers).
|
|
65
|
+
- `NetworkBlock#org` → `#organization`.
|
|
66
|
+
- `SecurityBlock#is_tor` → `#is_tor_exit`; `SecurityBlock#is_datacenter` → `#is_hosting`.
|
|
67
|
+
- `IpLookupResponse#version` → `#ip_version`.
|
|
68
|
+
|
|
69
|
+
### Breaking changes
|
|
70
|
+
|
|
71
|
+
- `FeedbackSubmissionInput` now takes the API's fields (`prefix_or_ip:`, `role:`, `issue_type:`,
|
|
72
|
+
`requested_correction:`, `evidence_url:`, `contact_consent:`, `contact_email:`). The 1.0
|
|
73
|
+
keywords (`ip_or_cidr:`, `suggested_*:`, `notes:`) are gone. The API rejected every 1.0
|
|
74
|
+
submission, so no working code depended on them.
|
|
75
|
+
- 1.0 model readers for fields the API never sends have been removed: for example `threat_level`,
|
|
76
|
+
`threat_types`, `asn_name`, `isp`, `bgp_prefix`, `rir`, `is_bogon`, `country_name`, `region_code`,
|
|
77
|
+
the old `ConnectionBlock`/`SecurityExtensionsBlock` readers, and the old network, datasets,
|
|
78
|
+
and status response readers. In 1.0 they were always `nil`/`false`/empty. Calling one now
|
|
79
|
+
raises `NoMethodError`.
|
|
80
|
+
- The network, datasets, and caller-IP response models changed shape. In 1.0 those methods
|
|
81
|
+
always failed with HTTP 404.
|
|
82
|
+
|
|
83
|
+
### Notes
|
|
84
|
+
|
|
85
|
+
- The minimum Ruby version is unchanged (`>= 2.6.0`). The test suite passes on 2.6, 3.2, and 3.3.
|
data/README.md
CHANGED
|
@@ -31,27 +31,57 @@ gem "ipscope"
|
|
|
31
31
|
```ruby
|
|
32
32
|
require "ipscope"
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
# API keys have the form "<public>:<private>" (a UUID, a colon, then a 43-character secret).
|
|
35
|
+
client = IpScope::Client.new(api_key: "<public>:<private>")
|
|
35
36
|
|
|
36
|
-
# 1. Single IPv4 or IPv6 lookup (cached
|
|
37
|
+
# 1. Single IPv4 or IPv6 lookup (GET /v1/ip/{ip}; cached in a bounded LRU cache)
|
|
37
38
|
ip_info = client.lookup_ip("8.8.8.8")
|
|
38
|
-
puts "#{ip_info.ip} #{ip_info.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
#
|
|
39
|
+
puts "#{ip_info.ip} IPv#{ip_info.ip_version} #{ip_info.geo.country_code} " \
|
|
40
|
+
"AS#{ip_info.network.asn} #{ip_info.network.organization}"
|
|
41
|
+
# Security booleans are true, false, or nil (nil = not enough evidence).
|
|
42
|
+
puts "VPN: #{ip_info.security.is_vpn.inspect} Hosting: #{ip_info.security.is_hosting.inspect} " \
|
|
43
|
+
"Tor exit: #{ip_info.security.is_tor_exit.inspect} Anonymizer: #{ip_info.security.anonymizer_type}"
|
|
44
|
+
# `connection` and `security_extensions` are nil unless your plan licenses them.
|
|
45
|
+
puts "Connection: #{ip_info.connection&.connection_type || 'n/a'} Dataset: #{ip_info.dataset_version}"
|
|
46
|
+
|
|
47
|
+
# 2. Your own public IP (GET /v1/ip/me)
|
|
48
|
+
me = client.lookup_caller_ip
|
|
49
|
+
|
|
50
|
+
# 3. Batch lookup (up to 100 IPs; deduplicates & reuses cached entries automatically)
|
|
42
51
|
batch = client.lookup_batch(["8.8.8.8", "1.1.1.1", "2606:4700:4700::1111"])
|
|
43
52
|
batch.results.each do |record|
|
|
44
|
-
puts "#{record.ip} -> #{record.network.
|
|
53
|
+
puts "#{record.ip} -> #{record.network.organization}"
|
|
45
54
|
end
|
|
46
55
|
|
|
47
|
-
#
|
|
56
|
+
# 4. Memory-bounded streaming batch lookup for 10,000+ IPs (constant O(chunk) RAM)
|
|
48
57
|
client.lookup_batch_stream(large_ip_list) do |chunk|
|
|
49
58
|
chunk.results.each do |record|
|
|
50
59
|
# Process each record with < 400 KB steady-state memory overhead
|
|
51
60
|
end
|
|
52
61
|
end
|
|
53
62
|
|
|
54
|
-
#
|
|
63
|
+
# 5. Network CIDR prefix lookup (GET /v1/networks/{address}/{length})
|
|
55
64
|
prefix = client.lookup_network("8.8.8.0/24")
|
|
56
|
-
puts "#{prefix.
|
|
65
|
+
puts "#{prefix.queried_cidr} matched #{prefix.matched_network} org: #{prefix.record&.organization || 'n/a'}"
|
|
66
|
+
|
|
67
|
+
# 6. Rate limits (per user): seconds until the window resets
|
|
68
|
+
limits = client.last_rate_limit
|
|
69
|
+
puts "#{limits&.remaining}/#{limits&.limit}, resets in #{limits&.reset_after_seconds}s"
|
|
70
|
+
|
|
71
|
+
# 7. Report a wrong answer (POST /v1/feedback)
|
|
72
|
+
client.submit_feedback(
|
|
73
|
+
IpScope::FeedbackSubmissionInput.new(
|
|
74
|
+
prefix_or_ip: "8.8.8.0/24",
|
|
75
|
+
role: "network_owner", # network_owner | user | researcher
|
|
76
|
+
issue_type: "wrong_city", # see IpScope::FeedbackSubmissionInput::ISSUE_TYPES
|
|
77
|
+
requested_correction: { "city" => "Mountain View" },
|
|
78
|
+
evidence_url: "https://example.net/geofeed.csv"
|
|
79
|
+
)
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
# 8. Service health and dataset versions
|
|
83
|
+
puts client.get_status.current_version
|
|
84
|
+
puts client.get_datasets_metadata.active_version
|
|
57
85
|
```
|
|
86
|
+
|
|
87
|
+
Upgrading from 1.0? See [CHANGELOG.md](CHANGELOG.md).
|
data/lib/ipscope/client.rb
CHANGED
|
@@ -68,9 +68,9 @@ module IpScope
|
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
70
|
|
|
71
|
-
# Resolves IP intelligence for the caller's own public IP address (`GET /v1/ip`).
|
|
71
|
+
# Resolves IP intelligence for the caller's own public IP address (`GET /v1/ip/me`).
|
|
72
72
|
def lookup_caller_ip(options = nil)
|
|
73
|
-
raw = @transport.request_json("GET", "/v1/ip", options: options)
|
|
73
|
+
raw = @transport.request_json("GET", "/v1/ip/me", options: options)
|
|
74
74
|
record = IpLookupResponse.from_h(raw[:data])
|
|
75
75
|
@cache.set(record.ip, record) if !(options&.bypass_cache) && !record.ip.empty?
|
|
76
76
|
record
|
|
@@ -85,6 +85,7 @@ module IpScope
|
|
|
85
85
|
|
|
86
86
|
resolved_map = {}
|
|
87
87
|
missing_ips = []
|
|
88
|
+
dataset_version = ""
|
|
88
89
|
|
|
89
90
|
if !bypass_cache && @cache.enabled?
|
|
90
91
|
unique_ips.each do |ip|
|
|
@@ -107,6 +108,7 @@ module IpScope
|
|
|
107
108
|
options: options
|
|
108
109
|
)
|
|
109
110
|
batch_resp = BatchLookupResponse.from_h(raw[:data])
|
|
111
|
+
dataset_version = batch_resp.dataset_version
|
|
110
112
|
|
|
111
113
|
batch_resp.results.each_with_index do |record, idx|
|
|
112
114
|
requested_key = missing_ips[idx] || record.ip
|
|
@@ -125,7 +127,8 @@ module IpScope
|
|
|
125
127
|
|
|
126
128
|
BatchLookupResponse.new(
|
|
127
129
|
count: ordered_results.length,
|
|
128
|
-
results: ordered_results
|
|
130
|
+
results: ordered_results,
|
|
131
|
+
dataset_version: dataset_version.empty? ? first_dataset_version(ordered_results) : dataset_version
|
|
129
132
|
)
|
|
130
133
|
end
|
|
131
134
|
|
|
@@ -138,7 +141,8 @@ module IpScope
|
|
|
138
141
|
end
|
|
139
142
|
BatchLookupResponse.new(
|
|
140
143
|
count: merged.length,
|
|
141
|
-
results: merged
|
|
144
|
+
results: merged,
|
|
145
|
+
dataset_version: first_dataset_version(merged)
|
|
142
146
|
)
|
|
143
147
|
end
|
|
144
148
|
|
|
@@ -182,18 +186,18 @@ module IpScope
|
|
|
182
186
|
end
|
|
183
187
|
end
|
|
184
188
|
|
|
185
|
-
# Looks up BGP/CIDR network prefix intelligence (`GET /v1/
|
|
189
|
+
# Looks up BGP/CIDR network prefix intelligence (`GET /v1/networks/{address}/{prefixLength}`).
|
|
186
190
|
def lookup_network(cidr, options = nil)
|
|
187
191
|
parsed = Validator.validate_cidr_prefix(cidr)
|
|
188
192
|
encoded_addr = URI.encode_www_form_component(parsed[:address])
|
|
189
|
-
path = "/v1/
|
|
193
|
+
path = "/v1/networks/#{encoded_addr}/#{parsed[:prefix_length]}"
|
|
190
194
|
raw = @transport.request_json("GET", path, options: options)
|
|
191
195
|
NetworkPrefixLookupResponse.from_h(raw[:data])
|
|
192
196
|
end
|
|
193
197
|
|
|
194
|
-
# Retrieves active
|
|
198
|
+
# Retrieves active and historical dataset snapshot metadata (`GET /v1/metadata/datasets`).
|
|
195
199
|
def get_datasets_metadata(options = nil)
|
|
196
|
-
raw = @transport.request_json("GET", "/v1/datasets
|
|
200
|
+
raw = @transport.request_json("GET", "/v1/metadata/datasets", options: options)
|
|
197
201
|
DatasetsMetadataResponse.from_h(raw[:data])
|
|
198
202
|
end
|
|
199
203
|
|
|
@@ -203,19 +207,20 @@ module IpScope
|
|
|
203
207
|
raise IpScopeValidationError.new("Expected FeedbackSubmissionInput instance.", field: "feedback")
|
|
204
208
|
end
|
|
205
209
|
|
|
206
|
-
trimmed = feedback.
|
|
210
|
+
trimmed = feedback.prefix_or_ip.strip
|
|
207
211
|
if trimmed.empty?
|
|
208
|
-
raise IpScopeValidationError.new("
|
|
212
|
+
raise IpScopeValidationError.new("prefix_or_ip must not be empty.", field: "prefix_or_ip")
|
|
209
213
|
end
|
|
210
214
|
|
|
211
215
|
normalized = if trimmed.include?("/")
|
|
212
216
|
Validator.validate_cidr_prefix(trimmed)[:canonical_cidr]
|
|
213
217
|
else
|
|
214
|
-
Validator.validate_ip_address(trimmed, "
|
|
218
|
+
Validator.validate_ip_address(trimmed, "prefix_or_ip")
|
|
215
219
|
end
|
|
220
|
+
validate_feedback_fields(feedback)
|
|
216
221
|
|
|
217
222
|
payload = feedback.to_h
|
|
218
|
-
payload["
|
|
223
|
+
payload["prefix_or_ip"] = normalized
|
|
219
224
|
|
|
220
225
|
raw = @transport.request_json("POST", "/v1/feedback", json_body: payload, options: options)
|
|
221
226
|
FeedbackSubmissionResponse.from_h(raw[:data])
|
|
@@ -227,7 +232,7 @@ module IpScope
|
|
|
227
232
|
ServiceStatusResponse.from_h(raw[:data])
|
|
228
233
|
end
|
|
229
234
|
|
|
230
|
-
# Returns the most recent rate-limit metadata observed from `
|
|
235
|
+
# Returns the most recent rate-limit metadata observed from `X-RateLimit-*` headers.
|
|
231
236
|
def last_rate_limit
|
|
232
237
|
@transport.last_rate_limit
|
|
233
238
|
end
|
|
@@ -244,6 +249,30 @@ module IpScope
|
|
|
244
249
|
|
|
245
250
|
private
|
|
246
251
|
|
|
252
|
+
def first_dataset_version(records)
|
|
253
|
+
found = records.find { |r| !r.dataset_version.empty? }
|
|
254
|
+
found ? found.dataset_version : ""
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
def validate_feedback_fields(feedback)
|
|
258
|
+
unless FeedbackSubmissionInput::ROLES.include?(feedback.role)
|
|
259
|
+
raise IpScopeValidationError.new(
|
|
260
|
+
"role must be one of: #{FeedbackSubmissionInput::ROLES.join(', ')}.", field: "role"
|
|
261
|
+
)
|
|
262
|
+
end
|
|
263
|
+
unless FeedbackSubmissionInput::ISSUE_TYPES.include?(feedback.issue_type)
|
|
264
|
+
raise IpScopeValidationError.new(
|
|
265
|
+
"issue_type must be one of: #{FeedbackSubmissionInput::ISSUE_TYPES.join(', ')}.", field: "issue_type"
|
|
266
|
+
)
|
|
267
|
+
end
|
|
268
|
+
if feedback.evidence_url && !%r{\Ahttps?://[^\s/]+\S*\z}i.match?(feedback.evidence_url)
|
|
269
|
+
raise IpScopeValidationError.new("evidence_url must be an absolute http(s) URL.", field: "evidence_url")
|
|
270
|
+
end
|
|
271
|
+
if feedback.contact_email && !/\A[^@\s]+@[^@\s]+\.[^@\s]+\z/.match?(feedback.contact_email)
|
|
272
|
+
raise IpScopeValidationError.new("contact_email must be a valid email address.", field: "contact_email")
|
|
273
|
+
end
|
|
274
|
+
end
|
|
275
|
+
|
|
247
276
|
def fetch_and_cache_single_ip(canonical_ip, bypass_cache, options)
|
|
248
277
|
encoded = URI.encode_www_form_component(canonical_ip)
|
|
249
278
|
raw = @transport.request_json("GET", "/v1/ip/#{encoded}", options: options)
|