Skip to content

Commit 00df254

Browse files
committed
Update entitlement endpoints.
See discord/discord-api-docs#7279.
1 parent 259dea7 commit 00df254

File tree

3 files changed

+79
-5
lines changed

3 files changed

+79
-5
lines changed

Backend/Remora.Discord.API.Abstractions/API/Rest/IDiscordRestMonetizationAPI.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public interface IDiscordRestMonetizationAPI
4747
/// <param name="limit">The maximum number of entitlements to return (1-100). Defaults to 100.</param>
4848
/// <param name="guildID">The ID of the guild to limit the search to.</param>
4949
/// <param name="excludeEnded">Whether to exclude expired entitlements.</param>
50+
/// <param name="excludeDeleted">Whether to exclude deleted entitlements.</param>
5051
/// <param name="ct">The cancellation token for this operation.</param>
5152
/// <returns>The entitlements.</returns>
5253
Task<Result<IReadOnlyList<IEntitlement>>> ListEntitlementsAsync
@@ -59,6 +60,21 @@ Task<Result<IReadOnlyList<IEntitlement>>> ListEntitlementsAsync
5960
Optional<int> limit = default,
6061
Optional<Snowflake> guildID = default,
6162
Optional<bool> excludeEnded = default,
63+
Optional<bool> excludeDeleted = default,
64+
CancellationToken ct = default
65+
);
66+
67+
/// <summary>
68+
/// Gets information about an entitlement.
69+
/// </summary>
70+
/// <param name="applicationID">The ID of the application.</param>
71+
/// <param name="entitlementID">The ID of the entitlement.</param>
72+
/// <param name="ct">The cancellation token for this operation.</param>
73+
/// <returns>The entitlement.</returns>
74+
Task<Result<IEntitlement>> GetEntitlementAsync
75+
(
76+
Snowflake applicationID,
77+
Snowflake entitlementID,
6278
CancellationToken ct = default
6379
);
6480

Backend/Remora.Discord.Rest/API/Monetization/DiscordRestMonetizationAPI.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public Task<Result<IReadOnlyList<IEntitlement>>> ListEntitlementsAsync
6868
Optional<int> limit = default,
6969
Optional<Snowflake> guildID = default,
7070
Optional<bool> excludeEnded = default,
71+
Optional<bool> excludeDeleted = default,
7172
CancellationToken ct = default
7273
) => this.RestHttpClient.GetAsync<IReadOnlyList<IEntitlement>>
7374
(
@@ -80,10 +81,24 @@ public Task<Result<IReadOnlyList<IEntitlement>>> ListEntitlementsAsync
8081
.AddQueryParameter("limit", limit)
8182
.AddQueryParameter("guild_id", guildID)
8283
.AddQueryParameter("exclude_ended", excludeEnded)
84+
.AddQueryParameter("exclude_deleted", excludeDeleted)
8385
.WithRateLimitContext(this.RateLimitCache),
8486
ct: ct
8587
);
8688

89+
/// <inheritdoc />
90+
public Task<Result<IEntitlement>> GetEntitlementAsync
91+
(
92+
Snowflake applicationID,
93+
Snowflake entitlementID,
94+
CancellationToken ct = default
95+
) => this.RestHttpClient.GetAsync<IEntitlement>
96+
(
97+
$"applications/{applicationID}/entitlements/{entitlementID}",
98+
b => b.WithRateLimitContext(this.RateLimitCache),
99+
ct: ct
100+
);
101+
87102
/// <inheritdoc />
88103
public Task<Result> ConsumeEntitlementAsync
89104
(

Tests/Remora.Discord.Rest.Tests/API/Monetization/DiscordRestMonetizationAPITests.cs

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,24 @@ public async Task PerformsRequestCorrectly()
7272
var limit = 1;
7373
var guildID = DiscordSnowflake.New(7);
7474
var excludeEnded = true;
75+
var excludeDeleted = true;
7576

7677
var api = CreateAPI
7778
(
7879
b => b
7980
.Expect(HttpMethod.Get, $"{Constants.BaseURL}applications/{applicationID}/entitlements")
8081
.WithExactQueryString
8182
(
82-
new KeyValuePair<string, string>[]
83-
{
83+
[
8484
new("user_id", userID.ToString()),
8585
new("sku_ids", string.Join(',', skuIDs.Select(id => id.ToString()))),
8686
new("before", before.ToString()),
8787
new("after", after.ToString()),
8888
new("limit", limit.ToString()),
8989
new("guild_id", guildID.ToString()),
90-
new("exclude_ended", excludeEnded.ToString())
91-
}
90+
new("exclude_ended", excludeEnded.ToString()),
91+
new("exclude_deleted", excludeDeleted.ToString())
92+
]
9293
)
9394
.Respond("application/json", "[ ]")
9495
);
@@ -102,7 +103,49 @@ public async Task PerformsRequestCorrectly()
102103
after,
103104
limit,
104105
guildID,
105-
excludeEnded
106+
excludeEnded,
107+
excludeDeleted
108+
);
109+
110+
ResultAssert.Successful(result);
111+
}
112+
}
113+
114+
/// <summary>
115+
/// Tests the <see cref="DiscordRestMonetizationAPI.GetEntitlementAsync"/> method.
116+
/// </summary>
117+
public class GetEntitlementAsync : RestAPITestBase<IDiscordRestMonetizationAPI>
118+
{
119+
/// <summary>
120+
/// Initializes a new instance of the <see cref="GetEntitlementAsync"/> class.
121+
/// </summary>
122+
/// <param name="fixture">The test fixture.</param>
123+
public GetEntitlementAsync(RestAPITestFixture fixture)
124+
: base(fixture)
125+
{
126+
}
127+
128+
/// <summary>
129+
/// Tests whether the API method performs its request correctly.
130+
/// </summary>
131+
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
132+
[Fact]
133+
public async Task PerformsRequestCorrectly()
134+
{
135+
var applicationID = DiscordSnowflake.New(1);
136+
var entitlementID = DiscordSnowflake.New(2);
137+
138+
var api = CreateAPI
139+
(
140+
b => b
141+
.Expect(HttpMethod.Get, $"{Constants.BaseURL}applications/{applicationID}/entitlements/{entitlementID}")
142+
.Respond("application/json", SampleRepository.Samples[typeof(IEntitlement)])
143+
);
144+
145+
var result = await api.GetEntitlementAsync
146+
(
147+
applicationID,
148+
entitlementID
106149
);
107150

108151
ResultAssert.Successful(result);

0 commit comments

Comments
 (0)