diff --git a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindCity.java b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindCity.java index 828112d..06986e6 100644 --- a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindCity.java +++ b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindCity.java @@ -13,8 +13,8 @@ public final class MaxMindCity { public MaxMindCity() {} // For Jackson public MaxMindCity(JsonObject legacy) { - this.confidence = legacy.getInteger("confidence"); - this.geonameId = legacy.getInteger("geoname_id"); + this.confidence = legacy.getInteger("confidence", -1); + this.geonameId = legacy.getInteger("geoname_id", -1); this.name = MaxMindUtils.getEnglishName(legacy); } diff --git a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindContinent.java b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindContinent.java index 40a4174..0243d55 100644 --- a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindContinent.java +++ b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindContinent.java @@ -13,8 +13,8 @@ public final class MaxMindContinent { public MaxMindContinent() {} // For Jackson public MaxMindContinent(JsonObject legacy) { - this.code = legacy.getString("code"); - this.geonameId = legacy.getInteger("geoname_id"); + this.code = legacy.getString("code", ""); + this.geonameId = legacy.getInteger("geoname_id", -1); this.name = MaxMindUtils.getEnglishName(legacy); } diff --git a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindCountry.java b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindCountry.java index 04b6891..29ade9f 100644 --- a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindCountry.java +++ b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindCountry.java @@ -14,9 +14,9 @@ public final class MaxMindCountry { public MaxMindCountry() {} // For Jackson public MaxMindCountry(JsonObject legacy) { - this.isoCode = legacy.getString("iso_code"); - this.confidence = legacy.getInteger("confidence"); - this.geonameId = legacy.getInteger("geoname_id"); + this.isoCode = legacy.getString("iso_code", ""); + this.confidence = legacy.getInteger("confidence", -1); + this.geonameId = legacy.getInteger("geoname_id", -1); this.name = MaxMindUtils.getEnglishName(legacy); } diff --git a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindPostal.java b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindPostal.java index 57e49e8..a3bef02 100644 --- a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindPostal.java +++ b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindPostal.java @@ -12,7 +12,7 @@ public final class MaxMindPostal { public MaxMindPostal(JsonObject legacy) { this.code = legacy.getString("code", ""); - this.confidence = legacy.getInteger("confidence"); + this.confidence = legacy.getInteger("confidence", -1); } } \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindRegisteredCountry.java b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindRegisteredCountry.java index fbb7c21..6770677 100644 --- a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindRegisteredCountry.java +++ b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindRegisteredCountry.java @@ -13,8 +13,8 @@ public final class MaxMindRegisteredCountry { public MaxMindRegisteredCountry() {} // For Jackson public MaxMindRegisteredCountry(JsonObject legacy) { - this.isoCode = legacy.getString("iso_code"); - this.geonameId = legacy.getInteger("geoname_id"); + this.isoCode = legacy.getString("iso_code", ""); + this.geonameId = legacy.getInteger("geoname_id", -1); this.name = MaxMindUtils.getEnglishName(legacy); } diff --git a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindResult.java b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindResult.java index 5437db1..9e28015 100644 --- a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindResult.java +++ b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindResult.java @@ -21,13 +21,13 @@ public final class MaxMindResult { public MaxMindResult() {} // For Jackson public MaxMindResult(JsonObject legacy) { - this.continent = new MaxMindContinent(legacy.getJsonObject("continent")); - this.city = new MaxMindCity(legacy.getJsonObject("city")); - this.postal = new MaxMindPostal(legacy.getJsonObject("postal")); + this.continent = new MaxMindContinent(legacy.getJsonObject("continent", new JsonObject())); + this.city = new MaxMindCity(legacy.getJsonObject("city", new JsonObject())); + this.postal = new MaxMindPostal(legacy.getJsonObject("postal", new JsonObject())); this.traits = new MaxMindTraits(legacy.getJsonObject("traits")); - this.location = new MaxMindLocation(legacy.getJsonObject("location")); - this.country = new MaxMindCountry(legacy.getJsonObject("country")); - this.registeredCountry = new MaxMindRegisteredCountry(legacy.getJsonObject("registered_country")); + this.location = new MaxMindLocation(legacy.getJsonObject("location", new JsonObject())); + this.country = new MaxMindCountry(legacy.getJsonObject("country", new JsonObject())); + this.registeredCountry = new MaxMindRegisteredCountry(legacy.getJsonObject("registered_country", new JsonObject())); List subdivisions = new LinkedList<>(); diff --git a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindSubdivision.java b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindSubdivision.java index ff78bbf..05948c9 100644 --- a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindSubdivision.java +++ b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindSubdivision.java @@ -14,9 +14,9 @@ public final class MaxMindSubdivision { public MaxMindSubdivision() {} // For Jackson public MaxMindSubdivision(JsonObject legacy) { - this.isoCode = legacy.getString("iso_code"); + this.isoCode = legacy.getString("iso_code", ""); this.confidence = legacy.getInteger("confidence", -1); - this.geonameId = legacy.getInteger("geoname_id"); + this.geonameId = legacy.getInteger("geoname_id", -1); this.name = MaxMindUtils.getEnglishName(legacy); } diff --git a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindTraits.java b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindTraits.java index 5e4d718..a100f27 100644 --- a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindTraits.java +++ b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindTraits.java @@ -15,12 +15,12 @@ public final class MaxMindTraits { public MaxMindTraits() {} // For Jackson public MaxMindTraits(JsonObject legacy) { - this.isp = legacy.getString("isp"); - this.domain = legacy.getString("domain"); - this.asn = legacy.getInteger("autonomous_system_number"); - this.asnOrganization = legacy.getString("autonomous_system_organization"); - this.userType = MaxMindUserType.valueOf(legacy.getString("user_type").toUpperCase()); - this.organization = legacy.getString("organization"); + this.isp = legacy.getString("isp", ""); + 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.organization = legacy.getString("organization", ""); } } \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindUserType.java b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindUserType.java index b4f2fbd..d6f48dc 100644 --- a/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindUserType.java +++ b/src/main/java/net/frozenorb/apiv3/maxmind/MaxMindUserType.java @@ -20,7 +20,6 @@ public enum MaxMindUserType { SEARCH_ENGINE_SPIDER(false), TRAVELER(true); - // TODO: ACTUALLY CARE ABOUT THIS @Getter private boolean allowed; MaxMindUserType(boolean allowed) { diff --git a/src/main/java/net/frozenorb/apiv3/util/MaxMindUtils.java b/src/main/java/net/frozenorb/apiv3/util/MaxMindUtils.java index 18fc24e..40787cd 100644 --- a/src/main/java/net/frozenorb/apiv3/util/MaxMindUtils.java +++ b/src/main/java/net/frozenorb/apiv3/util/MaxMindUtils.java @@ -19,7 +19,6 @@ public class MaxMindUtils { private static final HttpClient httpsClient = APIv3.getVertxInstance().createHttpClient(new HttpClientOptions().setSsl(true).setTrustAll(true)); public static void getInsights(String ip, SingleResultCallback callback) { - // We have to specifically use getHttpSClient(), vertx's http client is dumb. httpsClient.get(443, "geoip.maxmind.com", "/geoip/v2.1/insights/" + ip, (response) -> { response.bodyHandler((body) -> { JsonObject bodyJson = new JsonObject(body.toString()); @@ -33,7 +32,7 @@ public class MaxMindUtils { } public static String getEnglishName(JsonObject source) { - return source.getJsonObject("names").getString("en", "INVALID"); + return source.getJsonObject("names", new JsonObject()).getString("en", "INVALID"); } } \ No newline at end of file