Ejemplo n.º 1
0
        /// <summary>
        /// Use the authorization code parameter sent back to <see cref="TraktAuthentication.OAuthRedirectUri"/> to get a <see cref="TraktOAuthAccessToken"/>
        /// (stored in <see cref="TraktAuthentication.CurrentOAuthAccessToken"/>. Save the <see cref="TraktOAuthAccessToken"/> and restore it to
        /// <see cref="TraktAuthentication.CurrentOAuthAccessToken"/> during initialization.
        /// </summary>
        /// <param name="code">The authorization code returned from OAuth</param>
        /// <param name="clientId">Get this from your app settings</param>
        /// <param name="clientSecret">Get this from your app settings</param>
        /// <param name="redirectUri">The uri to which Trakt should redirect upon successful authentication. Refer to <see cref="TraktAuthentication.OAuthRedirectUri"/> for further details.</param>
        /// <param name="grantType">The requested grant type</param>
        /// <returns>See summary</returns>
        public async Task <TraktOAuthTokenResponse> GetOAuthTokenAsync(string code, string clientId, string clientSecret, string redirectUri, TraktOAuthTokenGrantType grantType)
        {
            TraktOAuthTokenRequestBody body = null;

            if (grantType == TraktOAuthTokenGrantType.AuthorizationCode)
            {
                body = new TraktOAuthTokenRequestBody
                {
                    Code         = code,
                    ClientId     = clientId,
                    ClientSecret = clientSecret,
                    RedirectUri  = redirectUri,
                    GrantType    = TraktEnumHelper.GetDescription(grantType)
                };
            }
            else
            {
                body = new TraktOAuthTokenRequestBody
                {
                    RefreshToken = code,
                    ClientId     = clientId,
                    ClientSecret = clientSecret,
                    RedirectUri  = redirectUri,
                    GrantType    = TraktEnumHelper.GetDescription(grantType)
                };
            }

            return(await SendAsync(new TraktOAuthTokenRequest(Client)
            {
                RequestBody = body
            }));
        }
