/// <summary>Adds a <see cref="TraktShow" />, which will be added to the ratings post.</summary> /// <param name="show">The Trakt show, which will be added.</param> /// <param name="seasons"> /// An <see cref="PostRatingsSeasons" /> instance, containing season and episode numbers.<para /> /// If it contains episode numbers, only the episodes with the given episode numbers will be added to the ratings. /// </param> /// <returns>The current <see cref="TraktSyncRatingsPostBuilder" /> instance.</returns> /// <exception cref="ArgumentNullException"> /// Thrown, if the given show is null. /// Thrown, if the given show ids are null. /// </exception> /// <exception cref="ArgumentException"> /// Thrown, if the given show has no valid ids set. /// Thrown, if the given show has an year set, which has more or less than four digits. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// Thrown, if at least one of the given season numbers in <paramref name="seasons" /> is below zero. /// Thrown, if at least one of the given episode numbers in <paramref name="seasons" /> is below zero. /// </exception> public TraktSyncRatingsPostBuilder AddShow(TraktShow show, PostRatingsSeasons seasons) { ValidateShow(show); if (seasons == null) { throw new ArgumentNullException(nameof(seasons)); } EnsureShowsListExists(); var showSeasons = CreateShowSeasons(seasons); CreateOrSetShow(show, showSeasons); return(this); }
/// <summary>Adds a <see cref="ITraktShow" />, which will be added to the ratings post.</summary> /// <param name="show">The Trakt show, which will be added.</param> /// <param name="rating">A rating from 1 to 10 for the given show.</param> /// <param name="ratedAt">The datetime, when the given show was rated. Will be converted to the Trakt UTC-datetime and -format.</param> /// <param name="seasons"> /// An <see cref="PostRatingsSeasons" /> instance, containing season and episode numbers.<para /> /// If it contains episode numbers, only the episodes with the given episode numbers will be added to the ratings. /// </param> /// <returns>The current <see cref="TraktSyncRatingsPostBuilder" /> instance.</returns> /// <exception cref="ArgumentNullException"> /// Thrown, if the given show is null. /// Thrown, if the given show ids are null. /// </exception> /// <exception cref="ArgumentException"> /// Thrown, if the given show has no valid ids set. /// Thrown, if the given show has an year set, which has more or less than four digits. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// Thrown, if at least one of the given season numbers in <paramref name="seasons" /> is below zero. /// Thrown, if at least one of the given episode numbers in <paramref name="seasons" /> is below zero. /// Thrown, if the given rating is not between 1 and 10. /// </exception> public TraktSyncRatingsPostBuilder AddShowWithRating(ITraktShow show, int rating, DateTime ratedAt, PostRatingsSeasons seasons) { ValidateShow(show); ValidateRating(rating); if (seasons == null) { throw new ArgumentNullException(nameof(seasons)); } EnsureShowsListExists(); var showSeasons = CreateShowSeasons(seasons); CreateOrSetShow(show, showSeasons, rating, ratedAt); return(this); }
private IEnumerable <ITraktSyncRatingsPostShowSeason> CreateSyncRatingsPostShowSeasons(PostRatingsSeasons seasons) { var syncRatingsPostShowSeasons = new List <ITraktSyncRatingsPostShowSeason>(); foreach (PostRatingsSeason season in seasons) { var syncRatingsPostShowSeason = new TraktSyncRatingsPostShowSeason { Number = season.Number }; if (season.Rating.HasValue) { syncRatingsPostShowSeason.Rating = season.Rating.Value; } if (season.RatedAt.HasValue) { syncRatingsPostShowSeason.RatedAt = season.RatedAt.Value.ToUniversalTime(); } if (season.Episodes?.Count() > 0) { var syncRatingsPostShowEpisodes = new List <ITraktSyncRatingsPostShowEpisode>(); foreach (PostRatingsEpisode episode in season.Episodes) { var syncRatingsPostShowEpisode = new TraktSyncRatingsPostShowEpisode { Number = episode.Number }; if (episode.Rating.HasValue) { syncRatingsPostShowEpisode.Rating = episode.Rating.Value; } if (episode.RatedAt.HasValue) { syncRatingsPostShowEpisode.RatedAt = episode.RatedAt.Value.ToUniversalTime(); } syncRatingsPostShowEpisodes.Add(syncRatingsPostShowEpisode); } syncRatingsPostShowSeason.Episodes = syncRatingsPostShowEpisodes; } syncRatingsPostShowSeasons.Add(syncRatingsPostShowSeason); } return(syncRatingsPostShowSeasons); }
private ITraktSyncRatingsPostShow CreateSyncRatingsPostShowWithSeasonsCollection(ITraktShow show, int?rating = null, DateTime?ratedAt = null, PostRatingsSeasons seasons = null) { var syncRatingsPostShow = CreateSyncRatingsPostShow(show, rating, ratedAt); if (seasons != null) { syncRatingsPostShow.Seasons = CreateSyncRatingsPostShowSeasons(seasons); } return(syncRatingsPostShow); }
public void Test_TraktPost_SyncRatingsPostBuilder_AddShowAndSeasonsCollection() { ITraktShow show = new TraktShow { Title = "show title", Year = 2020, Ids = new TraktShowIds { Trakt = 1, Slug = "show-title", Imdb = "ttshowtitle", Tmdb = 1, Tvdb = 1, TvRage = 1 } }; var seasons = new PostRatingsSeasons { 1, { 2, new PostRatingsEpisodes { 1, 2 } } }; ITraktSyncRatingsPost syncRatingsPost = TraktPost.NewSyncRatingsPost() .AddShowAndSeasonsCollection(show).WithSeasons(seasons) .Build(); syncRatingsPost.Should().NotBeNull(); syncRatingsPost.Shows.Should().NotBeNull().And.HaveCount(1); ITraktSyncRatingsPostShow postShow = syncRatingsPost.Shows.ToArray()[0]; postShow.Title = "show title"; postShow.Year = 2020; postShow.Ids.Should().NotBeNull(); postShow.Ids.Trakt.Should().Be(1U); postShow.Ids.Slug.Should().Be("show-title"); postShow.Ids.Imdb.Should().Be("ttshowtitle"); postShow.Ids.Tmdb.Should().Be(1U); postShow.Ids.Tvdb.Should().Be(1U); postShow.Ids.TvRage.Should().Be(1U); postShow.Rating.Should().BeNull(); postShow.RatedAt.Should().BeNull(); postShow.Seasons.Should().NotBeNull().And.HaveCount(2); ITraktSyncRatingsPostShowSeason[] showSeasons = postShow.Seasons.ToArray(); showSeasons[0].Number.Should().Be(1); showSeasons[0].Episodes.Should().BeNull(); showSeasons[1].Number.Should().Be(2); showSeasons[1].Episodes.Should().NotBeNull().And.HaveCount(2); ITraktSyncRatingsPostShowEpisode[] showSeasonEpisodes = showSeasons[1].Episodes.ToArray(); showSeasonEpisodes[0].Number.Should().Be(1); showSeasonEpisodes[1].Number.Should().Be(2); syncRatingsPost.Movies.Should().NotBeNull().And.BeEmpty(); syncRatingsPost.Episodes.Should().NotBeNull().And.BeEmpty(); }
private IEnumerable <TraktSyncRatingsPostShowSeason> CreateShowSeasons(PostRatingsSeasons seasons) { var showSeasons = new List <TraktSyncRatingsPostShowSeason>(); foreach (var season in seasons) { if (season.Number < 0) { throw new ArgumentOutOfRangeException("at least one season number not valid", nameof(season)); } var showSingleSeason = new TraktSyncRatingsPostShowSeason { Number = season.Number }; if (season.Rating.HasValue) { showSingleSeason.Rating = season.Rating; } if (season.RatedAt.HasValue) { showSingleSeason.RatedAt = season.RatedAt.Value.ToUniversalTime(); } if (season.Episodes != null && season.Episodes.Count() > 0) { var showEpisodes = new List <TraktSyncRatingsPostShowEpisode>(); foreach (var episode in season.Episodes) { if (episode.Number < 0) { throw new ArgumentOutOfRangeException("at least one episode number not valid", nameof(seasons)); } var showEpisode = new TraktSyncRatingsPostShowEpisode { Number = episode.Number }; if (episode.Rating.HasValue) { showEpisode.Rating = episode.Rating; } if (episode.RatedAt.HasValue) { showEpisode.RatedAt = episode.RatedAt.Value.ToUniversalTime(); } showEpisodes.Add(showEpisode); } showSingleSeason.Episodes = showEpisodes; } showSeasons.Add(showSingleSeason); } return(showSeasons); }