Skip to content

Commit

Permalink
Merge pull request #550 from henrikfroehling/epic/release-1.4.0/GH-502
Browse files Browse the repository at this point in the history
Resolves GH-502
  • Loading branch information
henrikfroehling authored Jul 7, 2023
2 parents fa8f8d8 + f1e97d6 commit 9f0395d
Show file tree
Hide file tree
Showing 60 changed files with 4,648 additions and 632 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ jobs:
path: 'release/'

- name: Push NuGet package to Github Package Registry
if: ${{ !contains(github.ref, 'pull') && github.actor != 'dependabot[bot]' }}
if: ${{ !contains(github.ref, 'pull') && !contains(github.ref, 'epic') && github.actor != 'dependabot[bot]' }}
run: dotnet nuget push '**/Trakt.NET*.nupkg'
working-directory: 'Source'

docs:
needs: [environment-check]
if: ${{ !contains(github.ref, 'pull') && github.actor != 'dependabot[bot]' }}
if: ${{ !contains(github.ref, 'pull') && !contains(github.ref, 'epic') && github.actor != 'dependabot[bot]' }}
runs-on: windows-latest
permissions:
contents: write
Expand Down
60 changes: 40 additions & 20 deletions Source/Lib/Trakt.NET/Modules/TraktCommentsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,23 @@ internal TraktCommentsModule(TraktClient client) : base(client)
/// <para>
/// See <a href="http://docs.trakt.apiary.io/#reference/comments/comment/get-a-comment-or-reply">"Trakt API Doc - Comments: Comment"</a> for more information.
/// </para>
/// <para>See also <seealso cref="GetMutlipleCommentsAsync(uint[], CancellationToken)" />.</para>
/// <para>See also <seealso cref="GetMutlipleCommentsAsync(TraktMultipleCommentsQueryParams, CancellationToken)" />.</para>
/// </summary>
/// <param name="commentId">The comment's id.</param>
/// <param name="extendedInfo">
/// The extended info, which determines how much data about the comment's media item should be queried.
/// See also <seealso cref="TraktExtendedInfo" />.
/// </param>
/// <param name="cancellationToken">
/// Propagates notification that the request should be canceled.<para/>
/// If provided, the exception <see cref="OperationCanceledException" /> should be catched.
/// </param>
/// <returns>An <see cref="ITraktComment" /> instance with the queried comment's data.</returns>
/// <exception cref="TraktException">Thrown, if the request fails.</exception>
/// <exception cref="TraktRequestValidationException">Thrown, if validation of request data fails.</exception>
public Task<TraktResponse<ITraktComment>> GetCommentAsync(uint commentId, CancellationToken cancellationToken = default)
=> GetCommentImplementationAsync(false, commentId, cancellationToken);
public Task<TraktResponse<ITraktComment>> GetCommentAsync(uint commentId, TraktExtendedInfo extendedInfo = null,
CancellationToken cancellationToken = default)
=> GetCommentImplementationAsync(false, commentId, extendedInfo, cancellationToken);

