Skip to content

Commit 50dae0e

Browse files
committed
Update to support isInEuropeanUnion()
1 parent 93e94ee commit 50dae0e

5 files changed

Lines changed: 69 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ CHANGELOG
44
1.8.0
55
------------------
66

7+
* Updated `geoip2` dependency. This version adds the `isInEuropeanUnion()`
8+
method to `com.maxmind.geoip2.record.Country` and
9+
`com.maxmind.minfraud.response.GeoIp2Country`. This returns `true` if the
10+
country is a member state of the European Union.
711
* The web service client now correctly handles a proxy of `Proxy.NO_PROXY`.
812
PR by Ernest Sadykov. GitHub #32.
913
* The following payment processors were added to the `Payment.Processor` enum:

src/main/java/com/maxmind/minfraud/response/GeoIp2Country.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,35 @@
1414
public final class GeoIp2Country extends Country {
1515
private final boolean isHighRisk;
1616

17+
// This method is for backwards compatibility. We should remove it when we
18+
// do a major release.
19+
public GeoIp2Country(
20+
List<String> locales,
21+
Integer confidence,
22+
Integer geoNameId,
23+
boolean isHighRisk,
24+
String isoCode,
25+
Map<String, String> names
26+
) {
27+
this(locales, confidence, geoNameId, isHighRisk, false, isoCode, names);
28+
}
29+
1730
public GeoIp2Country(
1831
@JacksonInject("locales") List<String> locales,
1932
@JsonProperty("confidence") Integer confidence,
2033
@JsonProperty("geoname_id") Integer geoNameId,
2134
@JsonProperty("is_high_risk") boolean isHighRisk,
35+
@JsonProperty("is_in_european_union") boolean isInEuropeanUnion,
2236
@JsonProperty("iso_code") String isoCode,
2337
@JsonProperty("names") Map<String, String> names
2438
) {
25-
super(locales, confidence, geoNameId, isoCode, names);
39+
super(locales, confidence, geoNameId, isInEuropeanUnion, isoCode,
40+
names);
2641
this.isHighRisk = isHighRisk;
2742
}
2843

2944
public GeoIp2Country() {
30-
this(null, null, null, false, null, null);
45+
this(null, null, null, false, false, null, null);
3146
}
3247

3348
/**

src/test/java/com/maxmind/minfraud/WebServiceClientTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import static com.jcabi.matchers.RegexMatchers.matchesPattern;
2323
import static com.maxmind.minfraud.request.RequestTestHelper.*;
2424
import static org.hamcrest.core.StringStartsWith.startsWith;
25+
import static org.junit.Assert.assertFalse;
26+
import static org.junit.Assert.assertTrue;
2527

2628
@RunWith(JUnitParamsRunner.class)
2729
public class WebServiceClientTest {
@@ -68,6 +70,15 @@ public void testFullInsightsTransaction() throws Exception {
6870
// We cannot change this as it would be a breaking change to the GeoIP2 API.
6971
JSONAssert.assertEquals(responseContent, response.toJson(), false);
7072
verifyRequestFor("insights", "full-request");
73+
assertTrue(
74+
"response.getIpAddress().getCountry().isInEuropeanUnion() does not return true",
75+
response.getIpAddress().getCountry().isInEuropeanUnion());
76+
assertFalse(
77+
"response.getIpAddress().getRegisteredCountry().isInEuropeanUnion() does not return false",
78+
response.getIpAddress().getRegisteredCountry().isInEuropeanUnion());
79+
assertTrue(
80+
"response.getIpAddress().getRepresentedCountry().isInEuropeanUnion() does not return true",
81+
response.getIpAddress().getRepresentedCountry().isInEuropeanUnion());
7182
}
7283
}
7384

@@ -83,6 +94,15 @@ public void testFullFactorsTransaction() throws Exception {
8394
// We cannot change this as it would be a breaking change to the GeoIP2 API.
8495
JSONAssert.assertEquals(responseContent, response.toJson(), false);
8596
verifyRequestFor("factors", "full-request");
97+
assertTrue(
98+
"response.getIpAddress().getCountry().isInEuropeanUnion() does not return true",
99+
response.getIpAddress().getCountry().isInEuropeanUnion());
100+
assertTrue(
101+
"response.getIpAddress().getRegisteredCountry().isInEuropeanUnion() does not return true",
102+
response.getIpAddress().getRegisteredCountry().isInEuropeanUnion());
103+
assertFalse(
104+
"response.getIpAddress().getRepresentedCountry().isInEuropeanUnion() does not return false",
105+
response.getIpAddress().getRepresentedCountry().isInEuropeanUnion());
86106
}
87107
}
88108

src/test/resources/test-data/factors-response.json

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"confidence": 99,
3737
"geoname_id": 2635167,
3838
"is_high_risk": false,
39+
"is_in_european_union": true,
3940
"iso_code": "GB",
4041
"names": {
4142
"de": "Vereinigtes K\u00f6nigreich",
@@ -56,17 +57,18 @@
5657
"time_zone": "Europe\/London"
5758
},
5859
"registered_country": {
59-
"geoname_id": 6252001,
60-
"iso_code": "US",
60+
"geoname_id": 2635167,
61+
"is_in_european_union": true,
62+
"iso_code": "GB",
6163
"names": {
62-
"de": "USA",
63-
"en": "United States",
64-
"es": "Estados Unidos",
65-
"fr": "\u00c9tats-Unis",
66-
"ja": "\u30a2\u30e1\u30ea\u30ab\u5408\u8846\u56fd",
67-
"pt-BR": "Estados Unidos",
68-
"ru": "\u0421\u0428\u0410",
69-
"zh-CN": "\u7f8e\u56fd"
64+
"de": "Vereinigtes K\u00f6nigreich",
65+
"en": "United Kingdom",
66+
"es": "Reino Unido",
67+
"fr": "Royaume-Uni",
68+
"ja": "\u30a4\u30ae\u30ea\u30b9",
69+
"pt-BR": "Reino Unido",
70+
"ru": "\u0412\u0435\u043b\u0438\u043a\u043e\u0431\u0440\u0438\u0442\u0430\u043d\u0438\u044f",
71+
"zh-CN": "\u82f1\u56fd"
7072
}
7173
},
7274
"subdivisions": [

src/test/resources/test-data/insights-response.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"confidence": 99,
3737
"geoname_id": 2635167,
3838
"is_high_risk": false,
39+
"is_in_european_union": true,
3940
"iso_code": "GB",
4041
"names": {
4142
"de": "Vereinigtes K\u00f6nigreich",
@@ -69,6 +70,21 @@
6970
"zh-CN": "\u7f8e\u56fd"
7071
}
7172
},
73+
"represented_country": {
74+
"geoname_id": 2635167,
75+
"is_in_european_union": true,
76+
"iso_code": "GB",
77+
"names": {
78+
"de": "Vereinigtes K\u00f6nigreich",
79+
"en": "United Kingdom",
80+
"es": "Reino Unido",
81+
"fr": "Royaume-Uni",
82+
"ja": "\u30a4\u30ae\u30ea\u30b9",
83+
"pt-BR": "Reino Unido",
84+
"ru": "\u0412\u0435\u043b\u0438\u043a\u043e\u0431\u0440\u0438\u0442\u0430\u043d\u0438\u044f",
85+
"zh-CN": "\u82f1\u56fd"
86+
}
87+
},
7288
"subdivisions": [
7389
{
7490
"confidence": 42,

0 commit comments

Comments
 (0)