Add MaxMind files

This commit is contained in:
Colin McDonald 2016-06-17 01:07:20 -04:00
parent 453a3264be
commit 63b1e7b2c3
11 changed files with 85 additions and 0 deletions

View File

@ -9,5 +9,7 @@ redis.port=6379
http.port=80
mandrill.apiKey=0OYtwymqJP6oqvszeJu0vQ
bugsnag.apiKey=0e47fba8b825416b7cbc839066184509
maxMind.userId=66817
maxMind.maxMindLicenseKey=8Aw9NsOUeOp7
auth.websiteApiKey=RVbp4hY6sCFVaf
auth.bungeeApiKey=6d9cf76dc9f0d23

View File

@ -0,0 +1,4 @@
package net.frozenorb.apiv3.maxmind;
public class MaxMindCity {
}

View File

@ -0,0 +1,4 @@
package net.frozenorb.apiv3.maxmind;
public class MaxMindContinent {
}

View File

@ -0,0 +1,4 @@
package net.frozenorb.apiv3.maxmind;
public class MaxMindCountry {
}

View File

@ -0,0 +1,4 @@
package net.frozenorb.apiv3.maxmind;
public class MaxMindLocation {
}

View File

@ -0,0 +1,4 @@
package net.frozenorb.apiv3.maxmind;
public class MaxMindPostal {
}

View File

@ -0,0 +1,4 @@
package net.frozenorb.apiv3.maxmind;
public class MaxMindRegisteredCountry {
}

View File

@ -0,0 +1,20 @@
package net.frozenorb.apiv3.maxmind;
import java.time.Instant;
public final class MaxMindResult {
private String ip;
private Instant lastUpdatedAt;
private MaxMindContinent continent;
private MaxMindCity city;
private MaxMindPostal postal;
private MaxMindTraits traits;
private MaxMindLocation location;
private MaxMindSubdivision[] subdivisions;
private MaxMindCountry country;
private MaxMindRegisteredCountry registeredCountry;
public MaxMindResult() {}
}

View File

@ -0,0 +1,4 @@
package net.frozenorb.apiv3.maxmind;
public class MaxMindSubdivision {
}

View File

@ -0,0 +1,4 @@
package net.frozenorb.apiv3.maxmind;
public class MaxMindTraits {
}

View File

@ -0,0 +1,31 @@
package net.frozenorb.apiv3.util;
import com.google.common.base.Charsets;
import com.mongodb.async.SingleResultCallback;
import lombok.experimental.UtilityClass;
import net.frozenorb.apiv3.APIv3;
import org.bson.Document;
import java.util.Base64;
@UtilityClass
public class MaxMindUtils {
private static final String maxMindUserId = APIv3.getConfig().getProperty("maxMind.userId");
private static final String maxMindLicenseKey = APIv3.getConfig().getProperty("maxMind.maxMindLicenseKey");
public static void getInsights(String ip, SingleResultCallback<Document> callback) {
// We have to specifically use getHttpSClient(), vertx's http client is dumb.
APIv3.getHttpsClient().get(443, "geoip.maxmind.com", "/geoip/v2.1/insights/" + ip, (response) -> {
response.bodyHandler((body) -> {
Document resJson = Document.parse(body.toString());
callback.onResult(resJson, null);
});
response.exceptionHandler((error) -> {
callback.onResult(null, error);
});
}).putHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString((maxMindUserId + ":" + maxMindLicenseKey).getBytes(Charsets.UTF_8))).end();
}
}