Skip to content

Commit c4c7fdd

Browse files
authored
Merge pull request #24 from ipinfo/uman/updates
Batch ops, new types & map integration
2 parents 4e81774 + 735847f commit c4c7fdd

27 files changed

+1234
-334
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 2.0.0
2+
3+
Breaking changes:
4+
5+
- `IPInfo` is renamed to `IPinfo`.
6+
- `IPInfoBuilder` is moved into `IPinfo.Builder`.
7+
- `ASNResponse.numIps` is now an `Integer` instead of a `String`.
8+
- The cache implementation now only uses `get` and `set`, which accept
9+
arbitrary strings, which may not necessarily be IP or ASN strings like
10+
"1.2.3.4" and "AS123".
11+
12+
Additions:
13+
14+
- `getBatch`, `getBatchIps` and `getBatchAsns` allow you to do lookups of
15+
multiple entities at once. There is no limit to the size of inputs on these
16+
library calls as long as your token has quota.
17+
- `getMap` will give you a map URL for https://ipinfo.io/tools/map given a list
18+
of IPs.
19+
- Many new pieces of data have been added that were previously missing. The new
20+
dataset reflects all the new data available via raw API calls.
21+
- The keys given to cache functions will now be versioned. `IPinfo.cacheKey`
22+
must be used to derive the correct key if doing manual lookups.

