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

Simplify #402

Merged
merged 1 commit into from
Jun 27, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@

namespace TwitchLib.Api.Core.RateLimiter
{
/// <summary>
/// Composed Awaitable Constraint
/// </summary>
public class ComposedAwaitableConstraint : IAwaitableConstraint
{
private IAwaitableConstraint _ac1;
private IAwaitableConstraint _ac2;
private readonly SemaphoreSlim _semafore = new SemaphoreSlim(1, 1);
private readonly SemaphoreSlim _semafore = new(1, 1);

internal ComposedAwaitableConstraint(IAwaitableConstraint ac1, IAwaitableConstraint ac2)
{
Expand Down
7 changes: 2 additions & 5 deletions TwitchLib.Api.Helix/Analytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ public class Analytics : ApiBase
/// <summary>
/// Analytics related APIs
/// </summary>
/// <param name="settings"></param>
/// <param name="rateLimiter"></param>
/// <param name="http"></param>
public Analytics(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallHandler http) : base(settings, rateLimiter, http)
{
}
Expand Down Expand Up @@ -87,7 +84,7 @@ public Task<GetGameAnalyticsResponse> GetGameAnalyticsAsync(string gameId = null
{
var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("first", first.ToString())
new("first", first.ToString())
};

if (!string.IsNullOrWhiteSpace(gameId))
Expand Down Expand Up @@ -173,7 +170,7 @@ public Task<GetExtensionAnalyticsResponse> GetExtensionAnalyticsAsync(string ext
{
var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("first", first.ToString())
new("first", first.ToString())
};

if (!string.IsNullOrWhiteSpace(extensionId))
Expand Down
7 changes: 4 additions & 3 deletions TwitchLib.Api.Helix/Bits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ public Bits(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallHandler ht
{
}

#region GetCheermotes

/// <summary>
/// Retrieves the list of available Cheermotes, animated emotes to which viewers can assign Bits, to cheer in chat. Cheermotes returned are available throughout Twitch, in all Bits-enabled channels.
/// </summary>
/// <param name="broadcasterId">D for the broadcaster who might own specialized Cheermotes.</param>
/// <param name="accessToken">optional access token to override the use of the stored one in the TwitchAPI instance</param>
/// <returns cref="GetCheermotesResponse"></returns>
#region GetCheermotes
public Task<GetCheermotesResponse> GetCheermotesAsync(string broadcasterId = null, string accessToken = null)
{
var getParams = new List<KeyValuePair<string, string>>();
Expand Down Expand Up @@ -67,7 +68,7 @@ public Task<GetBitsLeaderboardResponse> GetBitsLeaderboardAsync(int count = 10,
{
var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("count", count.ToString())
new("count", count.ToString())
};

switch (period)
Expand Down Expand Up @@ -115,7 +116,7 @@ public Task<GetExtensionBitsProductsResponse> GetExtensionBitsProductsAsync(bool
{
var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("should_include_all", shouldIncludeAll.ToString().ToLower())
new("should_include_all", shouldIncludeAll.ToString().ToLower())
};

return TwitchGetGenericAsync<GetExtensionBitsProductsResponse>("/bits/extensions", ApiVersion.Helix, getParams, accessToken);
Expand Down
28 changes: 17 additions & 11 deletions TwitchLib.Api.Helix/ChannelPoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public ChannelPoints(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallH
}

#region CreateCustomRewards

/// <summary>
/// Creates a Custom Reward on a channel.
/// <para>Required scope: channel:manage:redemptions</para>
Expand All @@ -40,14 +41,15 @@ public Task<CreateCustomRewardsResponse> CreateCustomRewardsAsync(string broadca
{
var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId)
new("broadcaster_id", broadcasterId)
};

return TwitchPostGenericAsync<CreateCustomRewardsResponse>("/channel_points/custom_rewards", ApiVersion.Helix, JsonConvert.SerializeObject(request), getParams, accessToken);
}
#endregion

#region DeleteCustomReward

/// <summary>
/// Deletes a Custom Reward on a channel.
/// <para>Required scope: channel:manage:redemptions</para>
Expand All @@ -68,15 +70,16 @@ public Task DeleteCustomRewardAsync(string broadcasterId, string rewardId, strin
{
var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId),
new KeyValuePair<string, string>("id", rewardId)
new("broadcaster_id", broadcasterId),
new("id", rewardId)
};

return TwitchDeleteAsync("/channel_points/custom_rewards", ApiVersion.Helix, getParams, accessToken);
}
#endregion

#region GetCustomReward

/// <summary>
/// Returns a list of Custom Reward objects for the Custom Rewards on a channel.
/// <para>Required scope: channel:read:redemptions</para>
Expand All @@ -93,8 +96,8 @@ public Task<GetCustomRewardsResponse> GetCustomRewardAsync(string broadcasterId,
{
var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId),
new KeyValuePair<string, string>("only_manageable_rewards", onlyManageableRewards.ToString().ToLower())
new("broadcaster_id", broadcasterId),
new("only_manageable_rewards", onlyManageableRewards.ToString().ToLower())
};

if (rewardIds != null && rewardIds.Count > 0)
Expand All @@ -107,6 +110,7 @@ public Task<GetCustomRewardsResponse> GetCustomRewardAsync(string broadcasterId,
#endregion

#region UpdateCustomReward

/// <summary>
/// Updates a Custom Reward created on a channel.
/// <para>The Custom Reward specified by id must have been created by the ClientId attached to the user OAuth token.</para>
Expand All @@ -124,15 +128,16 @@ public Task<UpdateCustomRewardResponse> UpdateCustomRewardAsync(string broadcast
{
var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId),
new KeyValuePair<string, string>("id", rewardId)
new("broadcaster_id", broadcasterId),
new("id", rewardId)
};

return TwitchPatchGenericAsync<UpdateCustomRewardResponse>("/channel_points/custom_rewards", ApiVersion.Helix, JsonConvert.SerializeObject(request), getParams, accessToken);
}
#endregion

#region GetCustomRewardRedemption

/// <summary>
/// Returns Custom Reward Redemption objects for a Custom Reward on a channel that was created by the same ClientId.
/// <para>Developers only have access to get and update redemptions for the rewards created programmatically by the same ClientId.</para>
Expand Down Expand Up @@ -164,8 +169,8 @@ public Task<GetCustomRewardRedemptionResponse> GetCustomRewardRedemptionAsync(st
{
var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId),
new KeyValuePair<string, string>("reward_id", rewardId),
new("broadcaster_id", broadcasterId),
new("reward_id", rewardId),
};

if (redemptionIds != null && redemptionIds.Count > 0)
Expand Down Expand Up @@ -198,6 +203,7 @@ public Task<GetCustomRewardRedemptionResponse> GetCustomRewardRedemptionAsync(st
#endregion

#region UpdateCustomRewardRedemption

/// <summary>
/// Updates a Custom Reward created on a channel.
/// <para>The Custom Reward specified by id must have been created by the ClientId attached to the user OAuth token.</para>
Expand All @@ -216,8 +222,8 @@ public Task<UpdateRedemptionStatusResponse> UpdateRedemptionStatusAsync(string b
{
var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId),
new KeyValuePair<string, string>("reward_id", rewardId)
new("broadcaster_id", broadcasterId),
new("reward_id", rewardId)
};

getParams.AddRange(redemptionIds.Select(redemptionId => new KeyValuePair<string, string>("id", redemptionId)));
Expand Down
37 changes: 20 additions & 17 deletions TwitchLib.Api.Helix/Channels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public Channels(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallHandle
}

#region GetChannelInformation

/// <summary>
/// Gets channel information for given user.
/// </summary>
Expand All @@ -42,14 +43,15 @@ public Task<GetChannelInformationResponse> GetChannelInformationAsync(string bro

var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId)
new("broadcaster_id", broadcasterId)
};

return TwitchGetGenericAsync<GetChannelInformationResponse>("/channels", ApiVersion.Helix, getParams, accessToken);
}
#endregion

#region ModifyChannelInformation

/// <summary>
/// Modifies channel information for given user.
/// <para>Required scope: channel:manage:broadcast</para>
Expand All @@ -66,7 +68,7 @@ public async Task<bool> ModifyChannelInformationAsync(string broadcasterId, Modi

var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId)
new("broadcaster_id", broadcasterId)
};

var response = await TwitchPatchAsync("/channels", ApiVersion.Helix, JsonConvert.SerializeObject(request), getParams, accessToken);
Expand All @@ -77,6 +79,7 @@ public async Task<bool> ModifyChannelInformationAsync(string broadcasterId, Modi
#endregion

#region GetChannelEditors

/// <summary>
/// Gets a list of users who have editor permissions for a specific channel.
/// <para>Required scope: channel:read:editors</para>
Expand All @@ -92,7 +95,7 @@ public Task<GetChannelEditorsResponse> GetChannelEditorsAsync(string broadcaster

var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId)
new("broadcaster_id", broadcasterId)
};

return TwitchGetGenericAsync<GetChannelEditorsResponse>("/channels/editors", ApiVersion.Helix, getParams, accessToken);
Expand Down Expand Up @@ -121,8 +124,8 @@ public Task<GetChannelVIPsResponse> GetVIPsAsync(string broadcasterId, List<stri

var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId),
new KeyValuePair<string, string>("first", first.ToString())
new("broadcaster_id", broadcasterId),
new("first", first.ToString())
};

if (userIds != null)
Expand Down Expand Up @@ -161,16 +164,16 @@ public Task AddChannelVIPAsync(string broadcasterId, string userId, string acces

var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId),
new KeyValuePair<string, string>("user_id", userId),
new("broadcaster_id", broadcasterId),
new("user_id", userId),
};

return TwitchPostAsync("/channels/vips", ApiVersion.Helix, null, getParams, accessToken);
}

#endregion

#region DeleteChannelVIP
#region RemoveChannelVIP

/// <summary>
/// Removes a VIP from the broadcaster’s chat room.
Expand All @@ -190,8 +193,8 @@ public Task RemoveChannelVIPAsync(string broadcasterId, string userId, string ac

var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId),
new KeyValuePair<string, string>("user_id", userId),
new("broadcaster_id", broadcasterId),
new("user_id", userId),
};

return TwitchDeleteAsync("/channels/vips", ApiVersion.Helix, getParams, accessToken);
Expand Down Expand Up @@ -228,7 +231,7 @@ public Task<GetFollowedChannelsResponse> GetFollowedChannelsAsync(string userId,

var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("user_id", userId)
new("user_id", userId)
};

if (!string.IsNullOrWhiteSpace(broadcasterId))
Expand All @@ -242,11 +245,11 @@ public Task<GetFollowedChannelsResponse> GetFollowedChannelsAsync(string userId,
}

#endregion

#region GetChannelFollowers

/// <summary>
/// Gets a list of users that follow the specified broadcaster.
/// Gets a list of users that follow the specified broadcaster. Requires moderator:read:followers scope.
/// <para>You can also use this endpoint to see whether a specific user follows the broadcaster.</para>
/// </summary>
/// <param name="broadcasterId">The broadcaster’s ID. Returns the list of users that follow this broadcaster.</param>
Expand All @@ -269,7 +272,7 @@ public Task<GetChannelFollowersResponse> GetChannelFollowersAsync(string broadca

var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId)
new("broadcaster_id", broadcasterId)
};

