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
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,15 @@ IpdataService ipdataService = Ipdata.builder().url(url)
.key("MY_KEY").get();
/.../
```
Optionally, you can configure a cache for faster access (less than 1ms latency on requests that hit the cache).

To use the EU endpoint for GDPR compliance, pass the EU API URL instead:
```java
URL url = new URL("https://eu-api.ipdata.co");
IpdataService ipdataService = Ipdata.builder().url(url)
.key("MY_KEY").get();
```

Optionally, you can configure a cache for faster access (less than 1ms latency on requests that hit the cache).

The cache is configurable for time and space eviction policies:

Expand Down Expand Up @@ -79,6 +87,7 @@ Output:
"city": null,
"region": null,
"region_code": null,
"region_type": null,
"country_name": "Australia",
"country_code": "AU",
"continent_name": "Oceania",
Expand All @@ -97,6 +106,12 @@ Output:
"route": "1.1.1.0/24",
"type": "hosting"
},
"company": {
"name": "Cloudflare, Inc.",
"domain": "cloudflare.com",
"network": "1.1.1.0/24",
"type": "hosting"
},
"languages": [
{
"name": "English",
Expand Down Expand Up @@ -124,7 +139,9 @@ Output:
"is_known_attacker": false,
"is_known_abuser": false,
"is_threat": false,
"is_bogon": false
"is_bogon": false,
"is_icloud_relay": false,
"is_datacenter": false
},
"count": "0"
}
Expand Down
36 changes: 18 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
</snapshotRepository>
</distributionManagement>
<properties>
<maven.compiler.source>6</maven.compiler.source>
<maven.compiler.target>6</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<sonar.coverage.jacoco.xmlReportPaths>${project.build.directory}/site/code-coverage/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
Expand All @@ -48,10 +48,10 @@
<sonar.projectKey>yassine_ipdata-java-client</sonar.projectKey>
<sonar.projectName>ipdata-java-client</sonar.projectName>
<sonar.projectVersion>${project.version}</sonar.projectVersion>
<version.build.jacoco>0.8.4</version.build.jacoco>
<version.build.sonar>3.7.0.1746</version.build.sonar>
<version.build.surefire>3.0.0-M3</version.build.surefire>
<version.client.feign>9.7.0</version.client.feign>
<version.build.jacoco>0.8.14</version.build.jacoco>
<version.build.sonar>3.11.0.3922</version.build.sonar>
<version.build.surefire>3.5.5</version.build.surefire>
<version.client.feign>11.10</version.client.feign>
</properties>
<dependencies>
<dependency>
Expand All @@ -72,22 +72,22 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>20.0</version>
<version>33.4.8-jre</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.30</version>
<version>1.7.36</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<version>1.18.38</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
Expand All @@ -98,13 +98,13 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.javacrumbs.json-unit</groupId>
<artifactId>json-unit</artifactId>
<version>2.17.0</version>
<version>2.40.1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -121,7 +121,7 @@
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<version>3.3.1</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
Expand Down Expand Up @@ -175,7 +175,7 @@
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<version>3.3.1</version>
<executions>
<execution>
<goals>
Expand All @@ -186,7 +186,7 @@
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.1.1</version>
<version>3.12.0</version>
<executions>
<execution>
<goals>
Expand All @@ -198,8 +198,8 @@
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<version>1.7.0</version>
<extensions>false</extensions>
<configuration>
<serverId>maven-central-staging</serverId>
<nexusUrl>https://oss.sonatype.org</nexusUrl>
Expand All @@ -208,7 +208,7 @@
</plugin>
<plugin>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<version>3.2.8</version>
<configuration>
<keyname>A143FB3D9A4D90CC76DE768495FD65EAEFC32F7E</keyname>
</configuration>
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/io/ipdata/client/model/Company.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.ipdata.client.model;

import lombok.Getter;
import lombok.ToString;
import lombok.experimental.Accessors;

@ToString @Getter @Accessors(fluent = true)
public class Company {
private String name;
private String domain;
private String network;
private String type;
}
2 changes: 2 additions & 0 deletions src/main/java/io/ipdata/client/model/IpdataModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class IpdataModel {

private String region;
private String regionCode;
private String regionType;
private String countryName;
private String countryCode;
private String continentName;
Expand All @@ -35,6 +36,7 @@ public class IpdataModel {
private String emojiUnicode;
private AsnModel asn;
private Carrier carrier;
private Company company;
private List<Language> languages;
private Currency currency;
private TimeZone timeZone;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/ipdata/client/model/ThreatModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public class ThreatModel {
private boolean threat;
@JsonProperty("is_bogon")
private boolean bogon;
@JsonProperty("is_icloud_relay")
private boolean icloudRelay;
@JsonProperty("is_datacenter")
private boolean datacenter;
}
6 changes: 5 additions & 1 deletion src/main/java/io/ipdata/client/service/IpdataField.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ public class IpdataField<T> {
public static final IpdataField<Boolean> IS_EU = new IpdataField<Boolean>("is_eu", Boolean.class);
public static final IpdataField<String> CITY = new IpdataField<String>("city", String.class);
public static final IpdataField<String> REGION = new IpdataField<String>("region", String.class);
public static final IpdataField<String> REGION_CODE = new IpdataField<String>("region_code", String.class);
public static final IpdataField<String> REGION_TYPE = new IpdataField<String>("region_type", String.class);
public static final IpdataField<String> COUNTRY_NAME = new IpdataField<String>("country_name", String.class);
public static final IpdataField<String> COUNTRY_CODE = new IpdataField<String>("country_code", String.class);
public static final IpdataField<String> CONTINENT_CODE = new IpdataField<String>("continent_code", String.class);
public static final IpdataField<String> CONTINENT_NAME = new IpdataField<String>("continent_name", String.class);
public static final IpdataField<Double> LATITUDE = new IpdataField<Double>("latitude", Double.class);
public static final IpdataField<Double> LONGITUDE = new IpdataField<Double>("longitude", Double.class);
public static final IpdataField<AsnModel> ASN = new IpdataField<AsnModel>("asn", AsnModel.class);
Expand All @@ -29,10 +32,11 @@ public class IpdataField<T> {
public static final IpdataField<String> EMOJI_FLAG = new IpdataField<String>("emoji_flag", String.class);
public static final IpdataField<String> EMOJI_UNICODE = new IpdataField<String>("emoji_unicode", String.class);
public static final IpdataField<Carrier> CARRIER = new IpdataField<Carrier>("carrier", Carrier.class);
public static final IpdataField<Company> COMPANY = new IpdataField<Company>("company", Company.class);
public static final IpdataField<Language> LANGUAGES = new IpdataField<Language>("languages", Language.class);
public static final IpdataField<Currency> CURRENCY = new IpdataField<Currency>("currency", Currency.class);
public static final IpdataField<TimeZone> TIME_ZONE = new IpdataField<TimeZone>("time_zone", TimeZone.class);
public static final IpdataField<TimeZone> THREAT = new IpdataField<TimeZone>("threat", TimeZone.class);
public static final IpdataField<ThreatModel> THREAT = new IpdataField<ThreatModel>("threat", ThreatModel.class);
public static final IpdataField<Integer> COUNT = new IpdataField<Integer>("count", Integer.class);
private final String name;
private final Class<T> type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface IpdataInternalSingleFieldClient {
@RequestLine("GET /{ip}/postal")
String getPostal(@Param(value = "ip", encoded = true) String ip) throws IpdataException;

@RequestLine("GET /{ip}/asn")
@RequestLine("GET /{ip}/calling_code")
String getCallingCode(@Param(value = "ip", encoded = true) String ip) throws IpdataException;

@RequestLine("GET /{ip}/flag")
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/io/ipdata/client/AsnTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@
import io.ipdata.client.model.AsnModel;
import io.ipdata.client.service.IpdataService;
import lombok.SneakyThrows;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.HttpClientBuilder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.net.URL;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertNotNull;

@RunWith(Parameterized.class)
public class AsnTest {

private static final TestContext TEST_CONTEXT = new TestContext("https://api.ipdata.co");
private static final TestContext TEST_CONTEXT = new TestContext(MockIpdataServer.API_KEY, MockIpdataServer.getInstance().getUrl());

@Parameterized.Parameter
public TestFixture fixture;
Expand All @@ -45,12 +43,11 @@ public void testASN() {
@SneakyThrows
@Test(expected = IpdataException.class)
public void testAsnError() {
URL url = new URL("https://api.ipdata.co");
IpdataService serviceWithInvalidKey = Ipdata.builder().url(url)
IpdataService serviceWithInvalidKey = Ipdata.builder().url(TEST_CONTEXT.url())
.key("THIS_IS_AN_INVALID_KEY")
.withDefaultCache()
.feignClient(new ApacheHttpClient(HttpClientBuilder.create()
.setSSLHostnameVerifier(new NoopHostnameVerifier()).setConnectionTimeToLive(10, TimeUnit.SECONDS)
.setConnectionTimeToLive(10, TimeUnit.SECONDS)
.build())
).get();
serviceWithInvalidKey.asn(fixture.target());
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/ipdata/client/BulkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@RunWith(Parameterized.class)
public class BulkTest {

private static final TestContext TEST_CONTEXT = new TestContext("https://api.ipdata.co");
private static final TestContext TEST_CONTEXT = new TestContext(MockIpdataServer.API_KEY, MockIpdataServer.getInstance().getUrl());

@Parameterized.Parameter
public IpdataService ipdataService;
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/io/ipdata/client/CurrencyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,17 @@
import io.ipdata.client.model.Currency;
import io.ipdata.client.service.IpdataService;
import lombok.SneakyThrows;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.HttpClientBuilder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.net.URL;
import java.util.concurrent.TimeUnit;

@RunWith(Parameterized.class)
public class CurrencyTest {

private static final TestContext TEST_CONTEXT = new TestContext("https://api.ipdata.co");
private static final TestContext TEST_CONTEXT = new TestContext(MockIpdataServer.API_KEY, MockIpdataServer.getInstance().getUrl());

@Parameterized.Parameter
public TestFixture fixture;
Expand All @@ -41,12 +39,11 @@ public void testCurrency() {
@SneakyThrows
@Test(expected = IpdataException.class)
public void testCurrencyError() {
URL url = new URL("https://api.ipdata.co");
IpdataService serviceWithInvalidKey = Ipdata.builder().url(url)
IpdataService serviceWithInvalidKey = Ipdata.builder().url(TEST_CONTEXT.url())
.key("THIS_IS_AN_INVALID_KEY")
.withDefaultCache()
.feignClient(new ApacheHttpClient(HttpClientBuilder.create()
.setSSLHostnameVerifier(new NoopHostnameVerifier()).setConnectionTimeToLive(10, TimeUnit.SECONDS)
.setConnectionTimeToLive(10, TimeUnit.SECONDS)
.build())
).get();
serviceWithInvalidKey.currency(fixture.target());
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/io/ipdata/client/FullModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@
import io.ipdata.client.model.IpdataModel;
import io.ipdata.client.service.IpdataService;
import lombok.SneakyThrows;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.HttpClientBuilder;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.net.URL;
import java.util.concurrent.TimeUnit;


@RunWith(Parameterized.class)
public class FullModelTest {

private static final TestContext TEST_CONTEXT = new TestContext("https://api.ipdata.co");
private static final TestContext TEST_CONTEXT = new TestContext(MockIpdataServer.API_KEY, MockIpdataServer.getInstance().getUrl());

@Parameterized.Parameter
public TestFixture fixture;
Expand Down Expand Up @@ -54,12 +52,11 @@ public void testSingleFields() {
@SneakyThrows
@Test(expected = IpdataException.class)
public void testError() {
URL url = new URL("https://api.ipdata.co");
IpdataService serviceWithInvalidKey = Ipdata.builder().url(url)
IpdataService serviceWithInvalidKey = Ipdata.builder().url(TEST_CONTEXT.url())
.key("THIS_IS_AN_INVALID_KEY")
.withDefaultCache()
.feignClient(new ApacheHttpClient(HttpClientBuilder.create()
.setSSLHostnameVerifier(new NoopHostnameVerifier()).setConnectionTimeToLive(10, TimeUnit.SECONDS)
.setConnectionTimeToLive(10, TimeUnit.SECONDS)
.build())).get();
serviceWithInvalidKey.ipdata(fixture.target());
}
Expand Down
Loading