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

Convert public method collection parameters to interfaces #267

Open
wants to merge 5 commits into
base: dev
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
2 changes: 1 addition & 1 deletion TwitchLib.Api.Core.Interfaces/IApiSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IApiSettings
string ClientId { get; set; }
bool SkipDynamicScopeValidation { get; set; }
bool SkipAutoServerTokenGeneration { get; set; }
List<AuthScopes> Scopes { get; set; }
IList<AuthScopes> Scopes { get; set; }

event PropertyChangedEventHandler PropertyChanged;
}
Expand Down
4 changes: 2 additions & 2 deletions TwitchLib.Api.Core/ApiSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ApiSettings : IApiSettings, INotifyPropertyChanged
private string _accessToken;
private bool _skipDynamicScopeValidation;
private bool _skipAutoServerTokenGeneration;
private List<AuthScopes> _scopes;
private IList<AuthScopes> _scopes;
public string ClientId
{
get => _clientId;
Expand Down Expand Up @@ -74,7 +74,7 @@ public bool SkipAutoServerTokenGeneration
}
}
}
public List<AuthScopes> Scopes
public IList<AuthScopes> Scopes
{
get => _scopes;
set
Expand Down
2 changes: 1 addition & 1 deletion TwitchLib.Api.Helix/ChannelPoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Task DeleteCustomRewardAsync(string broadcasterId, string rewardId, strin
#endregion

#region GetCustomReward
public Task<GetCustomRewardsResponse> GetCustomRewardAsync(string broadcasterId, List<string> rewardIds = null, bool onlyManageableRewards = false, string accessToken = null)
public Task<GetCustomRewardsResponse> GetCustomRewardAsync(string broadcasterId, ICollection<string> rewardIds = null, bool onlyManageableRewards = false, string accessToken = null)
{
var getParams = new List<KeyValuePair<string, string>>
{
Expand Down
2 changes: 1 addition & 1 deletion TwitchLib.Api.Helix/Clips.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Clips(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallHandler h

#region GetClips

public Task<GetClipsResponse> GetClipsAsync(List<string> clipIds = null, string gameId = null, string broadcasterId = null, string before = null, string after = null, DateTime? startedAt = null, DateTime? endedAt = null, int first = 20, string accessToken = null)
public Task<GetClipsResponse> GetClipsAsync(IEnumerable<string> clipIds = null, string gameId = null, string broadcasterId = null, string before = null, string after = null, DateTime? startedAt = null, DateTime? endedAt = null, int first = 20, string accessToken = null)
{
if (first < 0 || first > 100)
throw new BadParameterException("'first' must between 0 (inclusive) and 100 (inclusive).");
Expand Down
4 changes: 2 additions & 2 deletions TwitchLib.Api.Helix/Entitlements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Entitlements(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallHa
}

#region GetCodeStatus
public Task<GetCodeStatusResponse> GetCodeStatusAsync(List<string> codes, string userId, string accessToken = null)
public Task<GetCodeStatusResponse> GetCodeStatusAsync(ICollection<string> codes, string userId, string accessToken = null)
{
if (codes == null || codes.Count == 0 || codes.Count > 20)
throw new BadParameterException("codes cannot be null and must ahve between 1 and 20 items");
Expand Down Expand Up @@ -83,7 +83,7 @@ public Task<UpdateDropsEntitlementsResponse> UpdateDropsEntitlementsAsync(string
#endregion

#region RedeemCode
public Task<RedeemCodeResponse> RedeemCodeAsync(List<string> codes, string accessToken = null)
public Task<RedeemCodeResponse> RedeemCodeAsync(ICollection<string> codes, string accessToken = null)
{
if (codes == null || codes.Count == 0 || codes.Count > 20)
throw new BadParameterException("codes cannot be null and must ahve between 1 and 20 items");
Expand Down
2 changes: 1 addition & 1 deletion TwitchLib.Api.Helix/EventSub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public EventSub(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallHandle
{
}

public Task<CreateEventSubSubscriptionResponse> CreateEventSubSubscriptionAsync(string type, string version, Dictionary<string, string> condition, string method, string callback,
public Task<CreateEventSubSubscriptionResponse> CreateEventSubSubscriptionAsync(string type, string version, IDictionary<string, string> condition, string method, string callback,
string secret, string clientId = null, string accessToken = null)
{
if (string.IsNullOrEmpty(type))
Expand Down
2 changes: 1 addition & 1 deletion TwitchLib.Api.Helix/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Extensions(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallHand

#region GetExtensionTransactions

public Task<GetExtensionTransactionsResponse> GetExtensionTransactionsAsync(string extensionId, List<string> ids = null, string after = null, int first = 20, string applicationAccessToken = null)
public Task<GetExtensionTransactionsResponse> GetExtensionTransactionsAsync(string extensionId, ICollection<string> ids = null, string after = null, int first = 20, string applicationAccessToken = null)
{
if(extensionId == null)
throw new BadParameterException("extensionId cannot be null");
Expand Down
2 changes: 1 addition & 1 deletion TwitchLib.Api.Helix/Games.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public Games(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallHandler h

#region GetGames

public Task<GetGamesResponse> GetGamesAsync(List<string> gameIds = null, List<string> gameNames = null, string accessToken = null)
public Task<GetGamesResponse> GetGamesAsync(ICollection<string> gameIds = null, ICollection<string> gameNames = null, string accessToken = null)
{
if (gameIds == null && gameNames == null || gameIds != null && gameIds.Count == 0 && gameNames == null || gameNames != null && gameNames.Count == 0 && gameIds == null)
throw new BadParameterException("Either gameIds or gameNames must have at least one value");
Expand Down
12 changes: 6 additions & 6 deletions TwitchLib.Api.Helix/Moderation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Task ManageHeldAutoModMessagesAsync(string userId, string msgId, ManageHe

#region CheckAutoModeStatus

public Task<CheckAutoModStatusResponse> CheckAutoModStatusAsync(List<Message> messages, string broadcasterId, string accessToken = null)
public Task<CheckAutoModStatusResponse> CheckAutoModStatusAsync(ICollection<Message> messages, string broadcasterId, string accessToken = null)
{
if (messages == null || messages.Count == 0)
throw new BadParameterException("messages cannot be null and must be greater than 0 length");
Expand All @@ -55,7 +55,7 @@ public Task<CheckAutoModStatusResponse> CheckAutoModStatusAsync(List<Message> me

MessageRequest request = new MessageRequest()
{
Messages = messages.ToArray()
Messages = (Message[])messages
};

return TwitchPostGenericAsync<CheckAutoModStatusResponse>("/moderation/enforcements/status", ApiVersion.Helix, JsonConvert.SerializeObject(request), getParams, accessToken);
Expand All @@ -65,7 +65,7 @@ public Task<CheckAutoModStatusResponse> CheckAutoModStatusAsync(List<Message> me

#region GetBannedEvents

public Task<GetBannedEventsResponse> GetBannedEventsAsync(string broadcasterId, List<string> userIds = null, string after = null, string first = null, string accessToken = null)
public Task<GetBannedEventsResponse> GetBannedEventsAsync(string broadcasterId, ICollection<string> userIds = null, string after = null, string first = null, string accessToken = null)
{
if (broadcasterId == null || broadcasterId.Length == 0)
throw new BadParameterException("broadcasterId cannot be null and must be greater than 0 length");
Expand All @@ -92,7 +92,7 @@ public Task<GetBannedEventsResponse> GetBannedEventsAsync(string broadcasterId,

#region GetBannedUsers

public Task<GetBannedUsersResponse> GetBannedUsersAsync(string broadcasterId, List<string> userIds = null, string after = null, string before = null, string accessToken = null)
public Task<GetBannedUsersResponse> GetBannedUsersAsync(string broadcasterId, ICollection<string> userIds = null, string after = null, string before = null, string accessToken = null)
{
if (broadcasterId == null || broadcasterId.Length == 0)
throw new BadParameterException("broadcasterId cannot be null and must be greater than 0 length");
Expand All @@ -119,7 +119,7 @@ public Task<GetBannedUsersResponse> GetBannedUsersAsync(string broadcasterId, Li

#region GetModerators

public Task<GetModeratorsResponse> GetModeratorsAsync(string broadcasterId, List<string> userIds = null, string after = null, string accessToken = null)
public Task<GetModeratorsResponse> GetModeratorsAsync(string broadcasterId, ICollection<string> userIds = null, string after = null, string accessToken = null)
{
if (broadcasterId == null || broadcasterId.Length == 0)
throw new BadParameterException("broadcasterId cannot be null and must be greater than 0 length");
Expand All @@ -143,7 +143,7 @@ public Task<GetModeratorsResponse> GetModeratorsAsync(string broadcasterId, List

#region GetModeratorEvents

public Task<GetModeratorEventsResponse> GetModeratorEventsAsync(string broadcasterId, List<string> userIds = null, string accessToken = null)
public Task<GetModeratorEventsResponse> GetModeratorEventsAsync(string broadcasterId, ICollection<string> userIds = null, string accessToken = null)
{
if (broadcasterId == null || broadcasterId.Length == 0)
throw new BadParameterException("broadcasterId cannot be null and must be greater than 0 length");
Expand Down
2 changes: 1 addition & 1 deletion TwitchLib.Api.Helix/Polls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Polls(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallHandler h
{
}

public Task<GetPollsResponse> GetPollsAsync(string broadcasterId, List<string> ids = null, string after = null, int first = 20, string accessToken = null)
public Task<GetPollsResponse> GetPollsAsync(string broadcasterId, ICollection<string> ids = null, string after = null, int first = 20, string accessToken = null)
{
var getParams = new List<KeyValuePair<string, string>>
{
Expand Down
2 changes: 1 addition & 1 deletion TwitchLib.Api.Helix/Predictions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Predictions(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallHan
{
}

public Task<GetPredictionsResponse> GetPredictionsAsync(string broadcasterId, List<string> ids = null, string after = null, int first = 20, string accessToken = null)
public Task<GetPredictionsResponse> GetPredictionsAsync(string broadcasterId, ICollection<string> ids = null, string after = null, int first = 20, string accessToken = null)
{
var getParams = new List<KeyValuePair<string, string>>
{
Expand Down
2 changes: 1 addition & 1 deletion TwitchLib.Api.Helix/Schedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Schedule : ApiBase
public Schedule(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallHandler http) : base(settings, rateLimiter, http)
{ }

public Task<GetChannelStreamScheduleResponse> GetChannelStreamScheduleAsync(string broadcasterId, List<string> segmentIds = null, string startTime = null, string utcOffset = null,
public Task<GetChannelStreamScheduleResponse> GetChannelStreamScheduleAsync(string broadcasterId, ICollection<string> segmentIds = null, string startTime = null, string utcOffset = null,
int first = 20, string after = null, string accessToken = null)
{
var getParams = new List<KeyValuePair<string, string>>
Expand Down
4 changes: 2 additions & 2 deletions TwitchLib.Api.Helix/Streams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public Streams(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallHandler
{
}

public Task<GetStreamsResponse> GetStreamsAsync(string after = null, List<string> communityIds = null, int first = 20, List<string> gameIds = null, List<string> languages = null, string type = "all", List<string> userIds = null, List<string> userLogins = null, string accessToken = null)
public Task<GetStreamsResponse> GetStreamsAsync(string after = null, ICollection<string> communityIds = null, int first = 20, ICollection<string> gameIds = null, ICollection<string> languages = null, string type = "all", ICollection<string> userIds = null, ICollection<string> userLogins = null, string accessToken = null)
{
var getParams = new List<KeyValuePair<string, string>>
{
Expand Down Expand Up @@ -76,7 +76,7 @@ public Task<GetStreamTagsResponse> GetStreamTagsAsync(string broadcasterId, stri
return TwitchGetGenericAsync<GetStreamTagsResponse>("/streams/tags", ApiVersion.Helix, getParams, accessToken);
}

public Task ReplaceStreamTagsAsync(string broadcasterId, List<string> tagIds = null, string accessToken = null)
public Task ReplaceStreamTagsAsync(string broadcasterId, ICollection<string> tagIds = null, string accessToken = null)
{
var getParams = new List<KeyValuePair<string, string>>();
getParams.Add(new KeyValuePair<string, string>("broadcaster_id", broadcasterId));
Expand Down
2 changes: 1 addition & 1 deletion TwitchLib.Api.Helix/Subscriptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Task<CheckUserSubscriptionResponse> CheckUserSubscriptionAsync(string bro
return TwitchGetGenericAsync<CheckUserSubscriptionResponse>("/subscriptions/user", ApiVersion.Helix, getParams, accessToken);
}

public Task<GetUserSubscriptionsResponse> GetUserSubscriptionsAsync(string broadcasterId, List<string> userIds, string accessToken = null)
public Task<GetUserSubscriptionsResponse> GetUserSubscriptionsAsync(string broadcasterId, ICollection<string> userIds, string accessToken = null)
{
if (string.IsNullOrEmpty(broadcasterId))
{
Expand Down
2 changes: 1 addition & 1 deletion TwitchLib.Api.Helix/Users.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Task UnblockUserAsync(string targetUserId, string accessToken = null)
return TwitchDeleteAsync("/user/blocks", ApiVersion.Helix, getParams, accessToken);
}

public Task<GetUsersResponse> GetUsersAsync(List<string> ids = null, List<string> logins = null, string accessToken = null)
public Task<GetUsersResponse> GetUsersAsync(ICollection<string> ids = null, ICollection<string> logins = null, string accessToken = null)
{
var getParams = new List<KeyValuePair<string, string>>();
if (ids != null && ids.Count > 0)
Expand Down
2 changes: 1 addition & 1 deletion TwitchLib.Api.Helix/Videos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public Task<DeleteVideosResponse> DeleteVideosAsync(List<string> videoIds, strin
return TwitchDeleteGenericAsync<DeleteVideosResponse>("/videos", ApiVersion.Helix, getParams, accessToken);
}

public Task<GetVideosResponse> GetVideosAsync(List<string> videoIds = null, string userId = null, string gameId = null, string after = null, string before = null, int first = 20, string language = null, Period period = Period.All, VideoSort sort = VideoSort.Time, VideoType type = VideoType.All, string accessToken = null)
public Task<GetVideosResponse> GetVideosAsync(ICollection<string> videoIds = null, string userId = null, string gameId = null, string after = null, string before = null, int first = 20, string language = null, Period period = Period.All, VideoSort sort = VideoSort.Time, VideoType type = VideoType.All, string accessToken = null)
{
if ((videoIds == null || videoIds.Count == 0) && userId == null && gameId == null)
throw new BadParameterException("VideoIds, userId, and gameId cannot all be null/empty.");
Expand Down
2 changes: 1 addition & 1 deletion TwitchLib.Api/Events/OnUserAuthorizationDetectedArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace TwitchLib.Api.Events
public class OnUserAuthorizationDetectedArgs
{
public string Id { get; set; }
public List<AuthScopes> Scopes { get; set; }
public IList<AuthScopes> Scopes { get; set; }
public string Username { get; set; }
public string Token { get; set; }
public string Refresh { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions TwitchLib.Api/Services/ApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ApiService
/// <summary>
/// The list with channels to monitor.
/// </summary>
public List<string> ChannelsToMonitor { get; private set; }
public IList<string> ChannelsToMonitor { get; private set; }
/// <summary>
/// How often the service is being updated in seconds.
/// </summary>
Expand Down Expand Up @@ -100,17 +100,17 @@ public virtual void Stop()
/// <exception cref="ArgumentNullException">When <paramref name="channelsToMonitor"/> is null.</exception>
/// <exception cref="ArgumentException">When <paramref name="channelsToMonitor"/> is empty.</exception>
/// <param name="channelsToMonitor">The channels to monitor.</param>
protected virtual void SetChannels(List<string> channelsToMonitor)
protected virtual void SetChannels(ICollection<string> channelsToMonitor)
{
if (channelsToMonitor == null)
throw new ArgumentNullException(nameof(channelsToMonitor));

if (channelsToMonitor.Count == 0)
throw new ArgumentException("The provided list is empty.", nameof(channelsToMonitor));

ChannelsToMonitor = channelsToMonitor;
ChannelsToMonitor = new List<string>(channelsToMonitor);

OnChannelsSet?.Invoke(this, new OnChannelsSetArgs {Channels = channelsToMonitor});
OnChannelsSet?.Invoke(this, new OnChannelsSetArgs {Channels = ChannelsToMonitor});
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal abstract class CoreMonitor
{
protected readonly ITwitchAPI _api;

public abstract Task<GetStreamsResponse> GetStreamsAsync(List<string> channels, string accessToken = null);
public abstract Task<GetStreamsResponse> GetStreamsAsync(ICollection<string> channels, string accessToken = null);
public abstract Task<Func<Stream, bool>> CompareStream(string channel, string accessToken = null);

protected CoreMonitor(ITwitchAPI api)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override Task<Func<Stream, bool>> CompareStream(string channel, string ac
return Task.FromResult(new Func<Stream, bool>(stream => stream.UserId == channel));
}

public override Task<GetStreamsResponse> GetStreamsAsync(List<string> channels, string accessToken = null)
public override Task<GetStreamsResponse> GetStreamsAsync(ICollection<string> channels, string accessToken = null)
{
return _api.Helix.Streams.GetStreamsAsync(first: channels.Count, userIds: channels, accessToken: accessToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override async Task<Func<Stream, bool>> CompareStream(string channel, str
return stream => stream.UserId == channelId;
}

public override Task<GetStreamsResponse> GetStreamsAsync(List<string> channels, string accessToken = null)
public override Task<GetStreamsResponse> GetStreamsAsync(ICollection<string> channels, string accessToken = null)
{
return _api.Helix.Streams.GetStreamsAsync(first: channels.Count, userLogins: channels, accessToken: accessToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class OnNewFollowersDetectedArgs : EventArgs
/// <summary>Event property representing channel the service is currently monitoring.</summary>
public string Channel;
/// <summary>Event property representing all new followers detected.</summary>
public List<Follow> NewFollowers;
public IList<Follow> NewFollowers;
}
}
2 changes: 1 addition & 1 deletion TwitchLib.Api/Services/Events/OnChannelsSetArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public class OnChannelsSetArgs : EventArgs
/// <summary>
/// The channels the service is currently monitoring.
/// </summary>
public List<string> Channels;
public IList<string> Channels;
}
}
Loading