Example #1
0
        public async Task Test_TraktList_From_Json()
        {
            var jsonReader = new ListObjectJsonReader();
            var list       = await jsonReader.ReadObjectAsync(JSON) as TraktList;

            list.Should().NotBeNull();
            list.Name.Should().Be("Star Wars in machete order");
            list.Description.Should().Be("Next time you want to introduce someone to Star Wars for the first time, watch the films with them in this order: IV, V, II, III, VI.");
            list.Privacy.Should().Be(TraktAccessScope.Public);
            list.DisplayNumbers.Should().BeTrue();
            list.AllowComments.Should().BeFalse();
            list.SortBy.Should().Be("rank");
            list.SortHow.Should().Be("asc");
            list.CreatedAt.Should().Be(DateTime.Parse("2014-10-11T17:00:54.000Z").ToUniversalTime());
            list.UpdatedAt.Should().Be(DateTime.Parse("2014-11-09T17:00:54.000Z").ToUniversalTime());
            list.ItemCount.Should().Be(5);
            list.CommentCount.Should().Be(1);
            list.Likes.Should().Be(2);

            list.Ids.Should().NotBeNull();
            list.Ids.Trakt.Should().Be(55);
            list.Ids.Slug.Should().Be("star-wars-in-machete-order");

            list.User.Should().NotBeNull();
            list.User.Username.Should().Be("sean");
            list.User.IsPrivate.Should().BeFalse();
            list.User.Name.Should().Be("Sean Rudford");
            list.User.IsVIP.Should().BeTrue();
            list.User.IsVIP_EP.Should().BeFalse();
            list.User.Ids.Should().NotBeNull();
            list.User.Ids.Slug.Should().Be("sean");
        }
Example #2
0
        public override async Task <ITraktUserLikeItem> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktUserLikeItem)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var commentReader = new CommentObjectJsonReader();
                var listReader    = new ListObjectJsonReader();
                ITraktUserLikeItem traktUserLikeItem = new TraktUserLikeItem();

                while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = jsonReader.Value.ToString();

                    switch (propertyName)
                    {
                    case JsonProperties.USER_LIKE_ITEM_PROPERTY_NAME_LIKED_AT:
                    {
                        var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken);

                        if (value.First)
                        {
                            traktUserLikeItem.LikedAt = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.USER_LIKE_ITEM_PROPERTY_NAME_TYPE:
                        traktUserLikeItem.Type = await JsonReaderHelper.ReadEnumerationValueAsync <TraktUserLikeType>(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_LIKE_ITEM_PROPERTY_NAME_COMMENT:
                        traktUserLikeItem.Comment = await commentReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_LIKE_ITEM_PROPERTY_NAME_LIST:
                        traktUserLikeItem.List = await listReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    default:
                        await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);

                        break;
                    }
                }

                return(traktUserLikeItem);
            }

            return(await Task.FromResult(default(ITraktUserLikeItem)));
        }
