Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Subscription data #195

Open
wants to merge 3 commits into
base: 1.6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions src/main/java/discord4j/discordjson/json/SubscriptionData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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 java.util.List;
import java.util.Optional;
import org.immutables.value.Value;

@Value.Immutable
@JsonSerialize(as = ImmutableSubscriptionData.class)
@JsonDeserialize(as = ImmutableSubscriptionData.class)
public interface SubscriptionData {

static ImmutableSubscriptionData.Builder builder() {
return ImmutableSubscriptionData.builder();
}

Id id();

@JsonProperty("user_id")
Id userId();

@JsonProperty("sku_ids")
List<Id> skuIds();

@JsonProperty("entitlement_ids")
List<Id> entitlementIds();

@JsonProperty("current_period_start")
String currentPeriodStart();

@JsonProperty("current_period_end")
String currentPeriodEnd();

int status();

@JsonProperty("canceled_at")
Optional<String> canceledAt();

Possible<String> country();

}
Original file line number Diff line number Diff line change
@@ -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.SubscriptionData;
import org.immutables.value.Value;

@Value.Immutable
@JsonSerialize(as = ImmutableSubscriptionCreate.class)
@JsonDeserialize(as = ImmutableSubscriptionCreate.class)
public interface SubscriptionCreate {

static ImmutableSubscriptionCreate.Builder builder() {
return ImmutableSubscriptionCreate.builder();
}

@JsonUnwrapped
SubscriptionData subscription();

}
Original file line number Diff line number Diff line change
@@ -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.SubscriptionData;
import org.immutables.value.Value;

@Value.Immutable
@JsonSerialize(as = ImmutableSubscriptionDelete.class)
@JsonDeserialize(as = ImmutableSubscriptionDelete.class)
public interface SubscriptionDelete {

static ImmutableSubscriptionDelete.Builder builder() {
return ImmutableSubscriptionDelete.builder();
}

@JsonUnwrapped
SubscriptionData subscription();

}
Original file line number Diff line number Diff line change
@@ -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.SubscriptionData;
import org.immutables.value.Value;

@Value.Immutable
@JsonSerialize(as = ImmutableSubscriptionUpdate.class)
@JsonDeserialize(as = ImmutableSubscriptionUpdate.class)
public interface SubscriptionUpdate {

static ImmutableSubscriptionUpdate.Builder builder() {
return ImmutableSubscriptionUpdate.builder();
}

@JsonUnwrapped
SubscriptionData subscription();

}
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,10 @@ public void readGuildScheduledEvents() throws IOException {
GuildScheduledEventData[] data = read("/rest/GuildScheduledEventData.json", GuildScheduledEventData[].class);
log.info("{}", Arrays.asList(data));
}

@Test
public void readSubscriptionData() throws IOException {
SubscriptionData data = read("/rest/SubscriptionData.json", SubscriptionData.class);
log.info("{}", data);
}
}
12 changes: 12 additions & 0 deletions src/test/resources/rest/SubscriptionData.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id": "1278078770116427839",
"user_id": "1088605110638227537",
"sku_ids": [
"1158857122189168803"
],
"entitlement_ids": [],
"current_period_start": "2024-08-27T19:48:44.406602+00:00",
"current_period_end": "2024-09-27T19:48:44.406602+00:00",
"status": 0,
"canceled_at": null
}