Beispiel #1
0
        public void TestGetBooks()
        {
            ReadmillClient client = new ReadmillClient(this.clientId);

            BooksQueryOptions options = new BooksQueryOptions();
            options.CountValue = 50;

            List<Book> books = client.Books.GetBooksAsync(options).Result;

            foreach (Book book in books)
                Console.WriteLine(book.Title + " by " + book.Author);

            if (books.Count != 50)
                throw new InternalTestFailureException("Expected 5 Books. Got: " + books.Count);
        }
        public Task SearchBooksAsync(string searchString, CancellationToken cancelToken = default(CancellationToken))
        {
            BooksQueryOptions booksOptions = new BooksQueryOptions() { SearchStringValue = searchString, CountValue = 100 };

            Task<List<Book>> booksTask = client.Books.GetBooksAsync(booksOptions, cancelToken);

            return booksTask.ContinueWith(task =>
            {
                BookList = task.Result;
                ListState = State.SearchResult;
            });
        }
Beispiel #3
0
        /// <summary>
        /// Retrieves a list of books.
        /// </summary>
        /// <param name="options">Query options for retrieving the books</param>
        /// <returns></returns>
        public Task<List<Book>> GetBooksAsync(BooksQueryOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            IDictionary<string,string> parameters = GetInitializedParameterCollection();

            if (options != null)
            {
                parameters.Add(BooksQueryOptions.Count, options.CountValue.ToString());
                parameters.Add(BooksQueryOptions.SearchString, options.SearchStringValue);
            }

            //Remove extraneous parameters because Readmill doesn't like empty pairs
            IDictionary<string, string> tmpParams = new Dictionary<string, string>();
            foreach (string key in parameters.Keys)
            {
                if (!string.IsNullOrEmpty(parameters[key]))
                    tmpParams.Add(key, parameters[key]);
            }
            parameters = tmpParams;

            var booksUrl = booksUriTemplates[BooksUriTemplateType.Books].BindByName(this.readmillBaseUri, parameters);
            return GetAsync<List<Book>>(booksUrl, cancellationToken);
        }