Skip to content

Commit 8359150

Browse files
authored
Merge pull request #25 from maxmind/oalders/device-and-session-inputs
Add /device/session_age, /device/session_id and /email/first_seen
2 parents 55c1065 + 734f0ac commit 8359150

10 files changed

Lines changed: 118 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
* Added support for new Device inputs. These are:
5+
* `/device/session_age`
6+
* `/device/session_id`
7+
* Added support for new Email outputs. These are:
8+
* `/email/first_seen`
9+
410
1.4.0 (2017-02-22)
511
------------------
612

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ Checked exceptions:
119119
Transaction request = new Transaction.Builder(
120120
new Device.Builder(InetAddress.getByName("1.1.1.1"))
121121
.acceptLanguage("en-US")
122+
.sessionAge(3600.6)
123+
.sessionId("foobar")
122124
.userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36")
123125
.build()
124126
).account(

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ public final class Device extends AbstractModel {
1212
private final InetAddress ipAddress;
1313
private final String userAgent;
1414
private final String acceptLanguage;
15+
private final Double sessionAge;
16+
private final String sessionId;
1517

1618
private Device(Device.Builder builder) {
1719
ipAddress = builder.ipAddress;
1820
userAgent = builder.userAgent;
1921
acceptLanguage = builder.acceptLanguage;
22+
sessionAge = builder.sessionAge;
23+
sessionId = builder.sessionId;
2024
}
2125

2226
/**
@@ -27,6 +31,8 @@ public static final class Builder {
2731
InetAddress ipAddress;
2832
String userAgent;
2933
String acceptLanguage;
34+
Double sessionAge;
35+
String sessionId;
3036

3137
/**
3238
* The constructor for the {@code Device.Builder} class
@@ -62,6 +68,28 @@ public Device.Builder acceptLanguage(String acceptLanguage) {
6268
return this;
6369
}
6470

71+
/**
72+
* @param sessionAge The number of seconds between the creation of the
73+
* user's session and the time of the transaction.
74+
* Note that session_age is not the duration of the
75+
* current visit, but the time since the start of the
76+
* first visit.
77+
* @return The builder object.
78+
*/
79+
public Device.Builder sessionAge(Double sessionAge) { this.sessionAge =
80+
sessionAge; return this; }
81+
82+
/**
83+
* @param sessionId A string up to 255 characters in length. This is
84+
* an ID which uniquely identifies a visitor's
85+
* session on the site.
86+
* @return The builder object.
87+
*/
88+
public Device.Builder sessionId(String sessionId) {
89+
this.sessionId = sessionId;
90+
return this;
91+
}
92+
6593
/**
6694
* @return An instance of {@code Device} created from the
6795
* fields set on this builder.
@@ -87,6 +115,22 @@ public String getAcceptLanguage() {
87115
return acceptLanguage;
88116
}
89117

118+
/**
119+
* @return The session age.
120+
*/
121+
@JsonProperty("session_age")
122+
public Double getSessionAge() {
123+
return sessionAge;
124+
}
125+
126+
/**
127+
* @return The session id.
128+
*/
129+
@JsonProperty("session_id")
130+
public String getSessionId() {
131+
return sessionId;
132+
}
133+
90134
/**
91135
* @return The IP address used in the transaction.
92136
*/

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,27 @@
99
public final class Email extends AbstractModel {
1010
private final Boolean isFree;
1111
private final Boolean isHighRisk;
12+
private final String firstSeen;
1213

1314
public Email(
1415
@JsonProperty("is_free") Boolean isFree,
15-
@JsonProperty("is_high_risk") Boolean isHighRisk
16+
@JsonProperty("is_high_risk") Boolean isHighRisk,
17+
@JsonProperty("first_seen") String firstSeen
1618
) {
1719
this.isFree = isFree;
1820
this.isHighRisk = isHighRisk;
21+
this.firstSeen = firstSeen;
22+
}
23+
24+
public Email(
25+
Boolean isFree,
26+
Boolean isHighRisk
27+
) {
28+
this(isFree,isHighRisk,null);
1929
}
2030

2131
public Email() {
22-
this(null, null);
32+
this(null, null, null);
2333
}
2434

2535
/**
@@ -37,4 +47,14 @@ public Boolean isFree() {
3747
public Boolean isHighRisk() {
3848
return isHighRisk;
3949
}
50+
51+
/**
52+
* @return A date string (e.g. 2017-04-24) to identify the date an email
53+
* address was first seen by MaxMind. This is expressed using the
54+
* ISO 8601 date format.
55+
*/
56+
@JsonProperty("first_seen")
57+
public String getFirstSeen() {
58+
return firstSeen;
59+
}
4060
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,19 @@ public void testAcceptLanguage() throws Exception {
3535
Device device = new Builder(ip).acceptLanguage(al).build();
3636
assertEquals(al, device.getAcceptLanguage());
3737
}
38-
}
38+
39+
40+
@Test
41+
public void testSessionAge() throws Exception {
42+
Double hour = 3600d;
43+
Device device = new Builder(ip).sessionAge(hour).build();
44+
assertEquals(hour, device.getSessionAge());
45+
}
46+
47+
@Test
48+
public void testSessionId() throws Exception {
49+
String id = "foobar";
50+
Device device = new Builder(ip).sessionId(id).build();
51+
assertEquals(id, device.getSessionId());
52+
}
53+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public static Transaction fullTransaction() throws Exception {
2121
return new Transaction.Builder(
2222
new Device.Builder(InetAddress.getByName("81.2.69.160"))
2323
.userAgent("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36")
24+
.sessionAge(3600.5)
25+
.sessionId("foobar")
2426
.acceptLanguage("en-US,en;q=0.8")
2527
.build()
2628
)

src/test/java/com/maxmind/minfraud/response/EmailTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import com.fasterxml.jackson.jr.ob.JSON;
44
import org.junit.Test;
55

6+
import static org.junit.Assert.assertEquals;
67
import static org.junit.Assert.assertFalse;
78
import static org.junit.Assert.assertTrue;
9+
import static org.junit.Assert.assertNull;
810

911
public class EmailTest extends AbstractOutputTest {
1012

@@ -17,11 +19,31 @@ public void testEmail() throws Exception {
1719
.startObject()
1820
.put("is_free", false)
1921
.put("is_high_risk", true)
22+
.put("first_seen", "2017-01-02")
2023
.end()
2124
.finish()
2225
);
2326

2427
assertFalse(email.isFree());
2528
assertTrue(email.isHighRisk());
29+
assertEquals(email.getFirstSeen(),"2017-01-02");
30+
}
31+
32+
@Test
33+
public void testEmailWithoutFirstSeen() throws Exception {
34+
Email email = this.deserialize(
35+
Email.class,
36+
JSON.std
37+
.composeString()
38+
.startObject()
39+
.put("is_free", false)
40+
.put("is_high_risk", true)
41+
.end()
42+
.finish()
43+
);
44+
45+
assertFalse(email.isFree());
46+
assertTrue(email.isHighRisk());
47+
assertNull(email.getFirstSeen());
2648
}
2749
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"reason": "custom_rule"
121121
},
122122
"email": {
123+
"first_seen": "2017-01-02",
123124
"is_free": true,
124125
"is_high_risk": true
125126
},

src/test/resources/test-data/full-request.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@
8282
"device": {
8383
"ip_address": "81.2.69.160",
8484
"user_agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.89 Safari/537.36",
85+
"session_age": 3600.5,
86+
"session_id": "foobar",
8587
"accept_language": "en-US,en;q=0.8"
8688
}
8789
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
"reason": "custom_rule"
121121
},
122122
"email": {
123+
"first_seen": "2017-01-02",
123124
"is_free": true,
124125
"is_high_risk": true
125126
},

0 commit comments

Comments
 (0)