Ejemplo n.º 2
0
        protected override IEnumerable <KeyValuePair <string, string> > GetQueryStringParameters(Dictionary <string, string> queryStringParameters)
        {
            var ret = base.GetQueryStringParameters(queryStringParameters).ToDictionary(o => o.Key, o => o.Value);

            ret["query"] = Query;
            if (Type != TraktSearchItemType.Unspecified)
            {
                ret["type"] = TraktEnumHelper.GetDescription(Type);
            }
            return(ret);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Use the authorization code parameter sent back to <see cref="TraktAuthentication.OAuthRedirectUri"/> to get a <see cref="TraktOAuthAccessToken"/>
 /// (stored in <see cref="TraktAuthentication.CurrentOAuthAccessToken"/>. Save the <see cref="TraktOAuthAccessToken"/> and restore it to
 /// <see cref="TraktAuthentication.CurrentOAuthAccessToken"/> during initialization.
 /// </summary>
 /// <param name="code">The authorization code returned from OAuth</param>
 /// <param name="clientId">Get this from your app settings</param>
 /// <param name="clientSecret">Get this from your app settings</param>
 /// <param name="redirectUri">The uri to which Trakt should redirect upon successful authentication. Refer to <see cref="TraktAuthentication.OAuthRedirectUri"/> for further details.</param>
 /// <param name="grantType">The requested grant type</param>
 /// <returns>See summary</returns>
 public async Task <TraktOAuthTokenResponse> GetOAuthTokenAsync(string code, string clientId, string clientSecret, string redirectUri, TraktOAuthTokenGrantType grantType)
 {
     return(await SendAsync(new TraktOAuthTokenRequest(Client) {
         RequestBody = new TraktOAuthTokenRequestBody {
             Code = code,
             ClientId = clientId,
             ClientSecret = clientSecret,
             RedirectUri = redirectUri,
             GrantType = TraktEnumHelper.GetDescription(grantType)
         }
     }));
 }
Ejemplo n.º 4
0
        public MainViewModel(MainView view)
        {
            _view = view;

            Client = new TraktClient();
            AuthenticationModes = new ObservableCollection <string>(TraktEnumHelper.GetEnumMembers(typeof(TraktAuthenticationMode)).Select(v => v.Value.Description));
            ExtendedOptions     = new ObservableCollection <string>(TraktEnumHelper.GetEnumMembers(typeof(TraktExtendedOption)).Select(v => v.Value.Label));
            TestRequestTypes    = new ObservableCollection <string>(TraktEnumHelper.GetEnumMembers(typeof(TestRequests.TestRequestType)).Select(v => v.Value.Description));
            IdLookupTypes       = new ObservableCollection <string>(TraktEnumHelper.GetEnumMembers(typeof(TraktIdLookupType)).Select(v => v.Value.Label));
            TextQueryTypes      = new ObservableCollection <string>(TraktEnumHelper.GetEnumMembers(typeof(TraktSearchItemType)).Select(v => v.Value.Label));
            TryLoadState();
            PropertyChanged += (sender, e) => TrySaveState();

            Client.BeforeRequest += (sender, e) => {
                LastResponse = "Waiting...";
                NotifyPropertyChanged(this.GetMemberName(x => x.LastResponse));

                LastResponseJson = "Waiting...";
                NotifyPropertyChanged(this.GetMemberName(x => x.LastResponseJson));

                LastReturnedValue = "Waiting...";
                NotifyPropertyChanged(this.GetMemberName(x => x.LastReturnedValue));

                var sb = new StringBuilder();
                sb.AppendLine(string.Format("{0} {1} HTTP/{2}", e.Request.Method.ToString().ToUpper(), e.Request.RequestUri.AbsoluteUri, e.Request.Version));
                e.Request.Headers.Select(h => string.Format("{0}: {1}", h.Key, string.Join(",", h.Value))).ToList().ForEach(l => sb.AppendLine(l));
                sb.AppendLine();
                sb.AppendLine(e.RequestBody);
                LastRequest = sb.ToString();
                NotifyPropertyChanged(this.GetMemberName(x => x.LastRequest));
            };

            Client.AfterRequest += (sender, e) => {
                var sb     = new StringBuilder();
                var status = "UNKNOWN STATUS";
                try {
                    status = e.Response.Headers.First(h => h.Key.Equals("Status", StringComparison.InvariantCultureIgnoreCase)).Value.First().ToUpper();
                } catch {}
                sb.AppendLine(string.Format("HTTP/{0} {1}", e.Response.Version, status));
                e.Response.Headers.Select(h => string.Format("{0}: {1}", h.Key, string.Join(",", h.Value))).ToList().ForEach(l => sb.AppendLine(l));
                sb.AppendLine();
                sb.AppendLine(e.ResponseText);
                LastResponse = sb.ToString();
                NotifyPropertyChanged(this.GetMemberName(x => x.LastResponse));

                LastResponseJson = !string.IsNullOrEmpty(e.ResponseText) ? PrettyPrint(e.ResponseText) : "The response did not include a body";
                NotifyPropertyChanged(this.GetMemberName(x => x.LastResponseJson));
            };
        }
Ejemplo n.º 5
0
 protected virtual IEnumerable <KeyValuePair <string, string> > GetQueryStringParameters(Dictionary <string, string> queryStringParameters)
 {
     if (Extended != TraktExtendedOption.Unspecified)
     {
         queryStringParameters["extended"] = TraktEnumHelper.GetDescription(Extended);
     }
     if (SupportsPagination)
     {
         if (Pagination.Page != null)
         {
             queryStringParameters["page"] = Pagination.Page.ToString();
         }
         if (Pagination.Limit != null)
         {
             queryStringParameters["limit"] = Pagination.Limit.ToString();
         }
     }
     return(queryStringParameters);
 }
Ejemplo n.º 6
0
        public static async Task <object> ExecuteTestRequest(TraktClient client, TestRequestType requestType, TraktExtendedOption extended = TraktExtendedOption.Unspecified, string testId = null, string testUsername = null, bool authenticateIfOptional = true)
        {
            //Uncomment if required
            var testIdInt = 0;

            try { if (testId != null)
                  {
                      testIdInt = Int32.Parse(testId);
                  }
            } catch {}

            //Default to current user if no test username provided
            if (testUsername == null)
            {
                testUsername = client.Authentication.Username ?? string.Empty;
            }

            switch (requestType)
            {
            // Auth module
            case TestRequestType.AuthLoginAsync:
                return(await client.Auth.LoginAsync("username", "password"));

            case TestRequestType.AuthLogoutAsync:
                await client.Auth.LogoutAsync();

                return(null);

            // Calendars module
            case TestRequestType.CalendarsGetShowsAsync:
                return(await client.Calendars.GetShowsAsync(extended : extended, authenticate : authenticateIfOptional));

            case TestRequestType.CalendarsGetNewShowsAsync:
                return(await client.Calendars.GetNewShowsAsync(extended : extended, authenticate : authenticateIfOptional));

            case TestRequestType.CalendarsGetPremiereShowsAsync:
                return(await client.Calendars.GetPremiereShowsAsync(extended : extended, authenticate : authenticateIfOptional));

            case TestRequestType.CalendarsGetMoviesAsync:
                return(await client.Calendars.GetMoviesAsync(extended : extended, authenticate : authenticateIfOptional));

            // Checkin module
            case TestRequestType.CheckinCheckinMovieAsync:
                return(await client.Checkin.CheckinMovieAsync(testId ?? "tt0120591", TraktTextMovieIdType.Auto, extended : extended));

            case TestRequestType.CheckinCheckinEpisodeAsync:
                return(await client.Checkin.CheckinEpisodeAsync("Breaking Bad", 2008, 1, 1, extended : extended));

            case TestRequestType.CheckinRemoveActiveCheckinAsync:
                await client.Checkin.RemoveActiveCheckinAsync();

                return(null);

            // Comments module
            case TestRequestType.CommentsPostMovieCommentAsync:
                return(await client.Comments.PostMovieCommentAsync(testId ?? "tt0120591", TraktTextMovieIdType.Auto, "TraktSharp test comment"));

            case TestRequestType.CommentsPostShowCommentAsync:
                return(await client.Comments.PostShowCommentAsync(testId ?? "tt0903747", TraktTextShowIdType.Auto, "TraktSharp test comment"));

            case TestRequestType.CommentsPostEpisodeCommentAsync:
                return(await client.Comments.PostEpisodeCommentAsync(testId ?? "tt0959621", TraktTextEpisodeIdType.Auto, "TraktSharp test comment"));

            case TestRequestType.CommentsPostListCommentAsync:
                return(await client.Comments.PostListCommentAsync(testId ?? "[list id]", "TraktSharp test comment"));

            case TestRequestType.CommentsGetCommentAsync:
                return(await client.Comments.GetCommentAsync(testId ?? "[comment id]"));

            case TestRequestType.CommentsUpdateCommentAsync:
                return(await client.Comments.UpdateCommentAsync(testId ?? "[comment id]", "TraktSharp test comment"));

            case TestRequestType.CommentsDeleteCommentAsync:
                await client.Comments.DeleteCommentAsync(testId ?? "[comment id]");

                return(null);

            case TestRequestType.CommentsLikeCommentAsync:
                return(await client.Comments.LikeCommentAsync(testId ?? "[comment id]"));

            case TestRequestType.CommentsUnlikeCommentAsync:
                await client.Comments.UnlikeCommentAsync(testId ?? "[comment id]");

                return(null);

            // Episodes module
            case TestRequestType.EpisodesGetEpisodeAsync:
                return(await client.Episodes.GetEpisodeAsync(testId ?? "breaking-bad", 1, 1, extended));

            case TestRequestType.EpisodesGetCommentsAsync:
                return(await client.Episodes.GetCommentsAsync(testId ?? "breaking-bad", 1, 1));

            case TestRequestType.EpisodesGetRatingsAsync:
                return(await client.Episodes.GetRatingsAsync(testId ?? "breaking-bad", 1, 1));

            case TestRequestType.EpisodesGetStatsAsync:
                return(await client.Episodes.GetStatsAsync(testId ?? "breaking-bad", 1, 1));

            case TestRequestType.EpisodesGetUsersWatchingEpisodeAsync:
                return(await client.Episodes.GetUsersWatchingEpisodeAsync(testId ?? "breaking-bad", 1, 1, extended));

            // Genres module
            case TestRequestType.GenresGetGenresAsyncMovies:
                return(await client.Genres.GetGenresAsync(TraktGenreTypeOptions.Movies));

            case TestRequestType.GenresGetGenresAsyncShows:
                return(await client.Genres.GetGenresAsync(TraktGenreTypeOptions.Shows));

            // Movies module
            case TestRequestType.MoviesGetPopularMoviesAsync:
                return(await client.Movies.GetPopularMoviesAsync(extended));

            case TestRequestType.MoviesGetTrendingMoviesAsync:
                return(await client.Movies.GetTrendingMoviesAsync(extended));

            case TestRequestType.MoviesGetUpdatedMoviesAsync:
                return(await client.Movies.GetUpdatedMoviesAsync(DateTime.Now.AddMonths(-1), extended));

            case TestRequestType.MoviesGetMovieAsync:
                return(await client.Movies.GetMovieAsync(testId ?? "tt0120591", extended));

            case TestRequestType.MoviesGetAliasesAsync:
                return(await client.Movies.GetAliasesAsync(testId ?? "tt0120591"));

            case TestRequestType.MoviesGetReleasesAsync:
                return(await client.Movies.GetReleasesAsync(testId ?? "tt0120591", "us"));

            case TestRequestType.MoviesGetTranslationsAsync:
                return(await client.Movies.GetTranslationsAsync(testId ?? "tt0120591", "es"));

            case TestRequestType.MoviesGetCommentsAsync:
                return(await client.Movies.GetCommentsAsync(testId ?? "tt0468569"));

            case TestRequestType.MoviesGetCastAndCrewAsync:
                return(await client.Movies.GetCastAndCrewAsync(testId ?? "tt0120591", extended));

            case TestRequestType.MoviesGetRatingsAsync:
                return(await client.Movies.GetRatingsAsync(testId ?? "tt0120591"));

            case TestRequestType.MoviesGetRelatedMoviesAsync:
                return(await client.Movies.GetRelatedMoviesAsync(testId ?? "tt0120591", extended));

            case TestRequestType.MoviesGetStatsAsync:
                return(await client.Movies.GetStatsAsync(testId ?? "tt0120591"));

            case TestRequestType.MoviesGetUsersWatchingMovieAsync:
                return(await client.Movies.GetUsersWatchingMovieAsync(testId ?? "tt0120591", extended));

            // People module
            case TestRequestType.PeopleGetPersonAsync:
                return(await client.People.GetPersonAsync(testId ?? "nm0186505", extended));

            case TestRequestType.PeopleGetMoviesForPersonAsync:
                return(await client.People.GetMoviesForPersonAsync(testId ?? "brad-pitt", extended));

            case TestRequestType.PeopleGetShowsForPersonAsync:
                return(await client.People.GetShowsForPersonAsync(testId ?? "nm0186505", extended));

            // Recommendations module
            case TestRequestType.RecommendationsGetRecommendedMoviesAsync:
                return(await client.Recommendations.GetRecommendedMoviesAsync(extended));

            case TestRequestType.RecommendationsDismissMovieRecommendationAsync:
                await client.Recommendations.DismissMovieRecommendationAsync(testId ?? "tt0942385");

                return(null);

            case TestRequestType.RecommendationsGetRecommendedShowsAsync:
                return(await client.Recommendations.GetRecommendedShowsAsync(extended));

            case TestRequestType.RecommendationsDismissShowRecommendationAsync:
                await client.Recommendations.DismissShowRecommendationAsync(testId ?? "tt2322158");

                return(null);

            // Scrobble module
            case TestRequestType.ScrobbleStartMovieAsync:
                return(await client.Scrobble.StartMovieAsync(testId ?? "tt0120591", TraktTextMovieIdType.Auto, 1, extended : extended));

            case TestRequestType.ScrobbleStartEpisodeAsync:
                return(await client.Scrobble.StartEpisodeAsync(testId ?? "tt0959621", TraktTextEpisodeIdType.Auto, 1, extended : extended));

            case TestRequestType.ScrobblePauseMovieAsync:
                return(await client.Scrobble.PauseMovieAsync(testId ?? "tt0120591", TraktTextMovieIdType.Auto, 50, extended : extended));

            case TestRequestType.ScrobblePauseEpisodeAsync:
                return(await client.Scrobble.PauseEpisodeAsync(testId ?? "tt0959621", TraktTextEpisodeIdType.Auto, 50, extended : extended));

            case TestRequestType.ScrobbleStopMovieAsync:
                return(await client.Scrobble.StopMovieAsync(testId ?? "tt0120591", TraktTextMovieIdType.Auto, 99.9F, extended : extended));

            case TestRequestType.ScrobbleStopEpisodeAsync:
                return(await client.Scrobble.StopEpisodeAsync(testId ?? "tt0959621", TraktTextEpisodeIdType.Auto, 99.9F, extended : extended));

            // Seasons module
            case TestRequestType.SeasonsGetSeasonOverviewAsync:
                return(await client.Seasons.GetSeasonOverviewAsync(testId ?? "breaking-bad", extended));

            case TestRequestType.SeasonsGetEpisodesForSeasonAsync:
                return(await client.Seasons.GetEpisodesForSeasonAsync(testId ?? "breaking-bad", 1, extended));

            case TestRequestType.SeasonsGetCommentsAsync:
                return(await client.Seasons.GetCommentsAsync(testId ?? "breaking-bad", 1));

            case TestRequestType.SeasonsGetRatingsAsync:
                return(await client.Seasons.GetRatingsAsync(testId ?? "breaking-bad", 1));

            case TestRequestType.SeasonsGetUsersWatchingSeasonAsync:
                return(await client.Seasons.GetUsersWatchingSeasonAsync(testId ?? "breaking-bad", 1));

            // Shows module
            case TestRequestType.ShowsGetPopularShowsAsync:
                return(await client.Shows.GetPopularShowsAsync(extended));

            case TestRequestType.ShowsGetTrendingShowsAsync:
                return(await client.Shows.GetTrendingShowsAsync(extended));

            case TestRequestType.ShowsGetUpdatedShowsAsync:
                return(await client.Shows.GetUpdatedShowsAsync(DateTime.Now.AddMonths(-1), extended));

            case TestRequestType.ShowsGetShowAsync:
                return(await client.Shows.GetShowAsync(testId ?? "breaking-bad", extended));

            case TestRequestType.ShowsGetAliasesAsync:
                return(await client.Shows.GetAliasesAsync(testId ?? "breaking-bad"));

            case TestRequestType.ShowsGetTranslationsAsync:
                return(await client.Shows.GetTranslationsAsync(testId ?? "breaking-bad", "es"));

            case TestRequestType.ShowsGetCommentsAsync:
                return(await client.Shows.GetCommentsAsync(testId ?? "breaking-bad"));

            case TestRequestType.ShowsGetCollectionProgressAsync:
                return(await client.Shows.GetCollectionProgressAsync(testId ?? "breaking-bad", extended));

            case TestRequestType.ShowsGetWatchedProgressAsync:
                return(await client.Shows.GetWatchedProgressAsync(testId ?? "breaking-bad", extended));

            case TestRequestType.ShowsGetCastAndCrewAsync:
                return(await client.Shows.GetCastAndCrewAsync(testId ?? "breaking-bad", extended));

            case TestRequestType.ShowsGetRatingsAsync:
                return(await client.Shows.GetRatingsAsync(testId ?? "breaking-bad"));

            case TestRequestType.ShowsGetRelatedShowsAsync:
                return(await client.Shows.GetRelatedShowsAsync(testId ?? "breaking-bad", extended));

            case TestRequestType.ShowsGetStatsAsync:
                return(await client.Shows.GetStatsAsync(testId ?? "breaking-bad"));

            case TestRequestType.ShowsGetUsersWatchingShowAsync:
                return(await client.Shows.GetUsersWatchingShowAsync(testId ?? "breaking-bad", extended));

            // Sync module
            case TestRequestType.SyncGetLastActivitiesAsync:
                return(await client.Sync.GetLastActivitiesAsync());

            case TestRequestType.SyncGetPlaybackStateAsync:
                return(await client.Sync.GetPlaybackStateAsync(extended));

            case TestRequestType.SyncGetMoviesCollectionAsync:
                return(await client.Sync.GetMoviesCollectionAsync(extended));

            case TestRequestType.SyncGetShowsCollectionAsync:
                return(await client.Sync.GetShowsCollectionAsync(extended));

            case TestRequestType.SyncAddToCollectionByMovieIdAsync:
                return(await client.Sync.AddToCollectionByMovieIdAsync(testId ?? "tt0120591"));

            case TestRequestType.SyncAddToCollectionByShowIdAsync:
                return(await client.Sync.AddToCollectionByShowIdAsync(testId ?? "breaking-bad"));

            case TestRequestType.SyncAddToCollectionByShowIdAsyncSeasonNumbers:
                return(await client.Sync.AddToCollectionByShowIdAsync(testId ?? "breaking-bad", seasonNumbers : new[] { 1 }));

            case TestRequestType.SyncAddToCollectionByEpisodeIdAsync:
                return(await client.Sync.AddToCollectionByEpisodeIdAsync(testId ?? "tt0959621"));

            case TestRequestType.SyncRemoveFromCollectionByMovieIdAsync:
                return(await client.Sync.RemoveFromCollectionByMovieIdAsync(testId ?? "tt0120591"));

            case TestRequestType.SyncRemoveFromCollectionByShowIdAsync:
                return(await client.Sync.RemoveFromCollectionByShowIdAsync(testId ?? "breaking-bad"));

            case TestRequestType.SyncRemoveFromCollectionByShowIdAsyncSeasonNumbers:
                return(await client.Sync.RemoveFromCollectionByShowIdAsync(testId ?? "breaking-bad", seasonNumbers : new[] { 1 }));

            case TestRequestType.SyncRemoveFromCollectionByEpisodeIdAsync:
                return(await client.Sync.RemoveFromCollectionByEpisodeIdAsync(testId ?? "tt0959621"));

            case TestRequestType.SyncGetWatchedMoviesAsync:
                return(await client.Sync.GetWatchedMoviesAsync(extended));

            case TestRequestType.SyncGetWatchedShowsAsync:
                return(await client.Sync.GetWatchedShowsAsync(extended));

            case TestRequestType.SyncMarkWatchedByMovieIdAsync:
                return(await client.Sync.MarkWatchedByMovieIdAsync(testId ?? "tt0120591"));

            case TestRequestType.SyncMarkWatchedByShowIdAsync:
                return(await client.Sync.MarkWatchedByShowIdAsync(testId ?? "breaking-bad"));

            case TestRequestType.SyncMarkWatchedByShowIdAsyncSeasonNumbers:
                return(await client.Sync.MarkWatchedByShowIdAsync(testId ?? "breaking-bad", seasonNumbers : new[] { 1 }));

            case TestRequestType.SyncMarkWatchedByEpisodeIdAsync:
                return(await client.Sync.MarkWatchedByEpisodeIdAsync(testId ?? "tt0959621"));

            case TestRequestType.SyncMarkUnwatchedByMovieIdAsync:
                return(await client.Sync.MarkUnwatchedByMovieIdAsync(testId ?? "tt0120591"));

            case TestRequestType.SyncMarkUnwatchedByShowIdAsync:
                return(await client.Sync.MarkUnwatchedByShowIdAsync(testId ?? "breaking-bad"));

            case TestRequestType.SyncMarkUnwatchedByShowIdAsyncSeasonNumbers:
                return(await client.Sync.MarkUnwatchedByShowIdAsync(testId ?? "breaking-bad", seasonNumbers : new[] { 1 }));

            case TestRequestType.SyncMarkUnwatchedByEpisodeIdAsync:
                return(await client.Sync.MarkUnwatchedByEpisodeIdAsync(testId ?? "tt0959621"));

            case TestRequestType.SyncGetMovieRatingsAsync:
                return(await client.Sync.GetMovieRatingsAsync(TraktRating.Unspecified, extended));

            case TestRequestType.SyncGetShowRatingsAsync:
                return(await client.Sync.GetShowRatingsAsync(TraktRating.Unspecified, extended));

            case TestRequestType.SyncGetSeasonRatingsAsync:
                return(await client.Sync.GetSeasonRatingsAsync(TraktRating.Unspecified, extended));

            case TestRequestType.SyncGetEpisodeRatingsAsync:
                return(await client.Sync.GetEpisodeRatingsAsync(TraktRating.Unspecified, extended));

            case TestRequestType.SyncAddRatingByMovieIdAsync:
                return(await client.Sync.AddRatingByMovieIdAsync(testId ?? "tt0120591", TraktTextMovieIdType.Auto, TraktRating.Rating7));

            case TestRequestType.SyncAddRatingByShowIdAsync:
                return(await client.Sync.AddRatingByShowIdAsync(testId ?? "breaking-bad", TraktTextShowIdType.Auto, TraktRating.Rating7));

            case TestRequestType.SyncAddRatingByShowIdAsyncSeasonNumbers:
                return(await client.Sync.AddRatingByShowIdAsync(testId ?? "breaking-bad", TraktTextShowIdType.Auto, TraktRating.Rating7, seasonNumbers : new[] { 1 }));

            case TestRequestType.SyncAddRatingByEpisodeIdAsync:
                return(await client.Sync.AddRatingByEpisodeIdAsync(testId ?? "tt0959621", TraktTextEpisodeIdType.Auto, TraktRating.Rating7));

            case TestRequestType.SyncRemoveRatingByMovieIdAsync:
                return(await client.Sync.RemoveRatingByMovieIdAsync(testId ?? "tt0120591"));

            case TestRequestType.SyncRemoveRatingByShowIdAsync:
                return(await client.Sync.RemoveRatingByShowIdAsync(testId ?? "breaking-bad"));

            case TestRequestType.SyncRemoveRatingByShowIdAsyncSeasonNumbers:
                return(await client.Sync.RemoveRatingByShowIdAsync(testId ?? "breaking-bad", seasonNumbers : new[] { 1 }));

            case TestRequestType.SyncRemoveRatingByEpisodeIdAsync:
                return(await client.Sync.RemoveRatingByEpisodeIdAsync(testId ?? "tt0959621"));

            case TestRequestType.SyncGetWatchlistMoviesAsync:
                return(await client.Sync.GetWatchlistMoviesAsync(extended));

            case TestRequestType.SyncGetWatchlistShowsAsync:
                return(await client.Sync.GetWatchlistShowsAsync(extended));

            case TestRequestType.SyncGetWatchlistSeasonsAsync:
                return(await client.Sync.GetWatchlistSeasonsAsync(extended));

            case TestRequestType.SyncGetWatchlistEpisodesAsync:
                return(await client.Sync.GetWatchlistEpisodesAsync(extended));

            case TestRequestType.SyncAddToWatchlistByMovieIdAsync:
                return(await client.Sync.AddToWatchlistByMovieIdAsync(testId ?? "tt0120591"));

            case TestRequestType.SyncAddToWatchlistByShowIdAsync:
                return(await client.Sync.AddToWatchlistByShowIdAsync(testId ?? "breaking-bad"));

            case TestRequestType.SyncAddToWatchlistByShowIdAsyncSeasonNumbers:
                return(await client.Sync.AddToWatchlistByShowIdAsync(testId ?? "breaking-bad", seasonNumbers : new[] { 1 }));

            case TestRequestType.SyncAddToWatchlistByEpisodeIdAsync:
                return(await client.Sync.AddToWatchlistByEpisodeIdAsync(testId ?? "tt0959621"));

            case TestRequestType.SyncRemoveFromWatchlistByMovieIdAsync:
                return(await client.Sync.RemoveFromWatchlistByMovieIdAsync(testId ?? "tt0120591"));

            case TestRequestType.SyncRemoveFromWatchlistByShowIdAsync:
                return(await client.Sync.RemoveFromWatchlistByShowIdAsync(testId ?? "breaking-bad"));

            case TestRequestType.SyncRemoveFromWatchlistByShowIdAsyncSeasonNumbers:
                return(await client.Sync.RemoveFromWatchlistByShowIdAsync(testId ?? "breaking-bad", seasonNumbers : new[] { 1 }));

            case TestRequestType.SyncRemoveFromWatchlistByEpisodeIdAsync:
                return(await client.Sync.RemoveFromWatchlistByEpisodeIdAsync(testId ?? "tt0959621"));

            // Users module
            case TestRequestType.UsersGetSettingsAsync:
                return(await client.Users.GetSettingsAsync(extended));

            case TestRequestType.UsersUpdateSettingsAsync:
                return(await client.Users.UpdateSettingsAsync());

            case TestRequestType.UsersGetFollowRequestsAsync:
                return(await client.Users.GetFollowRequestsAsync(extended));

            case TestRequestType.UsersApproveFollowRequestAsync:
                return(await client.Users.ApproveFollowRequestAsync(testIdInt, extended));

            case TestRequestType.UsersDenyFollowRequestAsync:
                await client.Users.DenyFollowRequestAsync(testIdInt);

                return(null);

            case TestRequestType.UsersGetUserAsync:
                return(await client.Users.GetUserAsync(testUsername, extended, authenticateIfOptional));

            case TestRequestType.UsersGetMoviesCollectionAsync:
                return(await client.Users.GetMoviesCollectionAsync(testUsername, extended, authenticateIfOptional));

            case TestRequestType.UsersGetShowsCollectionAsync:
                return(await client.Users.GetShowsCollectionAsync(testUsername, extended, authenticateIfOptional));

            case TestRequestType.UsersGetListsAsync:
                return(await client.Users.GetListsAsync(testUsername, authenticateIfOptional));

            case TestRequestType.UsersCreateListAsync:
                return(await client.Users.CreateListAsync("Test List", "Test List Description"));

            case TestRequestType.UsersGetListAsync:
                return(await client.Users.GetListAsync(testId, testUsername, authenticateIfOptional));

            case TestRequestType.UsersUpdateListAsync:
                return(await client.Users.UpdateListAsync(testId, "Test List Updated", "Test List Description Updated"));

            case TestRequestType.UsersDeleteListAsync:
                await client.Users.DeleteListAsync(testId);

                return(null);

            case TestRequestType.UsersAddToListByMovieIdAsync:
                return(await client.Users.AddToListByMovieIdAsync(testId, "tt0120591"));

            case TestRequestType.UsersAddToListByShowIdAsync:
                return(await client.Users.AddToListByShowIdAsync(testId, "breaking-bad"));

            case TestRequestType.UsersAddToListByEpisodeIdAsync:
                return(await client.Users.AddToListByEpisodeIdAsync(testId, "tt0959621"));

            case TestRequestType.UsersRemoveFromListByMovieIdAsync:
                return(await client.Users.RemoveFromListByMovieIdAsync(testId, "tt0120591"));

            case TestRequestType.UsersRemoveFromListByShowIdAsync:
                return(await client.Users.RemoveFromListByShowIdAsync(testId, "breaking-bad"));

            case TestRequestType.UsersRemoveFromListByEpisodeIdAsync:
                return(await client.Users.RemoveFromListByEpisodeIdAsync(testId, "tt0959621"));

            case TestRequestType.UsersLikeListAsync:
                await client.Users.LikeListAsync(testId, testUsername);

                return(null);

            case TestRequestType.UsersUnlikeListAsync:
                await client.Users.UnlikeListAsync(testId, testUsername);

                return(null);

            case TestRequestType.UsersGetListItemsAsync:
                return(await client.Users.GetListItemsAsync(testId, extended, testUsername, authenticateIfOptional));

            case TestRequestType.UsersFollowAsync:
                return(await client.Users.FollowAsync(testUsername, extended));

            case TestRequestType.UsersUnfollowAsync:
                await client.Users.UnfollowAsync(testUsername);

                return(null);

            case TestRequestType.UsersGetFollowersAsync:
                return(await client.Users.GetFollowersAsync(testUsername, extended));

            case TestRequestType.UsersGetFollowingAsync:
                return(await client.Users.GetFollowingAsync(testUsername, extended));

            case TestRequestType.UsersGetFriendsAsync:
                return(await client.Users.GetFriendsAsync(testUsername, extended));

            case TestRequestType.UsersGetMoviesHistoryAsync:
                return(await client.Users.GetMoviesHistoryAsync(testUsername, extended));

            case TestRequestType.UsersGetEpisodesHistoryAsync:
                return(await client.Users.GetEpisodesHistoryAsync(testUsername, extended));

            case TestRequestType.UsersGetMovieRatingsAsync:
                return(await client.Users.GetMovieRatingsAsync(testUsername, extended : extended));

            case TestRequestType.UsersGetShowRatingsAsync:
                return(await client.Users.GetShowRatingsAsync(testUsername, extended : extended));

            case TestRequestType.UsersGetSeasonRatingsAsync:
                return(await client.Users.GetSeasonRatingsAsync(testUsername, extended : extended));

            case TestRequestType.UsersGetEpisodeRatingsAsync:
                return(await client.Users.GetEpisodeRatingsAsync(testUsername, extended : extended));

            case TestRequestType.UsersGetWatchlistMoviesAsync:
                return(await client.Users.GetWatchlistMoviesAsync(testUsername, extended));

            case TestRequestType.UsersGetWatchlistShowsAsync:
                return(await client.Users.GetWatchlistShowsAsync(testUsername, extended));

            case TestRequestType.UsersGetWatchlistSeasonsAsync:
                return(await client.Users.GetWatchlistSeasonsAsync(testUsername, extended));

            case TestRequestType.UsersGetWatchlistEpisodesAsync:
                return(await client.Users.GetWatchlistEpisodesAsync(testUsername, extended));

            case TestRequestType.UsersGetCurrentlyWatchingAsync:
                return(await client.Users.GetCurrentlyWatchingAsync(testUsername, extended));

            case TestRequestType.UsersGetWatchedMoviesAsync:
                return(await client.Users.GetWatchedMoviesAsync(testUsername, extended));

            case TestRequestType.UsersGetWatchedShowsAsync:
                return(await client.Users.GetWatchedShowsAsync(testUsername, extended));

            case TestRequestType.UsersGetActivitiesAsync:
                return(await client.Users.GetActivitiesAsync(testUsername));

            case TestRequestType.UsersGetFriendActivitiesAsync:
                return(await client.Users.GetFriendActivitiesAsync(testUsername));

            // Invalid request type
            default:
                throw new ArgumentOutOfRangeException("requestType",
                                                      string.Format("A test case has not been implemented for the requested method type: {0}", TraktEnumHelper.GetDescription(requestType)));
            }
        }
Ejemplo n.º 7
0
 protected override IEnumerable <KeyValuePair <string, string> > GetPathParameters(IEnumerable <KeyValuePair <string, string> > pathParameters)
 {
     return(new Dictionary <string, string> {
         { "type", TraktEnumHelper.GetDescription(Type) }
     });
 }
Ejemplo n.º 8
0
 protected override IEnumerable <KeyValuePair <string, string> > GetQueryStringParameters(Dictionary <string, string> queryStringParameters)
 {
     return(base.GetPathParameters(queryStringParameters).Union(new Dictionary <string, string> {
         { "id_type", TraktEnumHelper.GetDescription(IdType) }
     }));
 }
Ejemplo n.º 9
0
        public TvProfile()
        {
            CreateMap <TvMazeSearch, SearchTvShowViewModel>()
            .ForMember(dest => dest.Id, opts => opts.MapFrom(src => src.show.externals.thetvdb))
            .ForMember(dest => dest.FirstAired, opts => opts.MapFrom(src => src.show.premiered))
            .ForMember(dest => dest.ImdbId, opts => opts.MapFrom(src => src.show.externals.imdb))
            .ForMember(dest => dest.Network, opts => opts.MapFrom(src => src.show.network.name))
            .ForMember(dest => dest.NetworkId, opts => opts.MapFrom(src => src.show.network.id.ToString()))
            .ForMember(dest => dest.Overview, opts => opts.MapFrom(src => src.show.summary.RemoveHtml()))
            .ForMember(dest => dest.Rating, opts => opts.MapFrom(src => src.score.ToString(CultureInfo.CurrentUICulture)))
            .ForMember(dest => dest.Runtime, opts => opts.MapFrom(src => src.show.runtime.ToString()))
            .ForMember(dest => dest.SeriesId, opts => opts.MapFrom(src => src.show.id))
            .ForMember(dest => dest.Title, opts => opts.MapFrom(src => src.show.name))
            .ForMember(dest => dest.Banner, opts => opts.MapFrom(src => !string.IsNullOrEmpty(src.show.image.medium) ? src.show.image.medium.ToHttpsUrl() : string.Empty))
            .ForMember(dest => dest.Status, opts => opts.MapFrom(src => src.show.status));

            CreateMap <TvSearchResult, SearchTvShowViewModel>()
            .ForMember(dest => dest.Id, opts => opts.MapFrom(src => src.Id))
            .ForMember(dest => dest.TheMovieDbId, opts => opts.MapFrom(src => src.Id.ToString()))
            .ForMember(dest => dest.FirstAired, opts => opts.MapFrom(src => src.ReleaseDate))
            .ForMember(dest => dest.Overview, opts => opts.MapFrom(src => src.Overview))
            .ForMember(dest => dest.Rating, opts => opts.MapFrom(src => src.VoteAverage.ToString(CultureInfo.CurrentUICulture)))
            .ForMember(dest => dest.Title, opts => opts.MapFrom(src => src.Name))
            .ForMember(dest => dest.Banner, opts => opts.MapFrom(src => !string.IsNullOrEmpty(src.BackdropPath) ? src.BackdropPath.ToHttpsUrl() : src.PosterPath));

            CreateMap <TvMazeShow, SearchTvShowViewModel>()
            .ForMember(dest => dest.Id, opts => opts.MapFrom(src => src.externals.thetvdb))
            .ForMember(dest => dest.FirstAired, opts => opts.MapFrom(src => src.premiered))
            .ForMember(dest => dest.ImdbId, opts => opts.MapFrom(src => src.externals.imdb))
            .ForMember(dest => dest.Network, opts => opts.MapFrom(src => src.network.name))
            .ForMember(dest => dest.NetworkId, opts => opts.MapFrom(src => src.network.id.ToString()))
            .ForMember(dest => dest.Overview, opts => opts.MapFrom(src => src.summary.RemoveHtml()))
            .ForMember(dest => dest.Rating, opts => opts.MapFrom(src => src.rating.ToString()))
            .ForMember(dest => dest.Runtime,
                       opts => opts.MapFrom(src => src.runtime.ToString(CultureInfo.CurrentUICulture)))
            .ForMember(dest => dest.SeriesId, opts => opts.MapFrom(src => src.id))
            .ForMember(dest => dest.Title, opts => opts.MapFrom(src => src.name))
            .ForMember(dest => dest.Banner,
                       opts => opts.MapFrom(src => !string.IsNullOrEmpty(src.image.medium)
                        ? src.image.medium.ToHttpsUrl()
                        : string.Empty))
            .ForMember(dest => dest.Status, opts => opts.MapFrom(src => src.status));


            CreateMap <TraktShow, SearchTvShowViewModel>()
            .ForMember(dest => dest.Id, opts => opts.MapFrom(src => src.Ids.Tvdb.HasValue ? Convert.ToInt32(src.Ids.Tvdb.ToString()) : 0))
            .ForMember(dest => dest.FirstAired, opts => opts.MapFrom(src => src.FirstAired.HasValue ? src.FirstAired.Value.ToString("yyyy-MM-ddTHH:mm:ss") : string.Empty))
            .ForMember(dest => dest.ImdbId, opts => opts.MapFrom(src => src.Ids.Imdb))
            .ForMember(dest => dest.Network, opts => opts.MapFrom(src => src.Network))
            .ForMember(dest => dest.Overview, opts => opts.MapFrom(src => src.Overview.RemoveHtml()))
            .ForMember(dest => dest.Rating, opts => opts.MapFrom(src => src.Rating.ToString()))
            .ForMember(dest => dest.Runtime, opts => opts.MapFrom(src => src.Runtime.ToString()))
            .ForMember(dest => dest.Title, opts => opts.MapFrom(src => src.Title))
            .ForMember(dest => dest.Status, opts => opts.MapFrom(src => TraktEnumHelper.GetDescription(src.Status)))
            .ForMember(dest => dest.Trailer,
                       opts => opts.MapFrom(src => src.Trailer != null ? src.Trailer.ToString().ToHttpsUrl() : string.Empty))
            .ForMember(dest => dest.Homepage,
                       opts => opts.MapFrom(src => src.Homepage != null ? src.Homepage.ToString().ToHttpsUrl() : string.Empty));


            CreateMap <MovieDbSearchResult, SearchTvShowViewModel>()
            .ForMember(dest => dest.Id, opts => opts.MapFrom(src => src.Id))
            .ForMember(dest => dest.FirstAired, opts => opts.MapFrom(src => src.ReleaseDate))
            //.ForMember(dest => dest.ImdbId, opts => opts.MapFrom(src => src.Ids.Imdb))
            //.ForMember(dest => dest.Network, opts => opts.MapFrom(src => src.Network))
            .ForMember(dest => dest.Overview, opts => opts.MapFrom(src => src.Overview))
            .ForMember(dest => dest.Rating, opts => opts.MapFrom(src => src.VoteAverage.ToString()))
            .ForMember(dest => dest.BackdropPath, opts => opts.MapFrom(src => src.PosterPath))
            //.ForMember(dest => dest.Runtime, opts => opts.MapFrom(src => src.Runtime.ToString()))
            .ForMember(dest => dest.Title, opts => opts.MapFrom(src => src.Title))
            .ForMember(dest => dest.SeasonRequests, opts => opts.MapFrom(src => src.SeasonRequests))
            ;
            //.ForMember(dest => dest.Status, opts => opts.MapFrom(src => TraktEnumHelper.GetDescription(src.Status)))
            //.ForMember(dest => dest.Trailer,
            //    opts => opts.MapFrom(src => src.Trailer != null ? src.Trailer.ToString().ToHttpsUrl() : string.Empty))
            //.ForMember(dest => dest.Homepage,
            //    opts => opts.MapFrom(src => src.Homepage != null ? src.Homepage.ToString().ToHttpsUrl() : string.Empty));
        }