if (!string.IsNullOrWhiteSpace(userId))
Expand Down Expand Up @@ -299,7 +302,7 @@ public Task<GetAdScheduleResponse> GetAdScheduleAsync(string broadcasterId, stri
var getParams = new List<KeyValuePair<string, string>>
{

new KeyValuePair<string, string>("broadcaster_id", broadcasterId)
new("broadcaster_id", broadcasterId)
};

return TwitchGetGenericAsync<GetAdScheduleResponse>("/channels/ads", ApiVersion.Helix, getParams, accessToken);
Expand All @@ -315,13 +318,13 @@ public Task<GetAdScheduleResponse> GetAdScheduleAsync(string broadcasterId, stri
/// <param name="broadcasterId">The broadcaster's ID. Ad snoozing is relevant to this broadcaster, and so should the auth.</param>
/// <param name="accessToken"> Optional access token to override the use of the stored one in the TwitchAPI instance</param>
/// <returns cref="SnoozeNextAdResponse"></returns>
public Task<SnoozeNextAdResponse> SnoozeNextAd(string broadcasterId, string accessToken = null)
public Task<SnoozeNextAdResponse> SnoozeNextAdAsync(string broadcasterId, string accessToken = null)
{
if (string.IsNullOrWhiteSpace(broadcasterId))
throw new BadParameterException("broadcasterId must be set");
var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId)
new("broadcaster_id", broadcasterId)
};

return TwitchPostGenericAsync<SnoozeNextAdResponse>("/channels/ads/schedule/snooze", ApiVersion.Helix, null, getParams, accessToken);
Expand Down
8 changes: 5 additions & 3 deletions TwitchLib.Api.Helix/Charity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public Charity(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallHandler
}

#region GetCharityCampaign

/// <summary>
/// Gets information about the charity campaign that a broadcaster is running, such as their fundraising goal and the amount that’s been donated so far.
/// Requires an user access token that includes the channel:read:charity scope.
Expand All @@ -35,14 +36,15 @@ public Task<GetCharityCampaignResponse> GetCharityCampaignAsync(string broadcast

var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId)
new("broadcaster_id", broadcasterId)
};

