Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GoodreadsClient"/> class.
        /// Use this constructor if you already have OAuth permissions for the user.
        /// </summary>
        /// <param name="apiKey">Your Goodreads API key.</param>
        /// <param name="apiSecret">Your Goodreads API secret.</param>
        /// <param name="accessToken">The user's OAuth access token.</param>
        /// <param name="accessSecret">The user's OAuth access secret.</param>
        public GoodreadsClient(string apiKey, string apiSecret, string accessToken, string accessSecret)
        {
            var client = new RestClient(new Uri(GoodreadsUrl))
            {
                UserAgent = "goodreads-dotnet"
            };

            client.AddDefaultParameter("key", apiKey, ParameterType.QueryString);
            client.AddDefaultParameter("format", "xml", ParameterType.QueryString);

            var apiCredentials = new ApiCredentials(client, apiKey, apiSecret, accessToken, accessSecret);

            // Setup the OAuth authenticator if they have passed on the appropriate tokens
            if (!string.IsNullOrWhiteSpace(accessToken) &&
                !string.IsNullOrWhiteSpace(accessSecret))
            {
                client.Authenticator = OAuth1Authenticator.ForProtectedResource(
                    apiKey, apiSecret, accessToken, accessSecret);
            }

            Connection = new Connection(client, apiCredentials);
            Authors    = new AuthorsClient(Connection);
            Books      = new BooksClient(Connection);
            Shelves    = new ShelvesClient(Connection);
            Users      = new UsersClient(Connection);
            Reviews    = new ReviewsClient(Connection);
            Series     = new SeriesClient(Connection);
        }
Exemplo n.º 2
0
            public async Task ReturnsNullIfNotFound()
            {
                var userId  = -1;
                var shelves = await ShelvesClient.GetListOfUserShelves(userId);

                Assert.Null(shelves);
            }
Exemplo n.º 3
0
            public async Task AddBooksToShelves()
            {
                var shelves = new[] { "to-read", "leo" };
                var bookIds = new[] { 15823480, 656 };
                var result  = await ShelvesClient.AddBooksToShelves(shelves, bookIds);

                Assert.True(result);
            }
Exemplo n.º 4
0
            public async Task RemoveNotExistingBookFromShelf()
            {
                var shelf  = "read";
                var bookId = 1;
                var result = await ShelvesClient.AddBookToShelf(shelf, bookId, "remove");

                Assert.False(result);
            }
Exemplo n.º 5
0
            public async Task AddBookToShelf()
            {
                var shelf  = "to-read";
                var bookId = 7235533;
                var result = await ShelvesClient.AddBookToShelf(shelf, bookId);

                Assert.True(result);
            }
Exemplo n.º 6
0
            public async Task ReturnsShelves()
            {
                var userId  = 7284465;
                var shelves = await ShelvesClient.GetListOfUserShelves(userId);

                Assert.NotNull(shelves);
                Assert.NotEmpty(shelves.List);
                Assert.True(shelves.Pagination.TotalItems > 0);
            }
Exemplo n.º 7
0
            public async Task RemoveBookFromShelf()
            {
                var shelf  = "to-read";
                var bookId = 7235533;
                await ShelvesClient.AddBookToShelf(shelf, bookId);

                var result = await ShelvesClient.AddBookToShelf(shelf, bookId, "remove");

                Assert.True(result);
            }
Exemplo n.º 8
0
            public void AddExistingShelf()
            {
                const string name = "to-read";

                Assert.ThrowsAsync <ApiException>(() => ShelvesClient.AddShelf(name));
            }