From 5cd97b1ec8324a7615da2779715a0cfbe06ab402 Mon Sep 17 00:00:00 2001 From: Nathan Weisz <151496498+nateweisz@users.noreply.github.com> Date: Tue, 16 Apr 2024 16:58:52 -0700 Subject: [PATCH] invites api (#51) --- .../api/impl/invite/DeleteInviteRequest.java | 11 ++++++++ .../api/impl/invite/GetInviteRequest.java | 28 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/main/java/com/javadiscord/jdi/internal/api/impl/invite/DeleteInviteRequest.java create mode 100644 src/main/java/com/javadiscord/jdi/internal/api/impl/invite/GetInviteRequest.java diff --git a/src/main/java/com/javadiscord/jdi/internal/api/impl/invite/DeleteInviteRequest.java b/src/main/java/com/javadiscord/jdi/internal/api/impl/invite/DeleteInviteRequest.java new file mode 100644 index 00000000..8a8501c9 --- /dev/null +++ b/src/main/java/com/javadiscord/jdi/internal/api/impl/invite/DeleteInviteRequest.java @@ -0,0 +1,11 @@ +package com.javadiscord.jdi.internal.api.impl.invite; + +import com.javadiscord.jdi.internal.api.DiscordRequest; +import com.javadiscord.jdi.internal.api.DiscordRequestBuilder; + +public record DeleteInviteRequest(String inviteCode) implements DiscordRequest { + @Override + public DiscordRequestBuilder create() { + return new DiscordRequestBuilder().delete().path("/invites/%s".formatted(inviteCode)); + } +} diff --git a/src/main/java/com/javadiscord/jdi/internal/api/impl/invite/GetInviteRequest.java b/src/main/java/com/javadiscord/jdi/internal/api/impl/invite/GetInviteRequest.java new file mode 100644 index 00000000..2bc84a15 --- /dev/null +++ b/src/main/java/com/javadiscord/jdi/internal/api/impl/invite/GetInviteRequest.java @@ -0,0 +1,28 @@ +package com.javadiscord.jdi.internal.api.impl.invite; + +import com.javadiscord.jdi.internal.api.DiscordRequest; +import com.javadiscord.jdi.internal.api.DiscordRequestBuilder; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +public record GetInviteRequest( + String inviteCode, + Optional withCounts, + Optional withExpiration, + Optional guildScheduledEventId) + implements DiscordRequest { + @Override + public DiscordRequestBuilder create() { + Map body = new HashMap<>(); + withCounts.ifPresent(val -> body.put("with_counts", val)); + withExpiration.ifPresent(val -> body.put("with_expiration", val)); + guildScheduledEventId.ifPresent(val -> body.put("guild_schedulede_event_id", val)); + + return new DiscordRequestBuilder() + .get() + .path("/invites/%s".formatted(inviteCode)) + .body(body); + } +}