Skip to content

Commit b7fbbf2

Browse files
authored
Merge pull request #141 from maxmind/horgh/ip-optional
Update for IP being optional
2 parents 53940e6 + e2ab6ce commit b7fbbf2

7 files changed

Lines changed: 66 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
-------------------
66
* The HTTP client now allows up to 20 connections to be active at once.
77
Previously the limit was 2. Reported by mjancewicz. GitHub #110.
8+
* The device IP address is no longer a required input.
89

910
1.15.0 (2020-07-09)
1011
-------------------

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ Checked exceptions:
129129
### Insights
130130

131131
```java
132-
133132
Transaction request = new Transaction.Builder(
134133
new Device.Builder(InetAddress.getByName("1.1.1.1"))
135134
.acceptLanguage("en-US")
@@ -231,7 +230,6 @@ Transaction request = new Transaction.Builder(
231230

232231
WebServiceClient client = new WebServiceClient.Builder(6, "ABCD567890").build();
233232

234-
235233
System.out.println(client.insights(request));
236234
```
237235

src/main/java/com/maxmind/minfraud/WebServiceClient.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ public WebServiceClient.Builder disableHttps() {
147147
return this;
148148
}
149149

150-
151150
/**
152151
* @param val The host to use.
153152
* @return Builder object
@@ -166,7 +165,6 @@ public WebServiceClient.Builder port(int val) {
166165
return this;
167166
}
168167

169-
170168
/**
171169
* @param val List of locale codes to use in name property from most
172170
* preferred to least preferred.

src/main/java/com/maxmind/minfraud/request/Device.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,18 @@ public static final class Builder {
3535
String sessionId;
3636

3737
/**
38-
* The constructor for the {@code Device.Builder} class
38+
* Constructor for the {@code Device.Builder} class
39+
*/
40+
public Builder() {
41+
}
42+
43+
/**
44+
* Constructor for the {@code Device.Builder} class
3945
*
4046
* @param ipAddress The IP address associated with the device used
4147
* by the customer in the transaction.
4248
*/
4349
public Builder(InetAddress ipAddress) {
44-
if (ipAddress == null) {
45-
throw new IllegalArgumentException("ipAddress must not be null");
46-
}
47-
4850
this.ipAddress = ipAddress;
4951
}
5052

@@ -68,6 +70,16 @@ public Device.Builder acceptLanguage(String acceptLanguage) {
6870
return this;
6971
}
7072

73+
/**
74+
* @param ipAddress The IP address associated with the device used
75+
* by the customer in the transaction.
76+
* @return The builder object.
77+
*/
78+
public Device.Builder ipAddress(InetAddress ipAddress) {
79+
this.ipAddress = ipAddress;
80+
return this;
81+
}
82+
7183
/**
7284
* @param sessionAge The number of seconds between the creation of the
7385
* user's session and the time of the transaction.
@@ -139,7 +151,6 @@ public String getSessionId() {
139151
*/
140152
@JsonProperty("ip_address")
141153
public InetAddress getIpAddress() {
142-
143154
return ipAddress;
144155
}
145156
}

src/main/java/com/maxmind/minfraud/request/Transaction.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,17 @@ public static class Builder {
5454
final List<ShoppingCartItem> shoppingCart = new ArrayList<>();
5555

5656
/**
57-
* The constructor for {@code Builder}
57+
* Constructor for {@code Builder}
58+
*/
59+
public Builder() {
60+
}
61+
62+
/**
63+
* Constructor for {@code Builder}
5864
*
5965
* @param device The {@code Device} model for the request
6066
*/
6167
public Builder(Device device) {
62-
if (device == null) {
63-
throw new IllegalArgumentException("device must not be null");
64-
}
6568
this.device = device;
6669
}
6770

@@ -101,6 +104,15 @@ public Builder customInputs(CustomInputs val) {
101104
return this;
102105
}
103106

107+
/**
108+
* @param val The Device object.
109+
* @return The builder object.
110+
*/
111+
public Builder device(Device val) {
112+
device = val;
113+
return this;
114+
}
115+
104116
/**
105117
* @param val The Email object.
106118
* @return The builder object.

src/test/java/com/maxmind/minfraud/request/DeviceTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,23 @@ public DeviceTest() throws UnknownHostException {
1717
}
1818

1919
@Test
20-
public void testIpAddress() throws Exception {
20+
public void testConstructorWithoutIP() throws Exception {
21+
Device device = new Builder().build();
22+
assertEquals(null, device.getIpAddress());
23+
}
24+
25+
@Test
26+
public void testIpAddressThroughConstructor() throws Exception {
2127
Device device = new Builder(ip).build();
2228
assertEquals(ip, device.getIpAddress());
2329
}
2430

31+
@Test
32+
public void testIpAddress() throws Exception {
33+
Device device = new Builder().ipAddress(ip).build();
34+
assertEquals(ip, device.getIpAddress());
35+
}
36+
2537
@Test
2638
public void testUserAgent() throws Exception {
2739
String ua = "Mozila 5";
@@ -36,7 +48,6 @@ public void testAcceptLanguage() throws Exception {
3648
assertEquals(al, device.getAcceptLanguage());
3749
}
3850

39-
4051
@Test
4152
public void testSessionAge() throws Exception {
4253
Double hour = 3600d;

src/test/java/com/maxmind/minfraud/request/TransactionTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ private Transaction.Builder builder() throws UnknownHostException {
1212
return new Transaction.Builder(new Device.Builder(InetAddress.getByName("152.216.7.110")).build());
1313
}
1414

15+
@Test
16+
public void testConstructorWithoutDevice() throws Exception {
17+
Transaction request = new Transaction.Builder().build();
18+
assertEquals(null, request.getDevice());
19+
}
20+
1521
@Test
1622
public void testAccount() throws Exception {
1723
Transaction request = this.builder().account(new Account.Builder().userId("1").build()).build();
@@ -43,6 +49,19 @@ public void testDevice() throws Exception {
4349
assertEquals(InetAddress.getByName("152.216.7.110"), request.getDevice().getIpAddress());
4450
}
4551

52+
@Test
53+
public void testDeviceThroughMethod() throws Exception {
54+
InetAddress ip = InetAddress.getByName("152.216.7.110");
55+
56+
Device device = new Device.Builder().ipAddress(ip).build();
57+
58+
Transaction request = new Transaction.Builder()
59+
.device(device)
60+
.build();
61+
62+
assertEquals(ip, request.getDevice().getIpAddress());
63+
}
64+
4665
@Test
4766
public void testEmail() throws Exception {
4867
Transaction request = this.builder().email(new Email.Builder().domain("test.com").build()).build();

0 commit comments

Comments
 (0)