Search in sources :

Example 1 with OAuthApplicationJSON

use of io.discloader.discloader.network.json.OAuthApplicationJSON in project DiscLoader by R3alCl0ud.

the class DLUser method getOAuth2Application.

/**
 * Gets the OAuth2 application of the logged in user, if {@link User#isBot()}
 * returns true
 *
 * @return A Future that completes with a new {@link OAuth2Application} if
 *         successful.
 * @throws AccountTypeException
 *             Thrown if the account the client is logged in as is a user
 *             account.
 */
public CompletableFuture<OAuth2Application> getOAuth2Application() {
    if (!isBot()) {
        throw new AccountTypeException("Cannot fetch the OAuth2Application details of a User Account.");
    }
    CompletableFuture<OAuth2Application> future = new CompletableFuture<>();
    CompletableFuture<OAuthApplicationJSON> cf = getLoader().rest.request(Methods.GET, Endpoints.currentOAuthApplication, new RESTOptions(), OAuthApplicationJSON.class);
    cf.thenAcceptAsync(appData -> {
        IUser owner = EntityRegistry.addUser(appData.owner);
        future.complete(new OAuth2Application(appData, owner));
    });
    cf.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : OAuthApplicationJSON(io.discloader.discloader.network.json.OAuthApplicationJSON) CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) AccountTypeException(io.discloader.discloader.common.exceptions.AccountTypeException) IUser(io.discloader.discloader.entity.user.IUser)

Aggregations

AccountTypeException (io.discloader.discloader.common.exceptions.AccountTypeException)1 IUser (io.discloader.discloader.entity.user.IUser)1 OAuthApplicationJSON (io.discloader.discloader.network.json.OAuthApplicationJSON)1 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)1 CompletableFuture (java.util.concurrent.CompletableFuture)1