Skip to content

Commit af78129

Browse files
authored
Merge pull request #6 from yassine/master
0.2.0-Release
2 parents d9ab508 + 64e829b commit af78129

File tree

16 files changed

+131
-90
lines changed

16 files changed

+131
-90
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ You can have the library from Maven Central.
2626
<dependency>
2727
<groupId>co.ipdata.client</groupId>
2828
<artifactId>ipdata-java-client</artifactId>
29-
<version>0.1.1</version>
29+
<version>0.2.0</version>
3030
</dependency>
3131
```
3232

@@ -144,7 +144,7 @@ ThreatModel threat = ipdataService.threat("1.1.1.1");
144144
The list of available fields is available [here](https://docs.ipdata.co/api-reference/response-fields)
145145

146146
#### Multiple Field Selection
147-
If you're interested by multiple fields for a given IP address, you'll use the ``getFields`` method:
147+
If you're interested in multiple fields for a given IP address, you'll use the ``getFields`` method:
148148
```java
149149
import io.ipdata.client.service.IpdataField;
150150
import io.ipdata.client.service.IpdataService;

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>co.ipdata.client</groupId>
55
<artifactId>ipdata-java-client</artifactId>
6-
<version>0.1.1</version>
6+
<version>0.2.0</version>
77
<description>A java client for ipdata.co</description>
88
<name>Ipdata java client</name>
99
<url>https://github.com/ipdata/java</url>
@@ -23,7 +23,7 @@
2323
<connection>scm:git:git@github.com:ipdata/java.git</connection>
2424
<developerConnection>scm:git:git@github.com:ipdata/java.git</developerConnection>
2525
<url>https://github.com/ipdata/java</url>
26-
<tag>ipdata-java-0.1.1</tag>
26+
<tag>0.2.0</tag>
2727
</scm>
2828
<distributionManagement>
2929
<repository>

src/main/java/io/ipdata/client/CacheConfigBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package io.ipdata.client;
22

33
import io.ipdata.client.service.CacheConfig;
4-
import java.util.concurrent.TimeUnit;
54
import lombok.AccessLevel;
65
import lombok.RequiredArgsConstructor;
76
import lombok.experimental.Accessors;
87

