Clean up http request code in MandrillUtils and MaxMindUtils

This commit is contained in:
Colin McDonald 2016-06-24 22:53:57 -04:00
parent 0a036f5ec5
commit 2ca872706c
2 changed files with 8 additions and 2 deletions

View File

@ -27,7 +27,9 @@ public class MandrillUtils {
response.exceptionHandler((error) -> {
callback.onResult(null, error);
});
}).putHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString()).end(body.encode());
})
.putHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString())
.end(body.encode());
}
}

View File

@ -19,6 +19,8 @@ public class MaxMindUtils {
private static final HttpClient httpsClient = APIv3.getVertxInstance().createHttpClient(new HttpClientOptions().setSsl(true).setTrustAll(true));
public static void getInsights(String ip, SingleResultCallback<MaxMindResult> callback) {
String authHeader = "Basic " + Base64.getEncoder().encodeToString((maxMindUserId + ":" + maxMindLicenseKey).getBytes(Charsets.UTF_8));
httpsClient.get(443, "geoip.maxmind.com", "/geoip/v2.1/insights/" + ip, (response) -> {
response.bodyHandler((body) -> {
JsonObject bodyJson = new JsonObject(body.toString());
@ -28,7 +30,9 @@ public class MaxMindUtils {
response.exceptionHandler((error) -> {
callback.onResult(null, error);
});
}).putHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString((maxMindUserId + ":" + maxMindLicenseKey).getBytes(Charsets.UTF_8))).end();
})
.putHeader("Authorization", authHeader)
.end();
}
public static String getEnglishName(JsonObject source) {