return TwitchGetGenericAsync<GetCharityCampaignResponse>("/charity/campaigns", ApiVersion.Helix, getParams, accessToken);
}
#endregion

#region GetCharityCampaignDonations

/// <summary>
/// Gets the list of donations that users have made to the broadcaster’s active charity campaign.
/// Requires a user access token that includes the channel:read:charity scope.
Expand All @@ -63,8 +65,8 @@ public Task<GetCharityCampaignDonationsResponse> GetCharityCampaignDonationsAsyn

var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId),
new KeyValuePair<string, string>("first", first.ToString())
new("broadcaster_id", broadcasterId),
new("first", first.ToString())
};

if (!string.IsNullOrWhiteSpace(after))
Expand Down
3 changes: 2 additions & 1 deletion TwitchLib.Api.Helix/Clips.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public Clips(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallHandler h
{ }

#region GetClips

/// <summary>
/// Gets clip information by clip ID (one or more), broadcaster ID (one only), or game ID (one only).
/// <para>Note: The clips service returns a maximum of 1000 clips.</para>
Expand Down Expand Up @@ -123,7 +124,7 @@ public Task<CreatedClipResponse> CreateClipAsync(string broadcasterId, string ac
{
var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId)
new("broadcaster_id", broadcasterId)
};

return TwitchPostGenericAsync<CreatedClipResponse>("/clips", ApiVersion.Helix, null, getParams, accessToken);
Expand Down
Loading
Loading