Skip to content

Commit

Permalink
GH-376: Use ITraktSyncRecommendationsRemovePost instead of `ITraktS…
Browse files Browse the repository at this point in the history
…yncRecommendationsPost`
  • Loading branch information
henrikfroehling committed Apr 2, 2023
1 parent a9373b1 commit a744a37
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 9 deletions.
12 changes: 6 additions & 6 deletions Source/Lib/Trakt.NET/Modules/TraktSyncModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -645,12 +645,12 @@ public Task<TraktNoContentResponse> RemovePlaybackItemAsync(uint playbackId, Can
/// See <a href="https://trakt.docs.apiary.io/#reference/sync/remove-from-personal-recommendations/remove-items-from-personal-recommendations">"Trakt API Doc - Sync: Remove from Personal Recommendations"</a> for more information.
/// </para>
/// <para>
/// It is recommended to use the <see cref="ITraktSyncRecommendationsPostBuilder" /> to create an instance
/// of the required <see cref="ITraktSyncRecommendationsPost" />.
/// See also <seealso cref="TraktPost.NewSyncRecommendationsPost()" />.
/// It is recommended to use the <see cref="ITraktSyncRecommendationsRemovePostBuilder" /> to create an instance
/// of the required <see cref="ITraktSyncRecommendationsRemovePost" />.
/// See also <seealso cref="TraktPost.NewSyncRecommendationsRemovePost()" />.
/// </para>
/// </summary>
/// <param name="recommendationsPost">An <see cref="ITraktSyncRecommendationsPost" /> instance containing all movies and shows, which should be removed.</param>
/// <param name="recommendationsRemovePost">An <see cref="ITraktSyncRecommendationsRemovePost" /> instance containing all movies and shows, which should be removed.</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 @@ -659,14 +659,14 @@ public Task<TraktNoContentResponse> RemovePlaybackItemAsync(uint playbackId, Can
/// <exception cref="TraktException">Thrown, if the request fails.</exception>
/// <exception cref="TraktPostValidationException">Thrown, if validation of post data fails.</exception>
/// <exception cref="TraktRequestValidationException">Thrown, if validation of request data fails.</exception>
public Task<TraktResponse<ITraktSyncRecommendationsRemovePostResponse>> RemovePersonalRecommendationsAsync(ITraktSyncRecommendationsPost recommendationsPost,
public Task<TraktResponse<ITraktSyncRecommendationsRemovePostResponse>> RemovePersonalRecommendationsAsync(ITraktSyncRecommendationsRemovePost recommendationsRemovePost,
CancellationToken cancellationToken = default)
{
var requestHandler = new RequestHandler(Client);

return requestHandler.ExecuteSingleItemRequestAsync(new SyncRecommendationsRemoveRequest
{
RequestBody = recommendationsPost
RequestBody = recommendationsRemovePost
},
cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Objects.Post.Syncs.Recommendations;
using Objects.Post.Syncs.Recommendations.Responses;

internal class SyncRecommendationsRemoveRequest : ASyncPostRequest<ITraktSyncRecommendationsRemovePostResponse, ITraktSyncRecommendationsPost>
internal class SyncRecommendationsRemoveRequest : ASyncPostRequest<ITraktSyncRecommendationsRemovePostResponse, ITraktSyncRecommendationsRemovePost>
{
public override string UriTemplate => "sync/recommendations/remove";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task Test_TraktSyncModule_RemovePersonalRecommendations()
postJson.Should().NotBeNullOrEmpty();

TraktClient client = TestUtility.GetOAuthMockClient(REMOVE_RECOMMENDATIONS_URI, postJson, RECOMMENDATIONS_REMOVE_POST_RESPONSE_JSON);
TraktResponse<ITraktSyncRecommendationsRemovePostResponse> response = await client.Sync.RemovePersonalRecommendationsAsync(RecommendationsPost);
TraktResponse<ITraktSyncRecommendationsRemovePostResponse> response = await client.Sync.RemovePersonalRecommendationsAsync(RemoveRecommendationsPost);

response.Should().NotBeNull();
response.IsSuccess.Should().BeTrue();
Expand Down Expand Up @@ -87,7 +87,7 @@ public async Task Test_TraktSyncModule_RemovePersonalRecommendations_Throws_API_

try
{
await client.Sync.RemovePersonalRecommendationsAsync(RecommendationsPost);
await client.Sync.RemovePersonalRecommendationsAsync(RemoveRecommendationsPost);
Assert.False(true);
}
catch (Exception exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public partial class TraktSyncModule_Tests
private ITraktSyncCollectionPost AddCollectionItemsPost { get; }
private ITraktSyncRatingsPost AddRatingsPost { get; }
private ITraktSyncRecommendationsPost RecommendationsPost { get; }
private ITraktSyncRecommendationsRemovePost RemoveRecommendationsPost { get; }
private ITraktSyncHistoryPost AddHistoryPost { get; }
private ITraktSyncWatchlistPost AddWatchlistPost { get; }
private ITraktSyncCollectionRemovePost RemoveCollectionItemsPost { get; }
Expand All @@ -28,6 +29,7 @@ public TraktSyncModule_Tests()
AddCollectionItemsPost = SetupAddCollectionItemsPost();
AddRatingsPost = SetupAddRatingsPost();
RecommendationsPost = SetupAddRecommendationsPost();
RemoveRecommendationsPost = SetupAddRecommendationsRemovePost();
AddHistoryPost = SetupAddHistoryPost();
AddWatchlistPost = SetupAddWatchlistPost();
RemoveCollectionItemsPost = SetupRemoveCollectionItemsPost();
Expand Down Expand Up @@ -331,6 +333,66 @@ private ITraktSyncRecommendationsPost SetupAddRecommendationsPost()
};
}

private ITraktSyncRecommendationsRemovePost SetupAddRecommendationsRemovePost()
{
return new TraktSyncRecommendationsRemovePost
{
Movies = new List<ITraktSyncRecommendationsPostMovie>
{
new TraktSyncRecommendationsPostMovie
{
Title = "Batman Begins",
Year = 2005,
Ids = new TraktMovieIds
{
Trakt = 1,
Slug = "batman-begins-2005",
Imdb = "tt0372784",
Tmdb = 272
},
Notes = "One of Chritian Bale's most iconic roles."
},
new TraktSyncRecommendationsPostMovie
{
Ids = new TraktMovieIds
{
Imdb = "tt0000111"
}
}
},
Shows = new List<ITraktSyncRecommendationsPostShow>
{
new TraktSyncRecommendationsPostShow
{
Title = "Breaking Bad",
Year = 2008,
Ids = new TraktShowIds
{
Trakt = 1,
Slug = "breaking-bad",
Tvdb = 81189,
Imdb = "tt0903747",
Tmdb = 1396
},
Notes = "I AM THE DANGER!"
},
new TraktSyncRecommendationsPostShow
{
Title = "The Walking Dead",
Year = 2010,
Ids = new TraktShowIds
{
Trakt = 2,
Slug = "the-walking-dead",
Tvdb = 153021,
Imdb = "tt1520211",
Tmdb = 1402
}
}
}
};
}

private ITraktSyncHistoryPost SetupAddHistoryPost()
{
return new TraktSyncHistoryPost
Expand Down

0 comments on commit a744a37

Please sign in to comment.