Search in sources :

Example 1 with JSONArray

use of org.to2mbn.authlibinjector.internal.org.json.JSONArray in project authlib-injector by to2mbn.

the class DeprecatedApiHttpd method queryCharacterUUID.

private Optional<String> queryCharacterUUID(String username) throws UncheckedIOException, JSONException {
    String responseText;
    try {
        responseText = asString(postURL(configuration.getApiRoot() + "api/profiles/minecraft", CONTENT_TYPE_JSON, new JSONArray(new String[] { username }).toString().getBytes(UTF_8)));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    debug("[httpd] query uuid of username {0}, response: {1}", username, responseText);
    JSONArray response = new JSONArray(responseText);
    if (response.length() == 0) {
        return empty();
    } else if (response.length() == 1) {
        return of(response.getJSONObject(0).getString("id"));
    } else {
        throw new JSONException("Unexpected response length");
    }
}
Also used : JSONArray(org.to2mbn.authlibinjector.internal.org.json.JSONArray) JSONException(org.to2mbn.authlibinjector.internal.org.json.JSONException) UncheckedIOException(java.io.UncheckedIOException) IOUtils.asString(org.to2mbn.authlibinjector.util.IOUtils.asString) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Aggregations

IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 JSONArray (org.to2mbn.authlibinjector.internal.org.json.JSONArray)1 JSONException (org.to2mbn.authlibinjector.internal.org.json.JSONException)1 IOUtils.asString (org.to2mbn.authlibinjector.util.IOUtils.asString)1