Example #3
0
        public override async Task <ITraktListCommentPost> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktListCommentPost)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var sharingReader = new SharingObjectJsonReader();
                var listReader    = new ListObjectJsonReader();
                ITraktListCommentPost listCommentPost = new TraktListCommentPost();

                while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = jsonReader.Value.ToString();

                    switch (propertyName)
                    {
                    case JsonProperties.COMMENT_POST_PROPERTY_NAME_COMMENT:
                        listCommentPost.Comment = await jsonReader.ReadAsStringAsync(cancellationToken);

                        break;

                    case JsonProperties.COMMENT_POST_PROPERTY_NAME_SPOILER:
                    {
                        bool?value = await jsonReader.ReadAsBooleanAsync(cancellationToken);

                        if (value.HasValue)
                        {
                            listCommentPost.Spoiler = value.Value;
                        }

                        break;
                    }

                    case JsonProperties.COMMENT_POST_PROPERTY_NAME_SHARING:
                        listCommentPost.Sharing = await sharingReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.LIST_COMMENT_POST_PROPERTY_NAME_LIST:
                        listCommentPost.List = await listReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    default:
                        await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);

                        break;
                    }
                }

                return(listCommentPost);
            }

            return(await Task.FromResult(default(ITraktListCommentPost)));
        }
        public override async Task <ITraktUserComment> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            if (jsonReader == null)
            {
                return(await Task.FromResult(default(ITraktUserComment)));
            }

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var commentReader = new CommentObjectJsonReader();
                var movieReader   = new MovieObjectJsonReader();
                var showReader    = new ShowObjectJsonReader();
                var seasonReader  = new SeasonObjectJsonReader();
                var episodeReader = new EpisodeObjectJsonReader();
                var listReader    = new ListObjectJsonReader();
                ITraktUserComment traktUserComment = new TraktUserComment();

                while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = jsonReader.Value.ToString();

                    switch (propertyName)
                    {
                    case JsonProperties.USER_COMMENT_PROPERTY_NAME_TYPE:
                        traktUserComment.Type = await JsonReaderHelper.ReadEnumerationValueAsync <TraktObjectType>(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_COMMENT_PROPERTY_NAME_COMMENT:
                        traktUserComment.Comment = await commentReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_COMMENT_PROPERTY_NAME_MOVIE:
                        traktUserComment.Movie = await movieReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_COMMENT_PROPERTY_NAME_SHOW:
                        traktUserComment.Show = await showReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_COMMENT_PROPERTY_NAME_SEASON:
                        traktUserComment.Season = await seasonReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_COMMENT_PROPERTY_NAME_EPISODE:
                        traktUserComment.Episode = await episodeReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.USER_COMMENT_PROPERTY_NAME_LIST:
                        traktUserComment.List = await listReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    default:
                        await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);

                        break;
                    }
                }

                return(traktUserComment);
            }

            return(await Task.FromResult(default(ITraktUserComment)));
        }
        public override async Task <ITraktSearchResult> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            CheckJsonTextReader(jsonReader);

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var movieObjectReader   = new MovieObjectJsonReader();
                var showObjectReader    = new ShowObjectJsonReader();
                var episodeObjectReader = new EpisodeObjectJsonReader();
                var personObjectReader  = new PersonObjectJsonReader();
                var listObjectReader    = new ListObjectJsonReader();
                ITraktSearchResult traktSearchResult = new TraktSearchResult();

                while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = jsonReader.Value.ToString();

                    switch (propertyName)
                    {
                    case JsonProperties.PROPERTY_NAME_TYPE:
                        traktSearchResult.Type = await JsonReaderHelper.ReadEnumerationValueAsync <TraktSearchResultType>(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_SCORE:
                    {
                        var value = await JsonReaderHelper.ReadFloatValueAsync(jsonReader, cancellationToken);

                        if (value.First)
                        {
                            traktSearchResult.Score = value.Second;
                        }

                        break;
                    }

                    case JsonProperties.PROPERTY_NAME_MOVIE:
                        traktSearchResult.Movie = await movieObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_SHOW:
                        traktSearchResult.Show = await showObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_EPISODE:
                        traktSearchResult.Episode = await episodeObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_PERSON:
                        traktSearchResult.Person = await personObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_LIST:
                        traktSearchResult.List = await listObjectReader.ReadObjectAsync(jsonReader, cancellationToken);

                        break;

                    default:
                        await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);

                        break;
                    }
                }

                return(traktSearchResult);
            }

            return(await Task.FromResult(default(ITraktSearchResult)));
        }
        public override async Task <ITraktCommentItem> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            CheckJsonTextReader(jsonReader);

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                ITraktCommentItem traktCommentItem = new TraktCommentItem();
                var movieObjectJsonReader          = new MovieObjectJsonReader();
                var showObjectJsonReader           = new ShowObjectJsonReader();
                var seasonObjectJsonReader         = new SeasonObjectJsonReader();
                var episodeObjectJsonReader        = new EpisodeObjectJsonReader();
                var listObjectJsonReader           = new ListObjectJsonReader();

                while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = jsonReader.Value.ToString();

                    switch (propertyName)
                    {
                    case JsonProperties.PROPERTY_NAME_TYPE:
                        traktCommentItem.Type = await JsonReaderHelper.ReadEnumerationValueAsync <TraktObjectType>(jsonReader, cancellationToken);

                        break;

                    case JsonProperties.PROPERTY_NAME_MOVIE:
                        traktCommentItem.Movie = await movieObjectJsonReader.ReadObjectAsync(jsonReader, cancellationToken).ConfigureAwait(false);

                        break;

                    case JsonProperties.PROPERTY_NAME_SHOW:
                        traktCommentItem.Show = await showObjectJsonReader.ReadObjectAsync(jsonReader, cancellationToken).ConfigureAwait(false);

                        break;

                    case JsonProperties.PROPERTY_NAME_SEASON:
                        traktCommentItem.Season = await seasonObjectJsonReader.ReadObjectAsync(jsonReader, cancellationToken).ConfigureAwait(false);

                        break;

                    case JsonProperties.PROPERTY_NAME_EPISODE:
                        traktCommentItem.Episode = await episodeObjectJsonReader.ReadObjectAsync(jsonReader, cancellationToken).ConfigureAwait(false);

                        break;

                    case JsonProperties.PROPERTY_NAME_LIST:
                        traktCommentItem.List = await listObjectJsonReader.ReadObjectAsync(jsonReader, cancellationToken).ConfigureAwait(false);

                        break;

                    default:
                        await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);

                        break;
                    }
                }

                return(traktCommentItem);
            }

            return(await Task.FromResult(default(ITraktCommentItem)));
        }