Skip to content

Commit 1cad347

Browse files
authored
Merge pull request #61 from ipinfo/silvano/eng-491-add-plus-bundle-support-in-ipinfojava-library
Add support for Plus bundle
2 parents dd53a86 + 2313177 commit 1cad347

File tree

8 files changed

+713
-0
lines changed

8 files changed

+713
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package io.ipinfo.api;
2+
3+
import io.ipinfo.api.cache.Cache;
4+
import io.ipinfo.api.cache.SimpleCache;
5+
import io.ipinfo.api.context.Context;
6+
import io.ipinfo.api.errors.RateLimitedException;
7+
import io.ipinfo.api.model.IPResponsePlus;
8+
import io.ipinfo.api.request.IPRequestPlus;
9+
import java.time.Duration;
10+
import okhttp3.OkHttpClient;
11+
12+
public class IPinfoPlus {
13+
14+
private final OkHttpClient client;
15+
private final Context context;
16+
private final String token;
17+
private final Cache cache;
18+
19+
IPinfoPlus(
20+
OkHttpClient client,
21+
Context context,
22+
String token,
23+
Cache cache
24+
) {
25+
this.client = client;
26+
this.context = context;
27+
this.token = token;
28+
this.cache = cache;
29+
}
30+
31+
public static void main(String[] args) throws RateLimitedException {
32+
System.out.println("Running IPinfo Plus client");
33+
}
34+
35+
/**
36+
* Lookup IP information using the IP. This is a blocking call.
37+
*
38+
* @param ip IP address to query information for.
39+
* @return Response containing IP information.
40+
* @throws RateLimitedException if the user has exceeded the rate limit.
41+
*/
42+
public IPResponsePlus lookupIP(String ip) throws RateLimitedException {
43+
IPRequestPlus request = new IPRequestPlus(client, token, ip);
44+
IPResponsePlus response = request.handle();
45+
46+
if (response != null) {
47+
response.setContext(context);
48+
if (!response.getBogon()) {
49+
cache.set(cacheKey(ip), response);
50+
}
51+
}
52+
53+
return response;
54+
}
55+
56+
public static String cacheKey(String k) {
57+
return "plus_" + k;
58+
}
59+
60+
public static class Builder {
61+
62+
private OkHttpClient client;
63+
private String token;
64+
private Cache cache;
65+
66+
public Builder setClient(OkHttpClient client) {
67+
this.client = client;
68+
return this;
69+
}
70+
71+
public Builder setToken(String token) {
72+
this.token = token;
73+
return this;
74+
}
75+
76+
public Builder setCache(Cache cache) {
77+
this.cache = cache;
78+
return this;
79+
}
80+
81+
public IPinfoPlus build() {
82+
if (client == null) {
83+
client = new OkHttpClient();
84+
}
85+
if (cache == null) {
86+
cache = new SimpleCache(Duration.ofDays(1));
87+
}
88+
return new IPinfoPlus(client, new Context(), token, cache);
89+
}
90+
}
91+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package io.ipinfo.api.model;
2+
3+
public class ASNPlus {
4+
private final String asn;
5+
private final String name;
6+
private final String domain;
7+
private final String type;
8+
private final String last_changed;
9+
10+
public ASNPlus(
11+
String asn,
12+
String name,
13+
String domain,
14+
String type,
15+
String last_changed
16+
) {
17+
this.asn = asn;
18+
this.name = name;
19+
this.domain = domain;
20+
this.type = type;
21+
this.last_changed = last_changed;
22+
}
23+
24+
public String getAsn() {
25+
return asn;
26+
}
27+
28+
public String getName() {
29+
return name;
30+
}
31+
32+
public String getDomain() {
33+
return domain;
34+
}
35+
36+
public String getType() {
37+
return type;
38+
}
39+
40+
public String getLastChanged() {
41+
return last_changed;
42+
}
43+
44+
@Override
45+
public String toString() {
46+
return "ASNPlus{" +
47+
"asn='" + asn + '\'' +
48+
", name='" + name + '\'' +
49+
", domain='" + domain + '\'' +
50+
", type='" + type + '\'' +
51+
", last_changed='" + last_changed + '\'' +
52+
'}';
53+
}
54+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package io.ipinfo.api.model;
2+
3+
public class Anonymous {
4+
private final Boolean is_proxy;
5+
private final Boolean is_relay;
6+
private final Boolean is_tor;
7+
private final Boolean is_vpn;
8+
9+
public Anonymous(
10+
Boolean is_proxy,
11+
Boolean is_relay,
12+
Boolean is_tor,
13+
Boolean is_vpn
14+
) {
15+
this.is_proxy = is_proxy;
16+
this.is_relay = is_relay;
17+
this.is_tor = is_tor;
18+
this.is_vpn = is_vpn;
19+
}
20+
21+
public Boolean getIsProxy() {
22+
return is_proxy;
23+
}
24+
25+
public Boolean getIsRelay() {
26+
return is_relay;
27+
}
28+
29+
public Boolean getIsTor() {
30+
return is_tor;
31+
}
32+
33+
public Boolean getIsVpn() {
34+
return is_vpn;
35+
}
36+
37+
@Override
38+
public String toString() {
39+
return "Anonymous{" +
40+
"is_proxy=" + is_proxy +
41+
", is_relay=" + is_relay +
42+
", is_tor=" + is_tor +
43+
", is_vpn=" + is_vpn +
44+
'}';
45+
}
46+
}
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package io.ipinfo.api.model;
2+
3+
public class GeoPlus {
4+
private final String city;
5+
private final String region;
6+
private final String region_code;
7+
private final String country;
8+
private final String country_code;
9+
private final String continent;
10+
private final String continent_code;
11+
private final Double latitude;
12+
private final Double longitude;
13+
private final String timezone;
14+
private final String postal_code;
15+
private final String dma_code;
16+
private final String geoname_id;
17+
private final Integer radius;
18+
private final String last_changed;
19+
20+
public GeoPlus(
21+
String city,
22+
String region,
23+
String region_code,
24+
String country,
25+
String country_code,
26+
String continent,
27+
String continent_code,
28+
Double latitude,
29+
Double longitude,
30+
String timezone,
31+
String postal_code,
32+
String dma_code,
33+
String geoname_id,
34+
Integer radius,
35+
String last_changed
36+
) {
37+
this.city = city;
38+
this.region = region;
39+
this.region_code = region_code;
40+
this.country = country;
41+
this.country_code = country_code;
42+
this.continent = continent;
43+
this.continent_code = continent_code;
44+
this.latitude = latitude;
45+
this.longitude = longitude;
46+
this.timezone = timezone;
47+
this.postal_code = postal_code;
48+
this.dma_code = dma_code;
49+
this.geoname_id = geoname_id;
50+
this.radius = radius;
51+
this.last_changed = last_changed;
52+
}
53+
54+
public String getCity() {
55+
return city;
56+
}
57+
58+
public String getRegion() {
59+
return region;
60+
}
61+
62+
public String getRegionCode() {
63+
return region_code;
64+
}
65+
66+
public String getCountry() {
67+
return country;
68+
}
69+
70+
public String getCountryCode() {
71+
return country_code;
72+
}
73+
74+
public String getContinent() {
75+
return continent;
76+
}
77+
78+
public String getContinentCode() {
79+
return continent_code;
80+
}
81+
82+
public Double getLatitude() {
83+
return latitude;
84+
}
85+
86+
public Double getLongitude() {
87+
return longitude;
88+
}
89+
90+
public String getTimezone() {
91+
return timezone;
92+
}
93+
94+
public String getPostalCode() {
95+
return postal_code;
96+
}
97+
98+
public String getDmaCode() {
99+
return dma_code;
100+
}
101+
102+
public String getGeonameId() {
103+
return geoname_id;
104+
}
105+
106+
public Integer getRadius() {
107+
return radius;
108+
}
109+
110+
public String getLastChanged() {
111+
return last_changed;
112+
}
113+
114+
@Override
115+
public String toString() {
116+
return "GeoPlus{" +
117+
"city='" + city + '\'' +
118+
", region='" + region + '\'' +
119+
", region_code='" + region_code + '\'' +
120+
", country='" + country + '\'' +
121+
", country_code='" + country_code + '\'' +
122+
", continent='" + continent + '\'' +
123+
", continent_code='" + continent_code + '\'' +
124+
", latitude=" + latitude +
125+
", longitude=" + longitude +
126+
", timezone='" + timezone + '\'' +
127+
", postal_code='" + postal_code + '\'' +
128+
", dma_code='" + dma_code + '\'' +
129+
", geoname_id='" + geoname_id + '\'' +
130+
", radius=" + radius +
131+
", last_changed='" + last_changed + '\'' +
132+
'}';
133+
}
134+
}

0 commit comments

Comments
 (0)