Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions src/main/java/io/ipinfo/api/IPinfoPlus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package io.ipinfo.api;

import io.ipinfo.api.cache.Cache;
import io.ipinfo.api.cache.SimpleCache;
import io.ipinfo.api.context.Context;
import io.ipinfo.api.errors.RateLimitedException;
import io.ipinfo.api.model.IPResponsePlus;
import io.ipinfo.api.request.IPRequestPlus;
import java.time.Duration;
import okhttp3.OkHttpClient;

public class IPinfoPlus {

private final OkHttpClient client;
private final Context context;
private final String token;
private final Cache cache;

IPinfoPlus(
OkHttpClient client,
Context context,
String token,
Cache cache
) {
this.client = client;
this.context = context;
this.token = token;
this.cache = cache;
}

public static void main(String[] args) throws RateLimitedException {
System.out.println("Running IPinfo Plus client");
}

/**
* Lookup IP information using the IP. This is a blocking call.
*
* @param ip IP address to query information for.
* @return Response containing IP information.
* @throws RateLimitedException if the user has exceeded the rate limit.
*/
public IPResponsePlus lookupIP(String ip) throws RateLimitedException {
IPRequestPlus request = new IPRequestPlus(client, token, ip);
IPResponsePlus response = request.handle();

if (response != null) {
response.setContext(context);
if (!response.getBogon()) {
cache.set(cacheKey(ip), response);
}
}

return response;
}

public static String cacheKey(String k) {
return "plus_" + k;
}

public static class Builder {

private OkHttpClient client;
private String token;
private Cache cache;

public Builder setClient(OkHttpClient client) {
this.client = client;
return this;
}

public Builder setToken(String token) {
this.token = token;
return this;
}

public Builder setCache(Cache cache) {
this.cache = cache;
return this;
}

public IPinfoPlus build() {
if (client == null) {
client = new OkHttpClient();
}
if (cache == null) {
cache = new SimpleCache(Duration.ofDays(1));
}
return new IPinfoPlus(client, new Context(), token, cache);
}
}
}
54 changes: 54 additions & 0 deletions src/main/java/io/ipinfo/api/model/ASNPlus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.ipinfo.api.model;

public class ASNPlus {
private final String asn;
private final String name;
private final String domain;
private final String type;
private final String last_changed;

public ASNPlus(
String asn,
String name,
String domain,
String type,
String last_changed
) {
this.asn = asn;
this.name = name;
this.domain = domain;
this.type = type;
this.last_changed = last_changed;
}

public String getAsn() {
return asn;
}

public String getName() {
return name;
}

public String getDomain() {
return domain;
}

public String getType() {
return type;
}

public String getLastChanged() {
return last_changed;
}

@Override
public String toString() {
return "ASNPlus{" +
"asn='" + asn + '\'' +
", name='" + name + '\'' +
", domain='" + domain + '\'' +
", type='" + type + '\'' +
", last_changed='" + last_changed + '\'' +
'}';
}
}
46 changes: 46 additions & 0 deletions src/main/java/io/ipinfo/api/model/Anonymous.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.ipinfo.api.model;

public class Anonymous {
private final Boolean is_proxy;
private final Boolean is_relay;
private final Boolean is_tor;
private final Boolean is_vpn;

public Anonymous(
Boolean is_proxy,
Boolean is_relay,
Boolean is_tor,
Boolean is_vpn
) {
this.is_proxy = is_proxy;
this.is_relay = is_relay;
this.is_tor = is_tor;
this.is_vpn = is_vpn;
}

public Boolean getIsProxy() {
return is_proxy;
}

public Boolean getIsRelay() {
return is_relay;
}

public Boolean getIsTor() {
return is_tor;
}

public Boolean getIsVpn() {
return is_vpn;
}

@Override
public String toString() {
return "Anonymous{" +
"is_proxy=" + is_proxy +
", is_relay=" + is_relay +
", is_tor=" + is_tor +
", is_vpn=" + is_vpn +
'}';
}
}
134 changes: 134 additions & 0 deletions src/main/java/io/ipinfo/api/model/GeoPlus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package io.ipinfo.api.model;

public class GeoPlus {
private final String city;
private final String region;
private final String region_code;
private final String country;
private final String country_code;
private final String continent;
private final String continent_code;
private final Double latitude;
private final Double longitude;
private final String timezone;
private final String postal_code;
private final String dma_code;
private final String geoname_id;
private final Integer radius;
private final String last_changed;

public GeoPlus(
String city,
String region,
String region_code,
String country,
String country_code,
String continent,
String continent_code,
Double latitude,
Double longitude,
String timezone,
String postal_code,
String dma_code,
String geoname_id,
Integer radius,
String last_changed
) {
this.city = city;
this.region = region;
this.region_code = region_code;
this.country = country;
this.country_code = country_code;
this.continent = continent;
this.continent_code = continent_code;
this.latitude = latitude;
this.longitude = longitude;
this.timezone = timezone;
this.postal_code = postal_code;
this.dma_code = dma_code;
this.geoname_id = geoname_id;
this.radius = radius;
this.last_changed = last_changed;
}

public String getCity() {
return city;
}

public String getRegion() {
return region;
}

public String getRegionCode() {
return region_code;
}

public String getCountry() {
return country;
}

public String getCountryCode() {
return country_code;
}

public String getContinent() {
return continent;
}

public String getContinentCode() {
return continent_code;
}

public Double getLatitude() {
return latitude;
}

public Double getLongitude() {
return longitude;
}

public String getTimezone() {
return timezone;
}

public String getPostalCode() {
return postal_code;
}

public String getDmaCode() {
return dma_code;
}

public String getGeonameId() {
return geoname_id;
}

public Integer getRadius() {
return radius;
}

public String getLastChanged() {
return last_changed;
}

@Override
public String toString() {
return "GeoPlus{" +
"city='" + city + '\'' +
", region='" + region + '\'' +
", region_code='" + region_code + '\'' +
", country='" + country + '\'' +
", country_code='" + country_code + '\'' +
", continent='" + continent + '\'' +
", continent_code='" + continent_code + '\'' +
", latitude=" + latitude +
", longitude=" + longitude +
", timezone='" + timezone + '\'' +
", postal_code='" + postal_code + '\'' +
", dma_code='" + dma_code + '\'' +
", geoname_id='" + geoname_id + '\'' +
", radius=" + radius +
", last_changed='" + last_changed + '\'' +
'}';
}
}
Loading