From 6eeb1534135c1dfcd1a807bdaf368f94306bf6ed Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Fri, 24 Jun 2016 02:58:44 -0400 Subject: [PATCH] Add more MaxMind results --- .../net/frozenorb/apiv3/maxmind/MaxMindLocation.java | 10 +++++----- .../net/frozenorb/apiv3/maxmind/MaxMindResult.java | 3 ++- .../net/frozenorb/apiv3/maxmind/MaxMindTraits.java | 2 +- .../net/frozenorb/apiv3/maxmind/MaxMindUserType.java | 3 ++- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindLocation.java b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindLocation.java index f4b726a..5ff57ef 100644 --- a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindLocation.java +++ b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindLocation.java @@ -16,12 +16,12 @@ public final class MaxMindLocation { public MaxMindLocation() {} // For Jackson public MaxMindLocation(JsonObject legacy) { - this.latitude = legacy.getDouble("latitude"); - this.longitude = legacy.getDouble("longitude"); - this.accuracyRadius = legacy.getInteger("accuracy_radius"); - this.timeZone = legacy.getString("time_zone"); + this.latitude = legacy.getDouble("latitude", -1D); + this.longitude = legacy.getDouble("longitude", -1D); + this.accuracyRadius = legacy.getInteger("accuracy_radius", -1); + this.timeZone = legacy.getString("time_zone", ""); this.populationDensity = legacy.getInteger("population_density", -1); - this.metroCode = legacy.getInteger("metro_code", -1); // Metro codes are US only + this.metroCode = legacy.getInteger("metro_code", -1); this.averageIncome = legacy.getInteger("average_income", -1); } diff --git a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindResult.java b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindResult.java index 9e28015..c4906ce 100644 --- a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindResult.java +++ b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindResult.java @@ -1,6 +1,7 @@ package net.frozenorb.apiv3.maxmind; import com.google.common.collect.ImmutableList; +import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import lombok.Getter; @@ -31,7 +32,7 @@ public final class MaxMindResult { List subdivisions = new LinkedList<>(); - for (Object subdivision : legacy.getJsonArray("subdivisions")) { + for (Object subdivision : legacy.getJsonArray("subdivisions", new JsonArray())) { subdivisions.add(new MaxMindSubdivision((JsonObject) subdivision)); } diff --git a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindTraits.java b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindTraits.java index a100f27..0193f4b 100644 --- a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindTraits.java +++ b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindTraits.java @@ -19,7 +19,7 @@ public final class MaxMindTraits { this.domain = legacy.getString("domain", ""); this.asn = legacy.getInteger("autonomous_system_number", -1); this.asnOrganization = legacy.getString("autonomous_system_organization" , ""); - this.userType = MaxMindUserType.valueOf(legacy.getString("user_type", "").toUpperCase()); + this.userType = legacy.containsKey("user_type") ? MaxMindUserType.valueOf(legacy.getString("user_type").toUpperCase()) : MaxMindUserType.UNKNOWN; this.organization = legacy.getString("organization", ""); } diff --git a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindUserType.java b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindUserType.java index d6f48dc..92f9770 100644 --- a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindUserType.java +++ b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindUserType.java @@ -18,7 +18,8 @@ public enum MaxMindUserType { ROUTER(true), SCHOOL(true), SEARCH_ENGINE_SPIDER(false), - TRAVELER(true); + TRAVELER(true), + UNKNOWN(true); @Getter private boolean allowed;