/// <summary>Adds a <see cref="ITraktShow" />, which will be added to the history post.</summary> /// <param name="show">The Trakt show, which will be added.</param> /// <param name="seasons"> /// An <see cref="PostHistorySeasons" /> 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 history. /// </param> /// <returns>The current <see cref="TraktSyncHistoryPostBuilder" /> 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 TraktSyncHistoryPostBuilder AddShow(ITraktShow show, PostHistorySeasons 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 watchlist post.</summary> /// <param name="show">The Trakt show, which will be added.</param> /// <param name="seasons"> /// An array of season numbers for seasons in the given show. /// All seasons numbers will be added to the ratings. /// </param> /// <returns>The current <see cref="TraktSyncWatchlistPostBuilder" /> instance.</returns> /// <exception cref="ArgumentNullException"> /// Thrown, if the given show is null. /// Thrown, if the given show ids are null. /// Thrown, if the given seasons array is 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 is below zero. /// </exception> public TraktSyncWatchlistPostBuilder AddShow(ITraktShow show, int[] seasons) { ValidateShow(show); EnsureShowsListExists(); if (seasons == null) { throw new ArgumentNullException(nameof(seasons)); } var showSeasons = new List <ITraktSyncWatchlistPostShowSeason>(); for (int i = 0; i < seasons.Length; i++) { if (seasons[i] < 0) { throw new ArgumentOutOfRangeException("at least one season number not valid"); } showSeasons.Add(new TraktSyncWatchlistPostShowSeason { Number = seasons[i] }); } var existingShow = _watchlistPost.Shows.FirstOrDefault(s => s.Ids == show.Ids); if (existingShow != null) { existingShow.Seasons = showSeasons; } else { var watchlistShow = new TraktSyncWatchlistPostShow { Ids = show.Ids, Title = show.Title, Year = show.Year, Seasons = showSeasons }; (_watchlistPost.Shows as List <ITraktSyncWatchlistPostShow>)?.Add(watchlistShow); } return(this); }
protected TraktSyncHistoryRemovePostBuilder AddShowOrIgnore(ITraktShow show) { if (ContainsShow(show)) { return(this); } var historyShow = new TraktSyncHistoryPostShow { Ids = show.Ids, Title = show.Title, Year = show.Year }; (_historyPost.Shows as List <ITraktSyncHistoryPostShow>)?.Add(historyShow); 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="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, PostRatingsSeasons seasons) { ValidateShow(show); ValidateRating(rating); if (seasons == null) { throw new ArgumentNullException(nameof(seasons)); } EnsureShowsListExists(); var showSeasons = CreateShowSeasons(seasons); CreateOrSetShow(show, showSeasons, rating); return(this); }
public TraktUserHiddenItemsPostBuilder AddShow(ITraktShow show, int season, params int[] seasons) { ValidateShow(show); EnsureShowsListExists(); var seasonsToAdd = new int[seasons.Length + 1]; seasonsToAdd[0] = season; seasons.CopyTo(seasonsToAdd, 1); var showSeasons = new List <TraktUserHiddenItemsPostShowSeason>(); for (int i = 0; i < seasonsToAdd.Length; i++) { if (seasonsToAdd[i] < 0) { throw new ArgumentOutOfRangeException("at least one season number not valid"); } showSeasons.Add(new TraktUserHiddenItemsPostShowSeason { Number = seasonsToAdd[i] }); } var existingShow = _hiddenItemsPost.Shows.FirstOrDefault(s => s.Ids == show.Ids); if (existingShow != null) { existingShow.Seasons = showSeasons; } else { (_hiddenItemsPost.Shows as List <TraktUserHiddenItemsPostShow>)?.Add( new TraktUserHiddenItemsPostShow { Title = show.Title, Year = show.Year, Ids = show.Ids, Seasons = showSeasons }); } return(this); }
public async Task Test_TraktShowsModule_GetShow_With_ExtendedInfo() { TraktClient client = TestUtility.GetMockClient($"{GET_SHOW_URI}?extended={EXTENDED_INFO}", SHOW_JSON); TraktResponse <ITraktShow> response = await client.Shows.GetShowAsync(SHOW_ID, EXTENDED_INFO); response.Should().NotBeNull(); response.IsSuccess.Should().BeTrue(); response.HasValue.Should().BeTrue(); response.Value.Should().NotBeNull(); ITraktShow responseValue = response.Value; responseValue.Title.Should().Be("Game of Thrones"); responseValue.Year.Should().Be(2011); responseValue.Airs.Should().NotBeNull(); responseValue.Airs.Day.Should().Be("Sunday"); responseValue.Airs.Time.Should().Be("21:00"); responseValue.Airs.TimeZoneId.Should().Be("America/New_York"); responseValue.AvailableTranslationLanguageCodes.Should().NotBeNull().And.HaveCount(4).And.Contain("en", "fr", "it", "de"); responseValue.Ids.Should().NotBeNull(); responseValue.Ids.Trakt.Should().Be(1390U); responseValue.Ids.Slug.Should().Be("game-of-thrones"); responseValue.Ids.Tvdb.Should().Be(121361U); responseValue.Ids.Imdb.Should().Be("tt0944947"); responseValue.Ids.Tmdb.Should().Be(1399U); responseValue.Ids.TvRage.Should().Be(24493U); responseValue.Genres.Should().NotBeNull().And.HaveCount(5).And.Contain("drama", "fantasy", "science-fiction", "action", "adventure"); responseValue.Seasons.Should().BeNull(); responseValue.Overview.Should().Be("Seven noble families fight for control of the mythical land of Westeros. Friction between the houses leads to full-scale war. All while a very ancient evil awakens in the farthest north. Amidst the war, a neglected military order of misfits, the Night's Watch, is all that stands between the realms of men and the icy horrors beyond."); responseValue.FirstAired.Should().Be(DateTime.Parse("2011-04-17T07:00:00Z").ToUniversalTime()); responseValue.Runtime.Should().Be(60); responseValue.Certification.Should().Be("TV-MA"); responseValue.Network.Should().Be("HBO"); responseValue.CountryCode.Should().Be("us"); responseValue.UpdatedAt.Should().Be(DateTime.Parse("2016-04-06T10:39:11Z").ToUniversalTime()); responseValue.Trailer.Should().Be("http://youtube.com/watch?v=F9Bo89m2f6g"); responseValue.Homepage.Should().Be("http://www.hbo.com/game-of-thrones"); responseValue.Status.Should().Be(TraktShowStatus.ReturningSeries); responseValue.Rating.Should().Be(9.38327f); responseValue.Votes.Should().Be(44773); responseValue.LanguageCode.Should().Be("en"); responseValue.AiredEpisodes.Should().Be(50); }
/// <summary>Adds a <see cref="ITraktShow" />, which will be added to the user custom list items post.</summary> /// <param name="show">The Trakt show, which will be added.</param> /// <returns>The current <see cref="TraktUserCustomListItemsPostBuilder" /> 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> public TraktUserCustomListItemsPostBuilder AddShow(ITraktShow show) { ValidateShow(show); EnsureShowsListExists(); var existingShow = _listItemsPost.Shows.FirstOrDefault(s => s.Ids == show.Ids); if (existingShow != null) { return(this); } (_listItemsPost.Shows as List <ITraktUserCustomListItemsPostShow>)?.Add( new TraktUserCustomListItemsPostShow { Ids = show.Ids }); return(this); }
private ITraktSyncRatingsPostShow CreateSyncRatingsPostShow(ITraktShow show, int?rating = null, DateTime?ratedAt = null) { var syncRatingsPostShow = new TraktSyncRatingsPostShow { Ids = show.Ids, Title = show.Title, Year = show.Year }; if (rating.HasValue) { syncRatingsPostShow.Rating = rating.Value; } if (ratedAt.HasValue) { syncRatingsPostShow.RatedAt = ratedAt.Value.ToUniversalTime(); } return(syncRatingsPostShow); }
protected void CreateOrSetShow(ITraktShow show, IEnumerable <ITraktSyncHistoryPostShowSeason> showSeasons) { var existingShow = _historyPost.Shows.FirstOrDefault(s => s.Ids == show.Ids); if (existingShow != null) { existingShow.Seasons = showSeasons; } else { var historyShow = new TraktSyncHistoryPostShow { Ids = show.Ids, Title = show.Title, Year = show.Year, Seasons = showSeasons }; (_historyPost.Shows as List <ITraktSyncHistoryPostShow>)?.Add(historyShow); } }
public TraktUserHiddenItemsPostBuilder AddShow(ITraktShow show) { ValidateShow(show); EnsureShowsListExists(); var existingShow = _hiddenItemsPost.Shows.FirstOrDefault(s => s.Ids == show.Ids); if (existingShow != null) { return(this); } (_hiddenItemsPost.Shows as List <TraktUserHiddenItemsPostShow>)?.Add( new TraktUserHiddenItemsPostShow { Title = show.Title, Year = show.Year, Ids = show.Ids }); return(this); }
private ITraktSyncCollectionPostShow CreateSyncCollectionPostShow(ITraktShow show, ITraktMetadata metadata = null, DateTime?collectedAt = null) { var syncCollectionPostShow = new TraktSyncCollectionPostShow { Ids = show.Ids, Title = show.Title, Year = show.Year, MediaType = metadata?.MediaType, MediaResolution = metadata?.MediaResolution, Audio = metadata?.Audio, AudioChannels = metadata?.AudioChannels, ThreeDimensional = metadata?.ThreeDimensional, HDR = metadata?.HDR }; if (collectedAt.HasValue) { syncCollectionPostShow.CollectedAt = collectedAt.Value.ToUniversalTime(); } return(syncCollectionPostShow); }
private void ValidateShow(ITraktShow show) { if (show == null) { throw new ArgumentNullException(nameof(show), "show must not be null"); } if (string.IsNullOrEmpty(show.Title)) { throw new ArgumentException("show title not valid", nameof(show.Title)); } if (show.Ids == null) { throw new ArgumentNullException(nameof(show.Ids), "show ids must not be null"); } if (!show.Ids.HasAnyId) { throw new ArgumentException("show ids have no valid id", nameof(show.Ids)); } }
private void ValidateShow(ITraktShow show) { if (show == null) { throw new ArgumentNullException(nameof(show)); } if (show.Ids == null) { throw new ArgumentNullException(nameof(show.Ids)); } if (!show.Ids.HasAnyId) { throw new ArgumentException("no show ids set or valid", nameof(show.Ids)); } if (show.Year.HasValue && show.Year.Value.ToString().Length != 4) { throw new ArgumentException("show year not valid", nameof(show.Year)); } }
/// <summary>Adds a <see cref="ITraktShow" />, which will be added to the watchlist post.</summary> /// <param name="show">The Trakt show, which will be added.</param> /// <returns>The current <see cref="TraktSyncWatchlistPostBuilder" /> 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> public TraktSyncWatchlistPostBuilder AddShow(ITraktShow show) { ValidateShow(show); EnsureShowsListExists(); var existingShow = _watchlistPost.Shows.FirstOrDefault(s => s.Ids == show.Ids); if (existingShow != null) { return(this); } (_watchlistPost.Shows as List <ITraktSyncWatchlistPostShow>)?.Add( new TraktSyncWatchlistPostShow { Ids = show.Ids, Title = show.Title, Year = show.Year }); return(this); }
public async Task Test_TraktShowsModule_GetShow() { TraktClient client = TestUtility.GetMockClient(GET_SHOW_URI, SHOW_JSON); TraktResponse <ITraktShow> response = await client.Shows.GetShowAsync(SHOW_ID); response.Should().NotBeNull(); response.IsSuccess.Should().BeTrue(); response.HasValue.Should().BeTrue(); response.Value.Should().NotBeNull(); ITraktShow responseValue = response.Value; responseValue.Title.Should().Be("Game of Thrones"); responseValue.Year.Should().Be(2011); responseValue.Ids.Should().NotBeNull(); responseValue.Ids.Trakt.Should().Be(1390U); responseValue.Ids.Slug.Should().Be("game-of-thrones"); responseValue.Ids.Tvdb.Should().Be(121361U); responseValue.Ids.Imdb.Should().Be("tt0944947"); responseValue.Ids.Tmdb.Should().Be(1399U); responseValue.Ids.TvRage.Should().Be(24493U); }
protected TraktSyncHistoryPostBuilder AddShowOrIgnore(ITraktShow show, DateTime?watchedAt = null) { if (ContainsShow(show)) { return(this); } var historyShow = new TraktSyncHistoryPostShow { Ids = show.Ids, Title = show.Title, Year = show.Year }; if (watchedAt.HasValue) { historyShow.WatchedAt = watchedAt.Value.ToUniversalTime(); } (_historyPost.Shows as List <ITraktSyncHistoryPostShow>)?.Add(historyShow); return(this); }
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 ITraktPostBuilderShowAddedSeasons <ITraktSyncRatingsPostBuilder, ITraktSyncRatingsPost> AddShowAndSeasons(ITraktShow show) { if (show == null) { throw new ArgumentNullException(nameof(show)); } _showsWithSeasons.SetCurrentShow(show); return(_showsWithSeasons); }
public ITraktPostBuilderShowAddedRatingWithSeasonsCollection <ITraktSyncRatingsPostBuilder, ITraktSyncRatingsPost, PostRatingsSeasons> AddRatedShowAndSeasonsCollection(ITraktShow show) { if (show == null) { throw new ArgumentNullException(nameof(show)); } _ratedShowsWithSeasonsCollection.SetCurrentShow(show); return(_ratedShowsWithSeasonsCollection); }
public void SetCurrentShow(ITraktShow show) { _currentShow = show; }
internal PostBuilderShowAddedWatchedAt(TPostBuilderAddShow postBuilder) { _postBuilder = postBuilder; _currentShow = null; WatchedShows = new List <PostBuilderWatchedObject <ITraktShow> >(); }
/// <summary>Adds a <see cref="ITraktShow" />, which will be added to the watchlist post.</summary> /// <param name="show">The Trakt show, which will be added.</param> /// <param name="seasons"> /// An <see cref="PostSeasons" /> 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 watchlist. /// </param> /// <returns>The current <see cref="TraktSyncWatchlistPostBuilder" /> 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 TraktSyncWatchlistPostBuilder AddShow(ITraktShow show, PostSeasons seasons) { ValidateShow(show); EnsureShowsListExists(); if (_watchlistPost.Shows == null) { _watchlistPost.Shows = new List <ITraktSyncWatchlistPostShow>(); } List <ITraktSyncWatchlistPostShowSeason> showSeasons = null; if (seasons.Any()) { showSeasons = new List <ITraktSyncWatchlistPostShowSeason>(); foreach (PostSeason season in seasons) { if (season.Number < 0) { throw new ArgumentOutOfRangeException("at least one season number not valid", nameof(season)); } var showSingleSeason = new TraktSyncWatchlistPostShowSeason { Number = season.Number }; if (season.Episodes?.Count() > 0) { var showEpisodes = new List <TraktSyncWatchlistPostShowEpisode>(); foreach (PostEpisode episode in season.Episodes) { if (episode.Number < 0) { throw new ArgumentOutOfRangeException("at least one episode number not valid", nameof(seasons)); } showEpisodes.Add(new TraktSyncWatchlistPostShowEpisode { Number = episode.Number }); } showSingleSeason.Episodes = showEpisodes; } showSeasons.Add(showSingleSeason); } } ITraktSyncWatchlistPostShow existingShow = _watchlistPost.Shows.FirstOrDefault(s => s.Ids == show.Ids); if (existingShow != null) { existingShow.Seasons = showSeasons; } else { var watchlistShow = new TraktSyncWatchlistPostShow { Ids = show.Ids, Title = show.Title, Year = show.Year, Seasons = showSeasons }; (_watchlistPost.Shows as List <ITraktSyncWatchlistPostShow>)?.Add(watchlistShow); } return(this); }
internal PostBuilderShowAddedMetadataWithSeasons(TPostBuilderAddShow postBuilder) { _postBuilder = postBuilder; _currentShow = null; ShowsAndMetadataWithSeasons = new List <PostBuilderObjectWithMetadataAndSeasons <ITraktShow, IEnumerable <int> > >(); }
private ITraktSyncHistoryPostShow CreateSyncHistoryPostShowWithSeasonsCollection(ITraktShow show, DateTime?watchedAt = null, PostHistorySeasons seasons = null) { var syncHistoryPostShow = CreateSyncHistoryPostShow(show, watchedAt); if (seasons != null) { syncHistoryPostShow.Seasons = CreateSyncHistoryPostShowSeasons(seasons); } return(syncHistoryPostShow); }
public ITraktPostBuilderShowAddedRating <ITraktSyncRatingsPostBuilder, ITraktSyncRatingsPost> AddRatedShow(ITraktShow show) { if (show == null) { throw new ArgumentNullException(nameof(show)); } _ratedShows.SetCurrentShow(show); return(_ratedShows); }
/// <summary> /// Posts a comment for the given <see cref="ITraktShow" />. /// <para>OAuth authorization required.</para> /// <para> /// See <a href="http://docs.trakt.apiary.io/#reference/comments/comments/post-a-comment">"Trakt API Doc - Comments: Comments"</a> for more information. /// </para> /// </summary> /// <param name="show">The <see cref="ITraktShow" />, for which the comment should be posted.</param> /// <param name="comment">The comment's content for the given show. Should be at least five words long.</param> /// <param name="containsSpoiler">Determines, if the <paramref name="comment" /> contains any spoilers.</param> /// <param name="sharing"><see cref="ITraktSharing" /> instance, containing sharing information for the comment.</param> /// <param name="cancellationToken"></param> /// <returns>An <see cref="ITraktCommentPostResponse" /> instance, containing the successfully posted comment's data.</returns> /// <exception cref="TraktException">Thrown, if the request fails.</exception> /// <exception cref="ArgumentException"> /// Thrown, if the given show's title is null, empty or contains spaces. /// Thrown, if the given show has no valid ids. See also <seealso cref="ITraktShowIds" />. /// Thrown, if the given comment is null or empty. /// </exception> /// <exception cref="ArgumentNullException">Thrown, if the given show is null or its ids are null.</exception> /// <exception cref="ArgumentOutOfRangeException">Thrown, if the given comment's word count is below five.</exception> public Task <TraktResponse <ITraktCommentPostResponse> > PostShowCommentAsync(ITraktShow show, string comment, bool?containsSpoiler = null, ITraktSharing sharing = null, CancellationToken cancellationToken = default) { ValidateShow(show); ValidateComment(comment); var requestHandler = new RequestHandler(Client); return(requestHandler.ExecuteSingleItemRequestAsync(new CommentPostRequest <ITraktShowCommentPost> { RequestBody = new TraktShowCommentPost { Show = new TraktShow { Title = show.Title, Ids = show.Ids }, Comment = comment, Spoiler = containsSpoiler, Sharing = sharing } }, cancellationToken)); }
public ITraktPostBuilderShowAddedSeasonsCollection <ITraktSyncHistoryPostBuilder, ITraktSyncHistoryPost, PostHistorySeasons> AddShowAndSeasonsCollection(ITraktShow show) { if (show == null) { throw new ArgumentNullException(nameof(show)); } _showsWithSeasonsCollection.SetCurrentShow(show); return(_showsWithSeasonsCollection); }
internal PostBuilderShowAddedMetadataWithSeasonsCollection(TPostBuilderAddShow postBuilder) { _postBuilder = postBuilder; _currentShow = null; ShowsAndMetadataWithSeasonsCollection = new List <PostBuilderObjectWithMetadataAndSeasons <ITraktShow, TSeasonCollection> >(); }
public ITraktPostBuilderShowAddedWatchedAt <ITraktSyncHistoryPostBuilder, ITraktSyncHistoryPost> AddWatchedShow(ITraktShow show) { if (show == null) { throw new ArgumentNullException(nameof(show)); } _watchedShows.SetCurrentShow(show); return(_watchedShows); }
public ITraktEpisodeScrobblePostResponse StopScrobbleEpisode(ITraktEpisode episode, ITraktShow traktShow, float progress, string appVersion = null, DateTime?appBuildDate = null) { ITraktResponse <ITraktEpisodeScrobblePostResponse> response = new TraktResponse <ITraktEpisodeScrobblePostResponse>(); try { response = Task.Run(() => base.Scrobble.StopEpisodeWithShowAsync(episode, traktShow, progress, appVersion, appBuildDate)).Result; } catch (AggregateException aggregateException) { UnwrapAggregateException(aggregateException); } return(response.Value); }