Search in sources :

Example 1 with Invite

use of io.discloader.discloader.core.entity.invite.Invite 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 2 with Invite

use of io.discloader.discloader.core.entity.invite.Invite 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

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