README.md

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
[![Travis](https://travis-ci.com/ipinfo/java.svg?branch=master&style=flat-square)](https://travis-ci.com/ipinfo/java)
55

66
This is the official Java client library for the [IPinfo.io](https://ipinfo.io) IP address API, allowing you to lookup your own IP address, or get any of the following details for an IP:
7+
78
- [IP geolocation data](https://ipinfo.io/ip-geolocation-api) (city, region, country, postal code, latitude and longitude)
89
- [ASN information](https://ipinfo.io/asn-api) (ISP or network operator, associated domain name, and type, such as business, hosting or company)
910
- [Company data](https://ipinfo.io/ip-company-api) (the name and domain of the business that uses the IP address)
@@ -13,13 +14,14 @@ Check all the data we have for your IP address [here](https://ipinfo.io/what-is-
1314

1415
### Getting Started
1516

16-
You'll need an IPinfo API access token, which you can get by singing up for a free account at [https://ipinfo.io/signup](https://ipinfo.io/signup).
17+
You'll need an IPinfo API access token, which you can get by singing up for a free account at [https://ipinfo.io/signup](https://ipinfo.io/signup).
1718

1819
The free plan is limited to 50,000 requests per month, and doesn't include some of the data fields such as IP type and company data. To enable all the data fields and additional request volumes see [https://ipinfo.io/pricing](https://ipinfo.io/pricing)
1920

2021
#### Installation
2122

2223
##### Maven
24+
2325
Add these values to your pom.xml file:
2426

2527
Dependency:
@@ -29,7 +31,7 @@ Dependency:
2931
<dependency>
3032
<groupId>io.ipinfo</groupId>
3133
<artifactId>ipinfo-api</artifactId>
32-
<version>1.0</version>
34+
<version>2.0</version>
3335
<scope>compile</scope>
3436
</dependency>
3537
</dependencies>
@@ -39,16 +41,16 @@ Dependency:
3941

4042
##### IP Information
4143

42-
4344
````java
44-
import io.ipinfo.api.IPInfo;
45+
import io.ipinfo.api.IPinfo;
4546
import io.ipinfo.api.errors.RateLimitedException;
4647
import io.ipinfo.api.model.IPResponse;
4748

4849
public class Main {
49-
5050
public static void main(String... args) {
51-
IPInfo ipInfo = IPInfo.builder().setToken("YOUR TOKEN").build();
51+
IPinfo ipInfo = new IPinfo.Builder()
52+
.setToken("YOUR TOKEN")
53+
.build();
5254

5355
try {
5456
IPResponse response = ipInfo.lookupIP("8.8.8.8");
@@ -62,18 +64,18 @@ public class Main {
6264
}
6365
````
6466

65-
6667
##### ASN Information
6768

6869
````java
69-
import io.ipinfo.api.IPInfo;
70+
import io.ipinfo.api.IPinfo;
7071
import io.ipinfo.api.errors.RateLimitedException;
7172
import io.ipinfo.api.model.IPResponse;
7273

7374
public class Main {
74-
7575
public static void main(String... args) {
76-
IPInfo ipInfo = IPInfo.builder().setToken("YOUR TOKEN").build();
76+
IPinfo ipInfo = new IPinfo.Builder()
77+
.setToken("YOUR TOKEN")
78+
.build();
7779

7880
try {
7981
ASNResponse response = ipInfo.lookupASN("AS7922");
@@ -89,29 +91,36 @@ public class Main {
8991

9092
#### Errors
9193

92-
- ErrorResponseException: A runtime exception accessible through the ExecutionException of a future. This exception signals that something went wrong when mapping the API response to the wrapper. You probably can't recover from this exception.
93-
94-
- RateLimitedException An exception signalling that you've been rate limited.
94+
- `ErrorResponseException`: A runtime exception accessible through the
95+
`ExecutionException` of a future. This exception signals that something went
96+
wrong when mapping the API response to the wrapper. You probably can't
97+
recover from this exception.
98+
- `RateLimitedException` An exception signalling that you've been rate limited.
9599

96100
#### Caching
97101

98-
This library provides a very simple caching system accessible in `SimpleCache`. Simple cache is an in memory caching system that resets every time you restart your code.
99-
100-
If you prefer a different caching methodology, you may use the `Cache` interface and implement your own caching system around your own infrastructure.
102+
This library provides a very simple caching system accessible in `SimpleCache`.
103+
Simple cache is an in memory caching system that resets every time you restart
104+
your code.
101105

102-
The default cache length is 1 day, this can be changed by calling the SimpleCache constructor yourself.
106+
If you prefer a different caching methodology, you may use the `Cache`
107+
interface and implement your own caching system around your own infrastructure.
103108

109+
The default cache length is 1 day, this can be changed by calling the
110+
SimpleCache constructor yourself.
104111

105112
```java
106-
import io.ipinfo.api.IPInfo;
113+
import io.ipinfo.api.IPinfo;
107114
import io.ipinfo.api.errors.RateLimitedException;
108115
import io.ipinfo.api.model.IPResponse;
109116

110117
public class Main {
111-
112118
public static void main(String... args) {
113119
// 5 Day Cache
114-
IPInfo ipInfo = IPInfo.builder().setToken("YOUR TOKEN").setCache(new SimpleCache(Duration.ofDays(5))).build();
120+
IPinfo ipInfo = new IPinfo.Builder()
121+
.setToken("YOUR TOKEN")
122+
.setCache(new SimpleCache(Duration.ofDays(5)))
123+
.build();
115124

116125
try {
117126
IPResponse response = ipInfo.lookupIP("8.8.8.8");
@@ -127,19 +136,24 @@ public class Main {
127136

128137
#### Country Name Lookup
129138

130-
This library provides a system to lookup country names through ISO2 country codes.
139+
This library provides a system to lookup country names through ISO2 country
140+
codes.
131141

132-
By default, this translation exists for English (United States). If you wish to provide a different language mapping, just use the following system in the builder:
142+
By default, this translation exists for English (United States). If you wish to
143+
provide a different language mapping, just use the following system in the
144+
builder:
133145

134146
```java
135-
import io.ipinfo.api.IPInfo;
147+
import io.ipinfo.api.IPinfo;
136148
import io.ipinfo.api.errors.RateLimitedException;
137149
import io.ipinfo.api.model.IPResponse;
138150

139151
public class Main {
140-
141152
public static void main(String... args) {
142-
IPInfo ipInfo = IPInfo.builder().setToken("YOUR TOKEN").setCountryFile(new File("path/to/file.json")).build();
153+
IPinfo ipInfo = new IPinfo.Builder()
154+
.setToken("YOUR TOKEN")
155+
.setCountryFile(new File("path/to/file.json"))
156+
.build();
143157

144158
try {
145159
IPResponse response = ipInfo.lookupIP("8.8.8.8");
@@ -165,14 +179,16 @@ More language files can be found [here](https://country.io/data)
165179
This library provides an easy way to get the latitude and longitude of an IP Address:
166180

167181
```java
168-
import io.ipinfo.api.IPInfo;
182+
import io.ipinfo.api.IPinfo;
169183
import io.ipinfo.api.errors.RateLimitedException;
170184
import io.ipinfo.api.model.IPResponse;
171185

172186
public class Main {
173-
174187
public static void main(String... args) {
175-
IPInfo ipInfo = IPInfo.builder().setToken("YOUR TOKEN").setCountryFile(new File("path/to/file.json")).build();
188+
IPinfo ipInfo = new IPinfo.Builder()
189+
.setToken("YOUR TOKEN")
190+
.setCountryFile(new File("path/to/file.json"))
191+
.build();
176192

177193
try {
178194
IPResponse response = ipInfo.lookupIP("8.8.8.8");
@@ -190,13 +206,14 @@ public class Main {
190206

191207
#### Extra Information
192208

193-
- This library is thread safe. Feel free to call the different endpoints from different threads.
194-
- This library uses square's http client. Please refer to their documentation to get information on more functionality you can use.
195-
209+
- This library is thread safe. Feel free to call the different endpoints from
210+
different threads.
211+
- This library uses square's http client. Please refer to their documentation
212+
to get information on more functionality you can use.
196213

197214
### Other Libraries
198215

199-
There are official [IPinfo client libraries](https://ipinfo.io/developers/libraries) available for many languages including PHP, Python, Go, Java, Ruby, and many popular frameworks such as Django, Rails and Laravel. There are also many third party libraries and integrations available for our API.
216+
There are official [IPinfo client libraries](https://ipinfo.io/developers/libraries) available for many languages including PHP, Python, Go, Java, Ruby, and many popular frameworks such as Django, Rails and Laravel. There are also many third party libraries and integrations available for our API.
200217

201218
### About IPinfo
202219

pom.xml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>io.ipinfo</groupId>
66
<artifactId>ipinfo-api</artifactId>
7-
<version>1.2-SNAPSHOT</version>
7+
<version>2.0</version>
88
<packaging>jar</packaging>
99

1010
<parent>
@@ -42,25 +42,25 @@
4242
</scm>
4343

4444
<developers>
45-
<developer>
46-
<id>aaomidi</id>
47-
<name>Amir Omidi</name>
48-
<email>[email protected]</email>
49-
<organization>IPinfo</organization>
50-
</developer>
5145
<developer>
5246
<id>ipinfo</id>
5347
<name>IPinfo</name>
5448
<email>[email protected]</email>
5549
<organization>IPinfo</organization>
5650
</developer>
51+
<developer>
52+
<id>aaomidi</id>
53+
<name>Amir Omidi</name>
54+
<email>[email protected]</email>
55+
<organization>IPinfo</organization>
56+
</developer>
5757
</developers>
5858

5959
<dependencies>
6060
<dependency>
6161
<groupId>com.google.code.gson</groupId>
6262
<artifactId>gson</artifactId>
63-
<version>2.8.2</version>
63+
<version>2.8.7</version>
6464
<scope>compile</scope>
6565
</dependency>
6666
<dependency>
@@ -69,6 +69,12 @@
6969
<version>3.9.0</version>
7070
<scope>compile</scope>
7171
</dependency>
72+
<dependency>
73+
<groupId>com.google.guava</groupId>
74+
<artifactId>guava</artifactId>
75+
<version>30.1.1-jre</version>
76+
<scope>compile</scope>
77+
</dependency>
7278
<dependency>
7379
<groupId>org.junit.jupiter</groupId>
7480
<artifactId>junit-jupiter-api</artifactId>

src/main/java/io/ipinfo/api/IPInfo.java

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)