Search in sources :

Example 1 with IInvite

use of io.discloader.discloader.entity.invite.IInvite in project DiscLoader by R3alCl0ud.

the class Invite method delete.

@Override
public CompletableFuture<IInvite> delete() {
    CompletableFuture<IInvite> future = new CompletableFuture<>();
    CompletableFuture<InviteJSON> cf = loader.rest.request(Methods.DELETE, Endpoints.invite(code), new RESTOptions(), InviteJSON.class);
    cf.thenAcceptAsync(inviteJSON -> {
        future.complete(new Invite(inviteJSON, loader));
    });
    cf.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) InviteJSON(io.discloader.discloader.network.json.InviteJSON) IInvite(io.discloader.discloader.entity.invite.IInvite) IInvite(io.discloader.discloader.entity.invite.IInvite)

Example 2 with IInvite

use of io.discloader.discloader.entity.invite.IInvite in project DiscLoader by R3alCl0ud.

the class FetchInvites method complete.

@Override
public void complete(String s, Throwable ex) {
    if (ex != null) {
        future.completeExceptionally(ex);
        return;
    }
    List<IInvite> invites = new ArrayList<>();
    InviteJSON[] inviteJSONs = gson.fromJson(s, InviteJSON[].class);
    for (InviteJSON invite : inviteJSONs) {
        invites.add(EntityBuilder.getInviteFactory().buildInvite(invite));
    }
    future.complete(invites);
}
Also used : InviteJSON(io.discloader.discloader.network.json.InviteJSON) ArrayList(java.util.ArrayList) IInvite(io.discloader.discloader.entity.invite.IInvite)

Example 3 with IInvite

use of io.discloader.discloader.entity.invite.IInvite in project DiscLoader by R3alCl0ud.

the class DiscLoader method getInvite.

/**
 * @param code
 * @return A CompletableFuture that completes with an IInvite object if
 *         successful.
 */
public CompletableFuture<IInvite> getInvite(String code) {
    CompletableFuture<IInvite> future = new CompletableFuture<>();
    CompletableFuture<InviteJSON> cf = rest.request(Methods.GET, Endpoints.invite(code), new RESTOptions(), InviteJSON.class);
    cf.thenAcceptAsync(inviteJSON -> {
        future.complete(new Invite(inviteJSON, this));
    });
    cf.exceptionally(ex -> {
        future.completeExceptionally(ex);
        return null;
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) InviteJSON(io.discloader.discloader.network.json.InviteJSON) IInvite(io.discloader.discloader.entity.invite.IInvite) Invite(io.discloader.discloader.core.entity.invite.Invite) IInvite(io.discloader.discloader.entity.invite.IInvite)

Example 4 with IInvite

use of io.discloader.discloader.entity.invite.IInvite in project DiscLoader by R3alCl0ud.

the class Guild method fetchInvites.

@Override
public CompletableFuture<List<IInvite>> fetchInvites() {
    CompletableFuture<List<IInvite>> future = new CompletableFuture<List<IInvite>>();
    CompletableFuture<InviteJSON[]> cf = getLoader().rest.request(Methods.GET, Endpoints.guildInvites(getID()), new RESTOptions(), InviteJSON[].class);
    cf.thenAcceptAsync(inJ -> {
        List<IInvite> ins = new ArrayList<>();
        for (int i = 0; i < inJ.length; i++) {
            IInvite in = new Invite(inJ[i], getLoader());
            invites.put(in.getCode(), in);
            ins.add(in);
        }
        future.complete(ins);
    });
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RESTOptions(io.discloader.discloader.network.rest.RESTOptions) InviteJSON(io.discloader.discloader.network.json.InviteJSON) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) IInvite(io.discloader.discloader.entity.invite.IInvite) Invite(io.discloader.discloader.core.entity.invite.Invite) IInvite(io.discloader.discloader.entity.invite.IInvite)

Aggregations

IInvite (io.discloader.discloader.entity.invite.IInvite)4 InviteJSON (io.discloader.discloader.network.json.InviteJSON)4 RESTOptions (io.discloader.discloader.network.rest.RESTOptions)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 Invite (io.discloader.discloader.core.entity.invite.Invite)2 ArrayList (java.util.ArrayList)2 List (java.util.List)1