Search in sources :

Example 1 with ImplInvite

use of de.btobastian.javacord.entities.impl.ImplInvite in project Javacord by BtoBastian.

the class ImplDiscordAPI method parseInvite.

@Override
public Future<Invite> parseInvite(final String invite, FutureCallback<Invite> callback) {
    final String inviteCode = invite.replace("https://discord.gg/", "").replace("http://discord.gg/", "");
    ListenableFuture<Invite> future = getThreadPool().getListeningExecutorService().submit(new Callable<Invite>() {

        @Override
        public Invite call() throws Exception {
            logger.debug("Trying to parse invite {} (parsed code: {})", invite, inviteCode);
            HttpResponse<JsonNode> response = Unirest.get("https://discordapp.com/api/v6/invite/" + inviteCode).header("authorization", token).asJson();
            checkResponse(response);
            logger.debug("Parsed invite {} (parsed code: {})", invite, inviteCode);
            return new ImplInvite(ImplDiscordAPI.this, response.getBody().getObject());
        }
    });
    if (callback != null) {
        Futures.addCallback(future, callback);
    }
    return future;
}
Also used : HttpResponse(com.mashape.unirest.http.HttpResponse) ImplInvite(de.btobastian.javacord.entities.impl.ImplInvite) ImplInvite(de.btobastian.javacord.entities.impl.ImplInvite) UnirestException(com.mashape.unirest.http.exceptions.UnirestException) RateLimitedException(de.btobastian.javacord.exceptions.RateLimitedException) BadResponseException(de.btobastian.javacord.exceptions.BadResponseException) IOException(java.io.IOException) NotSupportedForBotsException(de.btobastian.javacord.exceptions.NotSupportedForBotsException) ExecutionException(java.util.concurrent.ExecutionException) PermissionsException(de.btobastian.javacord.exceptions.PermissionsException)

Aggregations

HttpResponse (com.mashape.unirest.http.HttpResponse)1 UnirestException (com.mashape.unirest.http.exceptions.UnirestException)1 ImplInvite (de.btobastian.javacord.entities.impl.ImplInvite)1 BadResponseException (de.btobastian.javacord.exceptions.BadResponseException)1 NotSupportedForBotsException (de.btobastian.javacord.exceptions.NotSupportedForBotsException)1 PermissionsException (de.btobastian.javacord.exceptions.PermissionsException)1 RateLimitedException (de.btobastian.javacord.exceptions.RateLimitedException)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1