use of org.jetbrains.annotations.Blocking in project BotCommands by freya022.
the class ApplicationCommandsUpdater method updateCommands.
@Blocking
public void updateCommands() {
final CommandListUpdateAction updateAction = guild != null ? guild.updateCommands() : context.getJDA().updateCommands();
final List<Command> commands = updateAction.addCommands(allCommandData).complete();
updatedCommands = true;
if (guild != null) {
thenAcceptGuild(commands, guild);
} else {
thenAcceptGlobal(commands);
}
}
use of org.jetbrains.annotations.Blocking in project AzAuth by Azuriom.
the class AzAuthenticator method authenticate.
/**
* Try to authenticate the player on the website and get his profile with a given response type.
*
* @param email the player email
* @param password the player password
* @param responseType the class of the response
* @param <T> the type of the response
* @return the player profile
* @throws AuthenticationException if credentials are not valid
* @throws IOException if an IO exception occurs
*/
@Blocking
@NotNull
public <T> T authenticate(@NotNull String email, @NotNull String password, @NotNull Class<T> responseType) throws AuthenticationException, IOException {
JsonObject body = new JsonObject();
body.addProperty("email", email);
body.addProperty("password", password);
return this.post("authenticate", body, responseType);
}
use of org.jetbrains.annotations.Blocking in project AzAuth by Azuriom.
the class AzAuthenticator method verify.
/**
* Verify an access token and get the associated profile with a given response type.
*
* @param accessToken the player access token
* @param responseType the class of the response
* @param <T> the type of the response
* @return the player profile
* @throws AuthenticationException if credentials are not valid
* @throws IOException if an IO exception occurs
*/
@Blocking
@NotNull
public <T> T verify(@NotNull String accessToken, @NotNull Class<T> responseType) throws AuthenticationException, IOException {
JsonObject body = new JsonObject();
body.addProperty("access_token", accessToken);
return this.post("verify", body, responseType);
}
use of org.jetbrains.annotations.Blocking in project AzAuth by Azuriom.
the class AzAuthenticator method post.
@Blocking
@Contract("_, _, null -> null; _, _, !null -> !null")
private <T> T post(@NotNull String endPoint, @NotNull JsonObject body, @Nullable Class<T> responseType) throws AuthenticationException, IOException {
URL apiUrl = new URL(this.url + "/api/auth/" + endPoint);
HttpURLConnection connection = (HttpURLConnection) apiUrl.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.addRequestProperty("User-Agent", "AzAuth authenticator v1");
connection.addRequestProperty("Content-Type", "application/json; charset=utf-8");
try (OutputStream out = connection.getOutputStream()) {
out.write(body.toString().getBytes(StandardCharsets.UTF_8));
}
if (connection.getResponseCode() == 422) {
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()))) {
AuthResponse status = GSON.fromJson(reader, AuthResponse.class);
throw new AuthenticationException(status.getMessage());
}
}
if (responseType == null) {
return null;
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
T response = GSON.fromJson(reader, responseType);
if (response == null) {
throw new IllegalStateException("Empty JSON response");
}
return response;
}
}
use of org.jetbrains.annotations.Blocking in project AzAuth by Azuriom.
the class AzAuthenticator method logout.
/**
* Invalidate the given access token.
* To get a new valid access token you need to use {@link #authenticate(String, String)} again.
*
* @param accessToken the player access token
* @throws AuthenticationException if credentials are not valid
* @throws IOException if an IO exception occurs
*/
@Blocking
public void logout(@NotNull String accessToken) throws AuthenticationException, IOException {
JsonObject body = new JsonObject();
body.addProperty("access_token", accessToken);
this.post("logout", body, null);
}
Aggregations