/// <summary>
/// Gets the attached media <see cref="ITraktCommentItem" /> from a comment with the given id.
Expand Down Expand Up @@ -135,9 +140,9 @@ public Task<TraktPagedResponse<ITraktCommentLike>> GetCommentLikesAsync(uint com
/// <para>
/// See <a href="http://docs.trakt.apiary.io/#reference/comments/comment/get-a-comment-or-reply">"Trakt API Doc - Comments: Comment"</a> for more information.
/// </para>
/// <para>See also <seealso cref="GetCommentAsync(uint, CancellationToken)" />.</para>
/// <para>See also <seealso cref="GetCommentAsync(uint, TraktExtendedInfo, CancellationToken)" />.</para>
/// </summary>
/// <param name="commentIds">An array of comment ids.</param>
/// <param name="commentsQueryParams">A list of comment ids and optional extended infos. See also <seealso cref="TraktMultipleCommentsQueryParams" />.</param>
/// <param name="cancellationToken">
/// Propagates notification that the request should be canceled.<para/>
/// If provided, the exception <see cref="OperationCanceledException" /> should be catched.
Expand All @@ -146,16 +151,17 @@ public Task<TraktPagedResponse<ITraktCommentLike>> GetCommentLikesAsync(uint com
/// <exception cref="TraktException">Thrown, if one request fails.</exception>
/// <exception cref="TraktRequestValidationException">Thrown, if validation of request data fails.</exception>
[Obsolete("GetMutlipleCommentsAsync is deprecated, please use GetCommentsStreamAsync instead.")]
public async Task<IEnumerable<TraktResponse<ITraktComment>>> GetMutlipleCommentsAsync(uint[] commentIds, CancellationToken cancellationToken = default)
public async Task<IEnumerable<TraktResponse<ITraktComment>>> GetMutlipleCommentsAsync(TraktMultipleCommentsQueryParams commentsQueryParams,
CancellationToken cancellationToken = default)
{
if (commentIds == null || commentIds.Length == 0)
if (commentsQueryParams == null || commentsQueryParams.Count == 0)
return new List<TraktResponse<ITraktComment>>();

var tasks = new List<Task<TraktResponse<ITraktComment>>>();

for (int i = 0; i < commentIds.Length; i++)
foreach (TraktCommentQueryParams queryParam in commentsQueryParams)
{
Task<TraktResponse<ITraktComment>> task = GetCommentAsync(commentIds[i], cancellationToken);
Task<TraktResponse<ITraktComment>> task = GetCommentAsync(queryParam.CommentId, queryParam.ExtendedInfo, cancellationToken);
tasks.Add(task);
}

Expand All @@ -169,26 +175,27 @@ public async Task<IEnumerable<TraktResponse<ITraktComment>>> GetMutlipleComments
/// <para>
/// See <a href="http://docs.trakt.apiary.io/#reference/comments/comment/get-a-comment-or-reply">"Trakt API Doc - Comments: Comment"</a> for more information.
/// </para>
/// <para>See also <seealso cref="GetCommentAsync(uint, CancellationToken)" />.</para>
/// <para>See also <seealso cref="GetCommentAsync(uint, TraktExtendedInfo, CancellationToken)" />.</para>
/// </summary>
/// <param name="commentIds">A list of comment ids.</param>
/// <param name="commentsQueryParams">A list of comment ids and optional extended infos. See also <seealso cref="TraktMultipleCommentsQueryParams" />.</param>
/// <param name="cancellationToken">
/// Propagates notification that the request should be canceled.<para/>
/// If provided, the exception <see cref="OperationCanceledException" /> should be catched.
/// </param>
/// <returns>An <a href="https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.iasyncenumerable-1?view=net-7.0">async stream</a> of <see cref="ITraktComment" /> instances with the data of each queried comment.</returns>
/// <exception cref="TraktException">Thrown, if one request fails.</exception>
/// <exception cref="TraktRequestValidationException">Thrown, if validation of request data fails.</exception>
public async IAsyncEnumerable<TraktResponse<ITraktComment>> GetCommentsStreamAsync(IEnumerable<uint> commentIds, [EnumeratorCancellation] CancellationToken cancellationToken = default)
public async IAsyncEnumerable<TraktResponse<ITraktComment>> GetCommentsStreamAsync(TraktMultipleCommentsQueryParams commentsQueryParams,
[EnumeratorCancellation] CancellationToken cancellationToken = default)
{
if (commentIds == null || !commentIds.Any())
if (commentsQueryParams == null || commentsQueryParams.Count == 0)
yield break;

var tasks = new List<Task<TraktResponse<ITraktComment>>>();

foreach (var commentId in commentIds)
foreach (TraktCommentQueryParams queryParam in commentsQueryParams)
{
Task<TraktResponse<ITraktComment>> task = GetCommentInStreamAsync(commentId, cancellationToken);
Task<TraktResponse<ITraktComment>> task = GetCommentInStreamAsync(queryParam.CommentId, queryParam.ExtendedInfo, cancellationToken);
tasks.Add(task);
}

Expand Down Expand Up @@ -657,6 +664,10 @@ public Task<TraktNoContentResponse> UnlikeCommentAsync(uint commentId, Cancellat
/// </para>
/// </summary>
/// <param name="commentId">The id of the comment, for which the replies should be queried.</param>
/// <param name="extendedInfo">
/// The extended info, which determines how much data about the comment's media item should be queried.
/// See also <seealso cref="TraktExtendedInfo" />.
/// </param>
/// <param name="pagedParameters">Specifies pagination parameters. <see cref="TraktPagedParameters" />.</param>
/// <param name="cancellationToken">
/// Propagates notification that the request should be canceled.<para/>
Expand All @@ -671,26 +682,35 @@ public Task<TraktNoContentResponse> UnlikeCommentAsync(uint commentId, Cancellat
/// </returns>
/// <exception cref="TraktException">Thrown, if the request fails.</exception>
/// <exception cref="TraktRequestValidationException">Thrown, if validation of request data fails.</exception>
public Task<TraktPagedResponse<ITraktComment>> GetCommentRepliesAsync(uint commentId, TraktPagedParameters pagedParameters = null,
public Task<TraktPagedResponse<ITraktComment>> GetCommentRepliesAsync(uint commentId, TraktExtendedInfo extendedInfo = null,
TraktPagedParameters pagedParameters = null,
CancellationToken cancellationToken = default)
{
var request = new CommentRepliesRequest
{
Id = commentId.ToString(),
ExtendedInfo = extendedInfo,
Page = pagedParameters?.Page,
Limit = pagedParameters?.Limit,
};

return RequestHandler.ExecutePagedRequestAsync(Client, request, cancellationToken);
}

private Task<TraktResponse<ITraktComment>> GetCommentInStreamAsync(uint commentId, CancellationToken cancellationToken = default)
=> GetCommentImplementationAsync(true, commentId, cancellationToken);
private Task<TraktResponse<ITraktComment>> GetCommentInStreamAsync(uint commentId, TraktExtendedInfo extendedInfo = null,
CancellationToken cancellationToken = default)
=> GetCommentImplementationAsync(true, commentId, extendedInfo, cancellationToken);

private Task<TraktResponse<ITraktComment>> GetCommentImplementationAsync(bool asyncStream, uint commentId, CancellationToken cancellationToken = default)
private Task<TraktResponse<ITraktComment>> GetCommentImplementationAsync(bool asyncStream, uint commentId,
TraktExtendedInfo extendedInfo = null,
CancellationToken cancellationToken = default)
{
var requestHandler = new RequestHandler(Client);
var request = new CommentSummaryRequest { Id = commentId.ToString() };
var request = new CommentSummaryRequest
{
Id = commentId.ToString(),
ExtendedInfo = extendedInfo
};

if (asyncStream)
return requestHandler.ExecuteSingleItemStreamRequestAsync(request, cancellationToken);
Expand Down
12 changes: 12 additions & 0 deletions Source/Lib/Trakt.NET/Modules/TraktEpisodesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ public async IAsyncEnumerable<TraktResponse<ITraktEpisode>> GetEpisodesStreamAsy
/// <param name="seasonNumber">The number of the season containing the episode, for which the comments should be queried.</param>
/// <param name="episodeNumber">The number of the episode, for which the comments should be queried.</param>
/// <param name="commentSortOrder">The comments sort order. See also <seealso cref="TraktExtendedCommentSortOrder" />.</param>
/// <param name="extendedInfo">
/// The extended info, which determines how much data about a comment's media item should be queried.
/// See also <seealso cref="TraktExtendedInfo" />.
/// </param>
/// <param name="pagedParameters">Specifies pagination parameters. <see cref="TraktPagedParameters" />.</param>
/// <param name="cancellationToken">
/// Propagates notification that the request should be canceled.<para/>
Expand All @@ -158,6 +162,7 @@ public async IAsyncEnumerable<TraktResponse<ITraktEpisode>> GetEpisodesStreamAsy
/// <exception cref="TraktRequestValidationException">Thrown, if validation of request data fails.</exception>
public Task<TraktPagedResponse<ITraktComment>> GetEpisodeCommentsAsync(string showIdOrSlug, uint seasonNumber, uint episodeNumber,
TraktExtendedCommentSortOrder commentSortOrder = null,
TraktExtendedInfo extendedInfo = null,
TraktPagedParameters pagedParameters = null,
CancellationToken cancellationToken = default)
{
Expand All @@ -167,6 +172,7 @@ public Task<TraktPagedResponse<ITraktComment>> GetEpisodeCommentsAsync(string sh
SeasonNumber = seasonNumber,
EpisodeNumber = episodeNumber,
SortOrder = commentSortOrder,
ExtendedInfo = extendedInfo,
Page = pagedParameters?.Page,
Limit = pagedParameters?.Limit
};
Expand All @@ -186,6 +192,10 @@ public Task<TraktPagedResponse<ITraktComment>> GetEpisodeCommentsAsync(string sh
/// <param name="episodeNumber">The number of the episode, for which the lists should be queried.</param>
/// <param name="listType">The type of lists, that should be queried. Defaults to personal lists.</param>
/// <param name="listSortOrder">The list sort order. See also <seealso cref="TraktListSortOrder" />. Defaults to sorted by popularity.</param>
/// <param name="extendedInfo">
/// The extended info, which determines how much data about the list items should be queried.
/// See also <seealso cref="TraktExtendedInfo" />.
/// </param>
/// <param name="pagedParameters">Specifies pagination parameters. <see cref="TraktPagedParameters" />.</param>
/// <param name="cancellationToken">
/// Propagates notification that the request should be canceled.<para/>
Expand All @@ -202,6 +212,7 @@ public Task<TraktPagedResponse<ITraktComment>> GetEpisodeCommentsAsync(string sh
/// <exception cref="TraktRequestValidationException">Thrown, if validation of request data fails.</exception>
public Task<TraktPagedResponse<ITraktList>> GetEpisodeListsAsync(string showIdOrSlug, uint seasonNumber, uint episodeNumber,
TraktListType listType = null, TraktListSortOrder listSortOrder = null,
TraktExtendedInfo extendedInfo = null,
TraktPagedParameters pagedParameters = null,
CancellationToken cancellationToken = default)
{
Expand All @@ -212,6 +223,7 @@ public Task<TraktPagedResponse<ITraktList>> GetEpisodeListsAsync(string showIdOr
EpisodeNumber = episodeNumber,
Type = listType,
SortOrder = listSortOrder,
ExtendedInfo = extendedInfo,
Page = pagedParameters?.Page,
Limit = pagedParameters?.Limit
};
Expand Down
Loading

0 comments on commit 9f0395d

Please sign in to comment.