Exemplo n.º 1
0
        public GoodReadsQuery(GoodReadsService goodReadsService)
        {
            service = goodReadsService;

            Field <AuthorType>("author",
                               arguments: new QueryArguments(
                                   new QueryArgument <IntGraphType>()
            {
                Name = "id"
            }
                                   ),
                               resolve: context => service.GetAuthor(context.GetArgument <int>("id")));
            Field <BookType>("book",
                             arguments: new QueryArguments(
                                 new QueryArgument <IntGraphType>()
            {
                Name = "id"
            }
                                 ),
                             resolve: context => service.GetBook(context.GetArgument <int>("id")));
            Field <ListGraphType <CommentType> >("comments",
                                                 arguments: new QueryArguments(
                                                     new QueryArgument <IntGraphType>()
            {
                Name = "bookId"
            }
                                                     ),
                                                 resolve: context => service.GetCommentsForBook(context.GetArgument <int>("bookId")));
        }
Exemplo n.º 2
0
        public void ShouldParseGoodreadsReviewResponse()
        {
            var context  = new TestClientContext(LoadTestFile("goodreads.xml"));
            var xmlCient = new XMLClient(context);
            var service  = new GoodReadsService(new GoodReadsSettings(GetTestAppsettings()), xmlCient);
            var result   = service.GetReviews("1234567");

            Assert.IsType <Response <GoodreadsResponse> >(result);
        }
Exemplo n.º 3
0
        public CommentType()
        {
            GoodReadsService service = new GoodReadsService();

            Name = nameof(Comment);

            Field(x => x.Id);
            Field(x => x.User);
            Field(x => x.CommentDetails);
            Field(x => x.BookId, nullable: true);
            Field(x => x.Rating, type: typeof(RatingEnum));
            Field(typeof(BookType), "Book", resolve:
                  ctx => service.GetBook(ctx.Source.BookId.Value));
        }
Exemplo n.º 4
0
        public async Task Books(CommandContext ctx,
                                [Description("Book title to find on GoodReads")][RemainingText] string query)
        {
            if (!BotServices.CheckUserInput(query))
            {
                return;
            }
            var results = GoodReadsService.GetBookDataAsync(query).Result.Search;

            if (results.ResultCount <= 0)
            {
                await BotServices.SendEmbedAsync(ctx, Resources.NOT_FOUND_GENERIC, EmbedType.Missing).ConfigureAwait(false);
            }
            else
            {
                foreach (var book in results.Results)
                {
                    // TODO: Add page count, publication, ISBN, URLs
                    var output = new DiscordEmbedBuilder()
                                 .WithTitle(book.Book.Title)
                                 .AddField("Written by", book.Book.Author.Name ?? "Unknown", true)
                                 .AddField("Publication Date", (book.PublicationMonth.Text ?? "01") + "-" + (book.PublicationDay.Text ?? "01") + "-" + book.PublicationYear.Text, true)
                                 .AddField("Avg. Rating", book.RatingAverage ?? "Unknown", true)
                                 .WithThumbnailUrl(book.Book.ImageUrl ?? book.Book.ImageUrlSmall)
                                 .WithFooter(!book.Equals(results.Results.Last()) ? "Type 'next' within 10 seconds for the next book." : "This is the last found book on the list.")
                                 .WithColor(new DiscordColor("#372213"));
                    var message = await ctx.RespondAsync(embed : output.Build()).ConfigureAwait(false);

                    if (results.Results.Count == 1)
                    {
                        continue;
                    }
                    var interactivity = await BotServices.GetUserInteractivity(ctx, "next", 10).ConfigureAwait(false);

                    if (interactivity.Result is null)
                    {
                        break;
                    }
                    await BotServices.RemoveMessage(interactivity.Result).ConfigureAwait(false);

                    if (!book.Equals(results.Results.Last()))
                    {
                        await BotServices.RemoveMessage(message).ConfigureAwait(false);
                    }
                }
            }
        }
        public CommentsSubscriptions(GoodReadsService goodReadsService)
        {
            service = goodReadsService;

            AddField(new EventStreamFieldType
            {
                Name      = "commentAddedForBook",
                Type      = typeof(CommentType),
                Arguments = new QueryArguments()
                {
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                        Name = "bookId"
                    }
                },
                Resolver   = new FuncFieldResolver <Comment>(ResolveComment),
                Subscriber = new EventStreamResolver <Comment>(Subscribe)
            });
        }
        public CommentsMutation(GoodReadsService goodReadsService)
        {
            service = goodReadsService;

            Name = "CommentsMutations";


            Field <CommentType>(
                "addComment",
                arguments: new QueryArguments()
            {
                new QueryArgument <NonNullGraphType <CommentInputType> > {
                    Name = "comment"
                }
            },
                resolve: context =>
            {
                Comment comment = context.GetArgument <Comment>("comment");
                comment.Id      = service.AllComments.Count + 1;

                return(service.AddComment(comment));
            });
        }
Exemplo n.º 7
0
 public void GetBookData()
 {
     Assert.Greater(GoodReadsService.GetBookDataAsync("Ender's Game").Result.Search.ResultCount, 0);
     Assert.AreEqual(GoodReadsService.GetBookDataAsync("Bender's Game").Result.Search.ResultCount, 0);
 }