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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ CHANGELOG
* The `DatabaseReader` methods `city()` and `country()` can now be called on
the Enterprise database and the `country()` method can be called on City
databases. Request by Gergely Boromissza. GitHub #132.
* New `getStaticIpScore()` and `getUserCount()` methods were added to
`com.maxmind.geoip2.record.Traits` for use with GeoIP2 Precision Insights.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we say anything about what they are? I think in the other libraries we've been doing that.

They represent a measure of how static or dynamic an IP address is, and an
estimate of the number of users sharing a given address or network,
respectively.

2.12.0 (2018-04-11)
-------------------
Expand Down
57 changes: 55 additions & 2 deletions src/main/java/com/maxmind/geoip2/record/Traits.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public final class Traits extends AbstractRecord {
private final String isp;
private final String organization;
private final String userType;
private final Integer userCount;
private final Double staticIpScore;

public Traits() {
this(null, null, null, null, false, false, null, null, null);
Expand Down Expand Up @@ -74,7 +76,33 @@ public Traits(
) {
this(autonomousSystemNumber, autonomousSystemOrganization, connectionType, domain,
ipAddress, false, isAnonymousProxy, false, false, isLegitimateProxy,
false, isSatelliteProvider, false, isp, organization, userType);
false, isSatelliteProvider, false, isp, organization, userType, null, null);
}

// This is for back-compat. If we ever do a major release, it should be
// removed.
public Traits(
Integer autonomousSystemNumber,
String autonomousSystemOrganization,
ConnectionType connectionType,
String domain,
String ipAddress,
boolean isAnonymous,
boolean isAnonymousProxy,
boolean isAnonymousVpn,
boolean isHostingProvider,
boolean isLegitimateProxy,
boolean isPublicProxy,
boolean isSatelliteProvider,
boolean isTorExitNode,
String isp,
String organization,
String userType
) {
this(autonomousSystemNumber, autonomousSystemOrganization, connectionType, domain,
ipAddress, isAnonymous, isAnonymousProxy, isAnonymousVpn, isHostingProvider,
isLegitimateProxy, isPublicProxy, isSatelliteProvider, isTorExitNode, isp,
organization, userType, null, null);
}

public Traits(
Expand All @@ -93,7 +121,9 @@ public Traits(
@JsonProperty("is_tor_exit_node") boolean isTorExitNode,
@JsonProperty("isp") String isp,
@JsonProperty("organization") String organization,
@JsonProperty("user_type") String userType
@JsonProperty("user_type") String userType,
@JsonProperty("user_count") Integer userCount,
@JsonProperty("static_ip_score") Double staticIpScore
) {
this.autonomousSystemNumber = autonomousSystemNumber;
this.autonomousSystemOrganization = autonomousSystemOrganization;
Expand All @@ -111,6 +141,8 @@ public Traits(
this.isp = isp;
this.organization = organization;
this.userType = userType;
this.userCount = userCount;
this.staticIpScore = staticIpScore;
}

/**
Expand Down Expand Up @@ -146,6 +178,27 @@ public ConnectionType getConnectionType() {
return this.connectionType;
}

/**
* @return The static IP score of the IP address. This is an indicator of
* how static or dynamic an IP address is. This attribute is only
* available from GeoIP2 Precision Insights.
*/
@JsonProperty("static_ip_score")
public Double getStaticIpScore() {
return this.staticIpScore;
}

/**
* @return The estimated number of users sharing the IP address/network
* during the past 24 hours. For IPv4, the count is for the individual
* IP address. For IPv6, the count is for the /64 network. This attribute
* is only available from GeoIP2 Precision Insights.
*/
@JsonProperty("user_count")
public Integer getUserCount() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a comment documenting this?

return this.userCount;
}

/**
* @return The second level domain associated with the IP address. This will
* be something like "example.com" or "example.co.uk", not
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/com/maxmind/geoip2/WebServiceClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ public void test200WithDefaultValues() throws Exception {
assertNull(traits.getIsp());
assertNull(traits.getOrganization());
assertNull(traits.getUserType());
assertNull(traits.getStaticIpScore());
assertNull(traits.getUserCount());
assertFalse(traits.isAnonymousProxy());
assertFalse(traits.isSatelliteProvider());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public void testTraits() {
traits.getOrganization());
assertEquals("traits.getUserType() does not return userType",
"college", traits.getUserType());
assertEquals("traits.getStaticIpScore() does not return 1.3",
Double.valueOf(1.3), traits.getStaticIpScore());
assertEquals("traits.getUserCount() does not return 2",
Integer.valueOf(2), traits.getUserCount());
}

@Test
Expand Down
2 changes: 2 additions & 0 deletions src/test/resources/test-data/insights0.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
"is_satellite_provider": true,
"is_tor_exit_node": true,
"organization": "Blorg",
"static_ip_score": 1.3,
"user_count": 2,
"user_type": "college"
}
}
2 changes: 2 additions & 0 deletions src/test/resources/test-data/insights1.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
"is_satellite_provider": true,
"is_tor_exit_node": true,
"organization": "Blorg",
"static_ip_score": 1.3,
"user_count": 2,
"user_type": "college"
}
}