Skip to content

Commit 6d1d95c

Browse files
committed
Add is_satellite, is_anycast and blocklist first/last/days seen fields
The API now flags satellite ISP addresses (is_satellite) and anycast addresses (is_anycast) next to is_eu, sending each key only when it is true, and every threat.blocklists entry may carry first_seen and last_seen (YYYY-MM-DD, UTC) and days_seen; some feeds, such as ipdata's own vpn feed, omit all three. IpdataModel gains primitive booleans mapped like is_eu (isSatellite(), isAnycast()) that read false when the key is absent. Blocklist gains nullable String firstSeen/lastSeen and Integer daysSeen; the dates stay strings (no new dependency, no format coupling). IpdataField gains IS_SATELLITE and IS_ANYCAST for getFields(...), and the single-field service methods isSatellite(ip) and isAnycast(ip) follow the existing GET /{ip}/{field} pattern. The Jackson decoder already ignores unknown properties (FAIL_ON_UNKNOWN_PROPERTIES is false); a test now covers it. Tests: fixtures built from the API samples (98.97.34.0 satellite ISP, 8.8.8.8 extended with is_anycast and two dated blocklist entries, 187.13.250.1 VPN exit whose third blocklist entry has no dates); NewResponseFieldsTest asserts the typed values, the false-when-absent behaviour, the single-field endpoints, field selection with the new names, bulk responses and unknown-key tolerance, with and without the cache. The README documents the five fields and the new methods. Claude-Session: https://claude.ai/code/session_01VQiRp4zEJKUXHrKkFaeUke Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 3685a51 commit 6d1d95c

11 files changed

Lines changed: 530 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ Output:
144144
}
145145
```
146146

147+
The following fields were added to the API responses recently and are mapped by the model (every other field is described in the [API reference](https://docs.ipdata.co/api-reference/response-fields)):
148+
149+
- `is_satellite` – `model.isSatellite()`: the address belongs to a satellite ISP. The API sends the key only when it is `true`; the model reads `false` when it is absent.
150+
- `is_anycast` – `model.isAnycast()`: the address is an anycast address (`8.8.8.8` for example). Same present-only-when-true behaviour.
151+
- `threat.blocklists[].first_seen` – `Blocklist.getFirstSeen()`: the first day the address was seen on that blocklist, as a `YYYY-MM-DD` (UTC) string, or `null` when the feed does not report it.
152+
- `threat.blocklists[].last_seen` – `Blocklist.getLastSeen()`: the most recent such day, same format, or `null`.
153+
- `threat.blocklists[].days_seen` – `Blocklist.getDaysSeen()`: the number of days the address was seen on that blocklist, as an `Integer`, or `null`.
154+
147155
#### Connection reuse and HTTP/2
148156
An `IpdataService` keeps a persistent HTTPS connection pool for as long as it lives. Create one service per process (or one per API key or endpoint), keep it, and reuse it for every lookup: each new service pays a fresh TLS handshake. Requests to api.ipdata.co are multiplexed over HTTP/2 when the platform negotiates it, and fall back to HTTP/1.1 keep-alive otherwise.
149157

@@ -177,6 +185,8 @@ exposes a method on each available field:
177185

178186
```java
179187
boolean isEu = ipdataService.isEu("1.1.1.1");
188+
boolean isSatellite = ipdataService.isSatellite("1.1.1.1");
189+
boolean isAnycast = ipdataService.isAnycast("1.1.1.1");
180190
AsnModel asn = ipdataService.asn("1.1.1.1");
181191
TimeZone tz = ipdataService.timeZone("1.1.1.1");
182192
ThreatModel threat = ipdataService.threat("1.1.1.1");
@@ -192,6 +202,7 @@ import io.ipdata.client.service.IpdataService;
192202

193203
/* The model will be hydrated by the selected fields only */
194204
IpdataModel model = ipdataService.getFields("1.1.1.1", IpdataField.ASN, IpdataField.CURRENCY);
205+
IpdataModel flags = ipdataService.getFields("1.1.1.1", IpdataField.IS_SATELLITE, IpdataField.IS_ANYCAST);
195206

