Пример #1
0
        public BookData FindBookById(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new ArgumentNullException("id");
            }
            BookData book = new BookData();
            var getUri = baseUrl + @"/" + id;

            using (var webClient = new GZipWebClient())
            {
                book = JsonConvert.DeserializeObject<BookData>(webClient.DownloadString(getUri));
            }

            return book;
        }
Пример #2
0
        public BooksData FindBooksByTitle(string title, int startIndex = 0, int maxResults = 10)
        {
            if (string.IsNullOrEmpty(title))
            {
                throw new ArgumentNullException("title");
            }

            BooksData books = new BooksData();

            var getUri = searchBaseUrl + Uri.EscapeDataString(title) + itemFields + sort + @"&startIndex=" + startIndex + @"&maxResults=" + maxResults;

            using (var webClient = new GZipWebClient())
            {
                books = JsonConvert.DeserializeObject<BooksData>(webClient.DownloadString(getUri));
            }

            return books;
        }
Пример #3
0
        public BookData FindBookByIsbn(string isbn)
        {
            if (string.IsNullOrEmpty(isbn))
            {
                throw new ArgumentNullException("isbn");
            }
            BookData book = new BookData();
            var getUri = searchBaseUrl + "isbn:" + isbn;

            using (var webClient = new GZipWebClient())
            {
                var books = JsonConvert.DeserializeObject<BooksData>(webClient.DownloadString(getUri));
                if (books.TotalItems == 1)
                {
                    book = books.Items[0];
                }
            }

            return book;
        }
Пример #4
0
        public int FindBooksTotalItemsByTitleAndAuthor(string title, string author)
        {
            if (string.IsNullOrEmpty(title))
            {
                throw new ArgumentNullException("title");
            }
            if (string.IsNullOrEmpty(author))
            {
                throw new ArgumentNullException("title");
            }

            int totalItems = 0;

            var getUri = searchBaseUrl + Uri.EscapeDataString(title) + "+inauthor:" + Uri.EscapeDataString(author) + totalItemsField;

            using (var webClient = new GZipWebClient())
            {
                totalItems = JsonConvert.DeserializeObject<BooksData>(webClient.DownloadString(getUri)).TotalItems;
            }

            return totalItems;
        }