From 749b1143739624e21193f68c75824bb5713ba910 Mon Sep 17 00:00:00 2001 From: Axel Joly Date: Tue, 26 Mar 2024 23:13:43 -0400 Subject: [PATCH] feat: add monetization data classes (#160) --- .../json/CreateTestEntitlementRequest.java | 27 +++++++++++ .../discordjson/json/EntitlementData.java | 48 +++++++++++++++++++ .../discordjson/json/InteractionData.java | 5 ++ .../discord4j/discordjson/json/SkuData.java | 30 ++++++++++++ .../json/gateway/EntitlementCreate.java | 21 ++++++++ .../json/gateway/EntitlementDelete.java | 21 ++++++++ .../json/gateway/EntitlementUpdate.java | 21 ++++++++ 7 files changed, 173 insertions(+) create mode 100644 src/main/java/discord4j/discordjson/json/CreateTestEntitlementRequest.java create mode 100644 src/main/java/discord4j/discordjson/json/EntitlementData.java create mode 100644 src/main/java/discord4j/discordjson/json/SkuData.java create mode 100644 src/main/java/discord4j/discordjson/json/gateway/EntitlementCreate.java create mode 100644 src/main/java/discord4j/discordjson/json/gateway/EntitlementDelete.java create mode 100644 src/main/java/discord4j/discordjson/json/gateway/EntitlementUpdate.java diff --git a/src/main/java/discord4j/discordjson/json/CreateTestEntitlementRequest.java b/src/main/java/discord4j/discordjson/json/CreateTestEntitlementRequest.java new file mode 100644 index 00000000..4da8b2d1 --- /dev/null +++ b/src/main/java/discord4j/discordjson/json/CreateTestEntitlementRequest.java @@ -0,0 +1,27 @@ +package discord4j.discordjson.json; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import discord4j.discordjson.Id; +import org.immutables.value.Value; + +@Value.Immutable +@JsonSerialize(as = ImmutableCreateTestEntitlementRequest.class) +@JsonDeserialize(as = ImmutableCreateTestEntitlementRequest.class) +public interface CreateTestEntitlementRequest { + + static ImmutableCreateTestEntitlementRequest.Builder builder() { + return ImmutableCreateTestEntitlementRequest.builder(); + } + + @JsonProperty("sku_id") + Id skuId(); + + @JsonProperty("owner_id") + Id ownerId(); + + @JsonProperty("owner_type") + int ownerType(); + +} diff --git a/src/main/java/discord4j/discordjson/json/EntitlementData.java b/src/main/java/discord4j/discordjson/json/EntitlementData.java new file mode 100644 index 00000000..dbf2a6a0 --- /dev/null +++ b/src/main/java/discord4j/discordjson/json/EntitlementData.java @@ -0,0 +1,48 @@ +package discord4j.discordjson.json; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import discord4j.discordjson.Id; +import discord4j.discordjson.possible.Possible; +import org.immutables.value.Value; + +@Value.Immutable +@JsonSerialize(as = ImmutableEntitlementData.class) +@JsonDeserialize(as = ImmutableEntitlementData.class) +public interface EntitlementData { + + static ImmutableEntitlementData.Builder builder() { + return ImmutableEntitlementData.builder(); + } + + Id id(); + + @JsonProperty("sku_id") + Id skuId(); + + @JsonProperty("application_id") + Id applicationId(); + + @JsonProperty("user_id") + Possible userId(); + + int type(); + + boolean deleted(); + + @JsonProperty("guild_id") + Possible guildId(); + + // The following fields will not be present in test entitlements + + @JsonProperty("starts_at") + Possible startsAt(); + + @JsonProperty("ends_at") + Possible endsAt(); + + @JsonProperty("subscription_id") + Possible subscriptionId(); + +} diff --git a/src/main/java/discord4j/discordjson/json/InteractionData.java b/src/main/java/discord4j/discordjson/json/InteractionData.java index a63e9a1a..2fb26512 100644 --- a/src/main/java/discord4j/discordjson/json/InteractionData.java +++ b/src/main/java/discord4j/discordjson/json/InteractionData.java @@ -7,6 +7,8 @@ import discord4j.discordjson.possible.Possible; import org.immutables.value.Value; +import java.util.List; + @Value.Immutable @JsonSerialize(as = ImmutableInteractionData.class) @JsonDeserialize(as = ImmutableInteractionData.class) @@ -64,4 +66,7 @@ static ImmutableInteractionData.Builder builder() { @JsonProperty("app_permissions") Possible appPermissions(); + + @JsonProperty("entitlements") + List entitlements(); } diff --git a/src/main/java/discord4j/discordjson/json/SkuData.java b/src/main/java/discord4j/discordjson/json/SkuData.java new file mode 100644 index 00000000..2367dadf --- /dev/null +++ b/src/main/java/discord4j/discordjson/json/SkuData.java @@ -0,0 +1,30 @@ +package discord4j.discordjson.json; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import discord4j.discordjson.Id; +import org.immutables.value.Value; + +@Value.Immutable +@JsonSerialize(as = ImmutableSkuData.class) +@JsonDeserialize(as = ImmutableSkuData.class) +public interface SkuData { + + static ImmutableSkuData.Builder builder() { + return ImmutableSkuData.builder(); + } + + Id id(); + + int type(); + + @JsonProperty("application_id") + Id applicationId(); + + String name(); + + String slug(); + + int flags(); +} diff --git a/src/main/java/discord4j/discordjson/json/gateway/EntitlementCreate.java b/src/main/java/discord4j/discordjson/json/gateway/EntitlementCreate.java new file mode 100644 index 00000000..6bc86bce --- /dev/null +++ b/src/main/java/discord4j/discordjson/json/gateway/EntitlementCreate.java @@ -0,0 +1,21 @@ +package discord4j.discordjson.json.gateway; + +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import discord4j.discordjson.json.EntitlementData; +import org.immutables.value.Value; + +@Value.Immutable +@JsonSerialize(as = ImmutableEntitlementCreate.class) +@JsonDeserialize(as = ImmutableEntitlementCreate.class) +public interface EntitlementCreate extends Dispatch { + + static ImmutableEntitlementCreate.Builder builder() { + return ImmutableEntitlementCreate.builder(); + } + + @JsonUnwrapped + EntitlementData entitlement(); + +} diff --git a/src/main/java/discord4j/discordjson/json/gateway/EntitlementDelete.java b/src/main/java/discord4j/discordjson/json/gateway/EntitlementDelete.java new file mode 100644 index 00000000..cdcfe877 --- /dev/null +++ b/src/main/java/discord4j/discordjson/json/gateway/EntitlementDelete.java @@ -0,0 +1,21 @@ +package discord4j.discordjson.json.gateway; + +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import discord4j.discordjson.json.EntitlementData; +import org.immutables.value.Value; + +@Value.Immutable +@JsonSerialize(as = ImmutableEntitlementDelete.class) +@JsonDeserialize(as = ImmutableEntitlementDelete.class) +public interface EntitlementDelete extends Dispatch { + + static ImmutableEntitlementDelete.Builder builder() { + return ImmutableEntitlementDelete.builder(); + } + + @JsonUnwrapped + EntitlementData entitlement(); + +} diff --git a/src/main/java/discord4j/discordjson/json/gateway/EntitlementUpdate.java b/src/main/java/discord4j/discordjson/json/gateway/EntitlementUpdate.java new file mode 100644 index 00000000..f3fc9d13 --- /dev/null +++ b/src/main/java/discord4j/discordjson/json/gateway/EntitlementUpdate.java @@ -0,0 +1,21 @@ +package discord4j.discordjson.json.gateway; + +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import discord4j.discordjson.json.EntitlementData; +import org.immutables.value.Value; + +@Value.Immutable +@JsonSerialize(as = ImmutableEntitlementUpdate.class) +@JsonDeserialize(as = ImmutableEntitlementUpdate.class) +public interface EntitlementUpdate extends Dispatch { + + static ImmutableEntitlementUpdate.Builder builder() { + return ImmutableEntitlementUpdate.builder(); + } + + @JsonUnwrapped + EntitlementData entitlement(); + +}