Add MaxMind files
This commit is contained in:
parent
453a3264be
commit
63b1e7b2c3
|
@ -9,5 +9,7 @@ redis.port=6379
|
||||||
http.port=80
|
http.port=80
|
||||||
mandrill.apiKey=0OYtwymqJP6oqvszeJu0vQ
|
mandrill.apiKey=0OYtwymqJP6oqvszeJu0vQ
|
||||||
bugsnag.apiKey=0e47fba8b825416b7cbc839066184509
|
bugsnag.apiKey=0e47fba8b825416b7cbc839066184509
|
||||||
|
maxMind.userId=66817
|
||||||
|
maxMind.maxMindLicenseKey=8Aw9NsOUeOp7
|
||||||
auth.websiteApiKey=RVbp4hY6sCFVaf
|
auth.websiteApiKey=RVbp4hY6sCFVaf
|
||||||
auth.bungeeApiKey=6d9cf76dc9f0d23
|
auth.bungeeApiKey=6d9cf76dc9f0d23
|
|
@ -0,0 +1,4 @@
|
||||||
|
package net.frozenorb.apiv3.maxmind;
|
||||||
|
|
||||||
|
public class MaxMindCity {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package net.frozenorb.apiv3.maxmind;
|
||||||
|
|
||||||
|
public class MaxMindContinent {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package net.frozenorb.apiv3.maxmind;
|
||||||
|
|
||||||
|
public class MaxMindCountry {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package net.frozenorb.apiv3.maxmind;
|
||||||
|
|
||||||
|
public class MaxMindLocation {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package net.frozenorb.apiv3.maxmind;
|
||||||
|
|
||||||
|
public class MaxMindPostal {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package net.frozenorb.apiv3.maxmind;
|
||||||
|
|
||||||
|
public class MaxMindRegisteredCountry {
|
||||||
|
}
|
|
@ -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() {}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package net.frozenorb.apiv3.maxmind;
|
||||||
|
|
||||||
|
public class MaxMindSubdivision {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package net.frozenorb.apiv3.maxmind;
|
||||||
|
|
||||||
|
public class MaxMindTraits {
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue