diff --git a/TwitchLib.Api.Helix.Models/Subscriptions/GetBroadcasterSubscriptionResquest.cs b/TwitchLib.Api.Helix.Models/Subscriptions/GetBroadcasterSubscriptionResquest.cs new file mode 100644 index 00000000..ff2e8dea --- /dev/null +++ b/TwitchLib.Api.Helix.Models/Subscriptions/GetBroadcasterSubscriptionResquest.cs @@ -0,0 +1,65 @@ +using System.Collections.Generic; + +namespace TwitchLib.Api.Helix.Models.Subscriptions; + +/// +/// A class to represent the request query data for a Get Broadcaster Subscriptions request. +/// +public class GetBroadcasterSubscriptionsRequest +{ + /// + /// The broadcaster’s ID. This ID must match the user ID in the access token. + /// + public string BroadcasterId { get; set; } = null!; + + /// + /// Filters the list to include only the specified subscribers. + /// + public List? UserIds { get; set; } + + /// + /// The maximum number of items to return per page in the response. + /// The minimum page size is 1 item per page and the maximum is 100 items per page. + /// The default is 20. + /// + public int? First { get; set; } + + /// + /// The cursor used to get the next page of results. + /// Do not specify if you set the query parameter. + /// The Pagination object in the response contains the cursor’s value. + /// + public string? After { get; set; } + + /// + /// The cursor used to get the previous page of results. + /// Do not specify if you set the query parameter. + /// The Pagination object in the response contains the cursor’s value. + /// + public string? Before { get; set; } + + public virtual List> ToParams() + { + var getParams = new List> + { + new("broadcaster_id", BroadcasterId), + new("first", First?.ToString() ?? "20") + }; + + if (UserIds?.Count > 0) + { + foreach (var userId in UserIds) + { + getParams.Add(new("user_id", userId)); + } + } + + if (!string.IsNullOrEmpty(After)) + getParams.Add(new("after", After)); + + if (!string.IsNullOrEmpty(Before)) + getParams.Add(new("before", Before)); + + return getParams; + } +} diff --git a/TwitchLib.Api.Helix/Subscriptions.cs b/TwitchLib.Api.Helix/Subscriptions.cs index 760e3b43..e0a9b894 100644 --- a/TwitchLib.Api.Helix/Subscriptions.cs +++ b/TwitchLib.Api.Helix/Subscriptions.cs @@ -1,4 +1,5 @@ #nullable disable +using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; @@ -92,6 +93,7 @@ public Task GetUserSubscriptionsAsync(string broad /// optional access token to override the use of the stored one in the TwitchAPI instance /// /// + [Obsolete("Use GetEventSubSubscriptionsAsync(GetBroadcasterSubscriptionsRequest, string) instead")] public Task GetBroadcasterSubscriptionsAsync(string broadcasterId, int first = 20, string after = null, string accessToken = null) { if (string.IsNullOrWhiteSpace(broadcasterId)) @@ -106,8 +108,32 @@ public Task GetBroadcasterSubscriptionsAsyn new("first", first.ToString()) }; - if (!string.IsNullOrWhiteSpace(after)) + if (!string.IsNullOrWhiteSpace(after)) getParams.Add(new KeyValuePair("after", after)); + + return TwitchGetGenericAsync("/subscriptions", ApiVersion.Helix, getParams, accessToken); + } + + /// + /// Gets a list of users that subscribe to the specified broadcaster. + /// Required scope: channel:read:subscriptions + /// + /// Request parameters for the call. + /// optional access token to override the use of the stored one in the TwitchAPI instance + /// + /// + public Task GetBroadcasterSubscriptionsAsync(GetBroadcasterSubscriptionsRequest request, string accessToken = null) + { + if (string.IsNullOrWhiteSpace(request.BroadcasterId)) + throw new BadParameterException("request.BroadcasterId must be set"); + + if (request.First > 100) + throw new BadParameterException("request.First must be 100 or less"); + + if (request.UserIds?.Count > 100) + throw new BadParameterException("Count of request.UserIds must be 100 or less"); + + var getParams = request.ToParams(); return TwitchGetGenericAsync("/subscriptions", ApiVersion.Helix, getParams, accessToken); }