196207
```
197208

‎src/main/java/io/ipdata/client/model/Blocklist.java‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.ipdata.client.model;
22

3+
import com.fasterxml.jackson.annotation.JsonProperty;
34
import lombok.Getter;
45
import lombok.ToString;
56

@@ -8,4 +9,21 @@ public class Blocklist {
89
private String name;
910
private String site;
1011
private String type;
12+
/**
13+
* First day the address was seen on this blocklist, as a {@code YYYY-MM-DD} (UTC) string, or {@code null}
14+
* when the feed does not report it.
15+
*/
16+
@JsonProperty("first_seen")
17+
private String firstSeen;
18+
/**
19+
* Most recent day the address was seen on this blocklist, as a {@code YYYY-MM-DD} (UTC) string, or
20+
* {@code null} when the feed does not report it.
21+
*/
22+
@JsonProperty("last_seen")
23+
private String lastSeen;
24+
/**
25+
* Number of days the address was seen on this blocklist, or {@code null} when the feed does not report it.
26+
*/
27+
@JsonProperty("days_seen")
28+
private Integer daysSeen;
1129
}

‎src/main/java/io/ipdata/client/model/IpdataModel.java‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ public class IpdataModel {
1414
private String ip;
1515
@JsonProperty("is_eu")
1616
private boolean eu;
17+
/**
18+
* The address belongs to a satellite ISP. The API sends the key only when it is true, so the field reads
19+
* {@code false} when it is absent.
20+
*/
21+
@JsonProperty("is_satellite")
22+
private boolean satellite;
23+
/**
24+
* The address is an anycast address. The API sends the key only when it is true, so the field reads
25+
* {@code false} when it is absent.
26+
*/
27+
@JsonProperty("is_anycast")
28+
private boolean anycast;
1729
private String city;
1830
private String organisation;
1931

@@ -44,4 +56,12 @@ public class IpdataModel {
4456
public boolean isEu() {
4557
return eu;
4658
}
59+
60+
public boolean isSatellite() {
61+
return satellite;
62+
}
63+
64+
public boolean isAnycast() {
65+
return anycast;
66+
}
4767
}

‎src/main/java/io/ipdata/client/service/IpdataField.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
public class IpdataField<T> {
1515
public static final IpdataField<String> IP = new IpdataField<String>("ip", String.class);
1616
public static final IpdataField<Boolean> IS_EU = new IpdataField<Boolean>("is_eu", Boolean.class);
17+
public static final IpdataField<Boolean> IS_SATELLITE = new IpdataField<Boolean>("is_satellite", Boolean.class);
18+
public static final IpdataField<Boolean> IS_ANYCAST = new IpdataField<Boolean>("is_anycast", Boolean.class);
1719
public static final IpdataField<String> CITY = new IpdataField<String>("city", String.class);
1820
public static final IpdataField<String> REGION = new IpdataField<String>("region", String.class);
1921
public static final IpdataField<String> REGION_CODE = new IpdataField<String>("region_code", String.class);

‎src/main/java/io/ipdata/client/service/IpdataInternalSingleFieldClient.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ interface IpdataInternalSingleFieldClient {
1616
@RequestLine("GET /{ip}/is_eu")
1717
boolean isEu(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
1818

19+
@RequestLine("GET /{ip}/is_satellite")
20+
boolean isSatellite(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
21+
22+
@RequestLine("GET /{ip}/is_anycast")
23+
boolean isAnycast(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
24+
1925
@RequestLine("GET /{ip}/city")
2026
String getCity(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
2127

‎src/test/java/io/ipdata/client/MockIpdataServer.java‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.HashMap;
2020
import java.util.List;
2121
import java.util.Map;
22+
import java.util.concurrent.ConcurrentHashMap;
2223

2324
public class MockIpdataServer {
2425

@@ -28,9 +29,10 @@ public class MockIpdataServer {
2829

2930
private final HttpServer server;
3031
private final String url;
31-
private final Map<String, JsonNode> fixtures = new HashMap<>();
32+
private final Map<String, JsonNode> fixtures = new ConcurrentHashMap<>();
3233
private final ObjectMapper mapper = new ObjectMapper();
3334
private volatile String lastRawPath;
35+
private volatile String lastRawQuery;
3436
private volatile String lastProtocol;
3537
/** The client socket address (IP and ephemeral port) of every request received, in order. */
3638
private final List<InetSocketAddress> remoteAddresses = Collections.synchronizedList(new ArrayList<>());
@@ -63,6 +65,23 @@ public String getLastRawPath() {
6365
return lastRawPath;
6466
}
6567

68+
/** @return the raw (still percent-encoded) query string of the last request received, or {@code null} */
69+
public String getLastRawQuery() {
70+
return lastRawQuery;
71+
}
72+
73+
/**
74+
* Registers (or replaces) the response served for an IP address, for tests that need a shape the fixture
75+
* files do not have.
76+
*
77+
* @param ip the address, as it appears in request paths
78+
* @param json the full response body
79+
* @throws IOException if {@code json} is not valid JSON
80+
*/
81+
public void registerFixture(String ip, String json) throws IOException {
82+
fixtures.put(ip, mapper.readTree(json));
83+
}
84+
6685
/** @return the protocol of the last request received, for example {@code HTTP/1.1} */
6786
public String getLastProtocol() {
6887
return lastProtocol;
@@ -86,7 +105,8 @@ public List<InetSocketAddress> getRemoteAddresses() {
86105
}
87106

88107
private void loadFixtures() {
89-
String[] ips = {"8.8.8.8", "2001:4860:4860::8888", "1.1.1.1", "2001:4860:4860::8844", "41.128.21.123"};
108+
String[] ips = {"8.8.8.8", "2001:4860:4860::8888", "1.1.1.1", "2001:4860:4860::8844", "41.128.21.123",
109+
"98.97.34.0", "187.13.250.1"};
90110
for (String ip : ips) {
91111
String resourceName = "fixtures/" + ip.replace(":", "-") + ".json";
92112
try (InputStream is = getClass().getResourceAsStream(resourceName)) {
@@ -107,6 +127,7 @@ private void handleRequest(HttpExchange exchange) throws IOException {
107127
String path = exchange.getRequestURI().getPath();
108128
lastRawPath = exchange.getRequestURI().getRawPath();
109129
String rawQuery = exchange.getRequestURI().getRawQuery();
130+
lastRawQuery = rawQuery;
110131
Map<String, String> params = parseQuery(rawQuery);
111132

112133
String apiKey = params.get("api-key");

0 commit comments

Comments
 (0)