8+
import java.util.concurrent.TimeUnit;
9+
910
@Accessors(fluent = true)
1011
@RequiredArgsConstructor(access = AccessLevel.PACKAGE)
1112
public class CacheConfigBuilder {

src/main/java/io/ipdata/client/Ipdata.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
import io.ipdata.client.service.CacheConfig;
55
import io.ipdata.client.service.IpdataService;
66
import io.ipdata.client.service.IpdataServiceBuilder;
7-
import java.net.URL;
8-
import java.util.concurrent.TimeUnit;
97
import lombok.AccessLevel;
108
import lombok.NoArgsConstructor;
119
import lombok.Setter;
1210
import lombok.experimental.Accessors;
1311
import lombok.experimental.UtilityClass;
1412
import org.slf4j.Logger;
1513

14+
import java.net.URL;
15+
import java.util.concurrent.TimeUnit;
16+
1617
@UtilityClass
1718
public class Ipdata {
1819

src/main/java/io/ipdata/client/model/AsnModel.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,4 @@ public class AsnModel {
1111
private String domain;
1212
private String route;
1313
private String type;
14-
15-
/**
16-
* Deprecated
17-
*
18-
* @deprecated : See: https://github.com/ipdata/java/issues/2
19-
*/
20-
@Deprecated
21-
private String isp;
2214
}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ public class IpdataModel {
4242
//meta
4343
private String count;
4444

45-
/**
46-
* Rely on organisation field instead.
47-
* @deprecated Use organisation instead
48-
*/
49-
@Deprecated
50-
private String organization;
51-
5245
public boolean isEu() {
5346
return eu;
5447
}

src/main/java/io/ipdata/client/service/IpdataInternalClient.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,41 @@
77

88
import java.util.List;
99

10-
@SuppressWarnings("RedundantThrows")
10+
/*
11+
12+
For http protocol, the ':' character is actually tolerated in a path segment. feign library seems to encode all reserved
13+
characters in the same way, i.e. regardless of their usage (path param or query param), according to global restrictions.
14+
For IPV6 addresses, the path parameter includes colons ':' that gets encoded according to global restrictions rules,
15+
while they are still tolerated in a path segment.
16+
17+
In order to by pass this restrictive behavior, encoding is disabled for the ip path as validation is performed
18+
server-side for it.
19+
20+
From RFC 1738:
21+
22+
Section 3.3, Page 9
23+
'Within the <path> and <searchpart> components, "/", ";", "?" are reserved.'
24+
25+
Section 5, Page 20 : globally reserved characters
26+
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "="
27+
28+
Section 5, Page 18 :
29+
; HTTP
30+
httpurl = "http://" hostport [ "/" hpath [ "?" search ]]
31+
hpath = hsegment *[ "/" hsegment ]
32+
hsegment = *[ uchar | ";" | ":" | "@" | "&" | "=" ] <---- ':' is tolerated for a path segment
33+
search = *[ uchar | ";" | ":" | "@" | "&" | "=" ]
34+
35+
*/
1136
interface IpdataInternalClient {
1237
@Cacheable
1338
@RequestLine("GET /{ip}")
14-
IpdataModel ipdata(@Param("ip") String ip) throws IpdataException;
39+
IpdataModel ipdata(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
1540

1641
@RequestLine("POST /bulk")
1742
List<IpdataModel> bulk(List<String> ips) throws IpdataException;
1843

1944
@Cacheable
2045
@RequestLine("GET /{ip}?fields={fields}")
21-
IpdataModel getFields(@Param("ip") String ip, @Param("fields") String fields) throws IpdataException;
46+
IpdataModel getFields(@Param(value = "ip", encoded = true) String ip, @Param("fields") String fields) throws IpdataException;
2247
}

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,64 @@
88
import io.ipdata.client.model.ThreatModel;
99
import io.ipdata.client.model.TimeZone;
1010

11-
@SuppressWarnings("RedundantThrows")
1211
interface IpdataInternalSingleFieldClient {
1312

1413
@RequestLine("GET /{ip}/ip")
15-
String getIp(@Param("ip") String ip) throws IpdataException;
14+
String getIp(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
1615

1716
@RequestLine("GET /{ip}/is_eu")
18-
boolean isEu(@Param("ip") String ip) throws IpdataException;
17+
boolean isEu(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
1918

2019
@RequestLine("GET /{ip}/city")
21-
String getCity(@Param("ip") String ip) throws IpdataException;
20+
String getCity(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
2221

2322
@RequestLine("GET /{ip}/country_name")
24-
String getCountryName(@Param("ip") String ip) throws IpdataException;
23+
String getCountryName(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
2524

2625
@RequestLine("GET /{ip}/country_code")
27-
String getCountryCode(@Param("ip") String ip) throws IpdataException;
26+
String getCountryCode(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
2827

2928
@RequestLine("GET /{ip}/continent_code")
30-
String getContinentCode(@Param("ip") String ip) throws IpdataException;
29+
String getContinentCode(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
3130

3231
@RequestLine("GET /{ip}/longitude")
33-
double getLongitude(@Param("ip") String ip) throws IpdataException;
32+
double getLongitude(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
3433

3534
@RequestLine("GET /{ip}/latitude")
36-
double getLatitude(@Param("ip") String ip) throws IpdataException;
35+
double getLatitude(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
3736

3837
@RequestLine("GET /{ip}/organisation")
39-
String getOrganisation(@Param("ip") String ip) throws IpdataException;
38+
String getOrganisation(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
4039

4140
@RequestLine("GET /{ip}/postal")
42-
String getPostal(@Param("ip") String ip) throws IpdataException;
41+
String getPostal(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
4342

4443
@RequestLine("GET /{ip}/asn")
45-
String getCallingCode(@Param("ip") String ip) throws IpdataException;
44+
String getCallingCode(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
4645

4746
@RequestLine("GET /{ip}/flag")
48-
String getFlag(@Param("ip") String ip) throws IpdataException;
47+
String getFlag(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
4948

5049
@RequestLine("GET /{ip}/emoji_flag")
51-
String getEmojiFlag(@Param("ip") String ip) throws IpdataException;
50+
String getEmojiFlag(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
5251

5352
@RequestLine("GET /{ip}/emoji_unicode")
54-
String getEmojiUnicode(@Param("ip") String ip) throws IpdataException;
53+
String getEmojiUnicode(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
5554

5655
@Cacheable
5756
@RequestLine("GET /{ip}/asn")
58-
AsnModel asn(@Param("ip") String ip) throws IpdataException;
57+
AsnModel asn(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
5958

6059
@Cacheable
6160
@RequestLine("GET /{ip}/time_zone")
62-
TimeZone timeZone(@Param("ip") String ip) throws IpdataException;
61+
TimeZone timeZone(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
6362

6463
@Cacheable
6564
@RequestLine("GET /{ip}/currency")
66-
Currency currency(@Param("ip") String ip) throws IpdataException;
65+
Currency currency(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
6766

6867
@Cacheable
6968
@RequestLine("GET /{ip}/threat")
70-
ThreatModel threat(@Param("ip") String ip) throws IpdataException;
69+
ThreatModel threat(@Param(value = "ip", encoded = true) String ip) throws IpdataException;
7170

7271
}

src/test/java/io/ipdata/client/AsnTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.net.URL;
1515
import java.util.concurrent.TimeUnit;
1616

17-
import static java.util.Arrays.asList;
1817
import static org.junit.Assert.assertNotNull;
1918

2019
@RunWith(Parameterized.class)
@@ -23,19 +22,20 @@ public class AsnTest {
2322
private static final TestContext TEST_CONTEXT = new TestContext("https://api.ipdata.co");
2423

2524
@Parameterized.Parameter
26-
public IpdataService ipdataService;
25+
public TestFixture fixture;
2726

2827
@Test
2928
@SneakyThrows
3029
public void testASN() {
31-
AsnModel asn = ipdataService.asn("8.8.8.8");
30+
IpdataService ipdataService = fixture.service();
31+
AsnModel asn = ipdataService.asn(fixture.target());
3232
assertNotNull(asn.type()); /* See: https://github.com/ipdata/java/issues/2 */
3333
String actual = TEST_CONTEXT.mapper().writeValueAsString(asn);
34-
String expected = TEST_CONTEXT.get("/8.8.8.8/asn", null);
34+
String expected = TEST_CONTEXT.get("/"+fixture.target()+"/asn", null);
3535
TEST_CONTEXT.assertEqualJson(actual, expected);
3636
if (ipdataService == TEST_CONTEXT.cachingIpdataService()) {
3737
//value will be returned from cache now
38-
asn = ipdataService.asn("8.8.8.8");
38+
asn = ipdataService.asn(fixture.target());
3939
assertNotNull(asn.type());
4040
actual = TEST_CONTEXT.mapper().writeValueAsString(asn);
4141
TEST_CONTEXT.assertEqualJson(actual, expected);
@@ -53,12 +53,12 @@ public void testAsnError() {
5353
.setSSLHostnameVerifier(new NoopHostnameVerifier()).setConnectionTimeToLive(10, TimeUnit.SECONDS)
5454
.build())
5555
).get();
56-
serviceWithInvalidKey.asn("8.8.8.8");
56+
serviceWithInvalidKey.asn(fixture.target());
5757
}
5858

5959
@Parameterized.Parameters
60-
public static Iterable<IpdataService> data() {
61-
return asList(TEST_CONTEXT.ipdataService(), TEST_CONTEXT.cachingIpdataService());
60+
public static Iterable<TestFixture> data() {
61+
return TEST_CONTEXT.fixtures();
6262
}
6363

6464
}

src/test/java/io/ipdata/client/BulkTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ public void testBulkResponse() {
3030
TEST_CONTEXT.assertEqualJson(expected, actual, TEST_CONTEXT.configuration().whenIgnoringPaths("[0].time_zone.current_time", "[1].time_zone.current_time", "[0].count", "[1].count"));
3131
}
3232

33+
@SneakyThrows
34+
@Test
35+
public void testBulkResponseIpv6() {
36+
List<IpdataModel> ipdataModels = ipdataService.bulk(Arrays.asList("2001:4860:4860::8888", "2001:4860:4860::8844"));
37+
String actual = TEST_CONTEXT.mapper().writeValueAsString(ipdataModels);
38+
String expected = TEST_CONTEXT.post("/bulk", "[\"2001:4860:4860::8888\",\"2001:4860:4860::8844\"]", null);
39+
expected = TEST_CONTEXT.mapper().writeValueAsString(TEST_CONTEXT.mapper().readValue(expected, IpdataModel[].class));
40+
TEST_CONTEXT.assertEqualJson(expected, actual, TEST_CONTEXT.configuration().whenIgnoringPaths("[0].time_zone.current_time", "[1].time_zone.current_time", "[0].count", "[1].count"));
41+
}
42+
3343
@Parameterized.Parameters
3444
public static Iterable<IpdataService> data() {
3545
return asList(TEST_CONTEXT.ipdataService(), TEST_CONTEXT.cachingIpdataService());

0 commit comments

Comments
 (0)