示例#1
0
        public List <PocoBook> FetchBookInfo(PocoBook book)
        {
            if (PocoBook.IsNullOrEmpty(book))
            {
                throw new ArgumentNullException(nameof(book), "Book cannot be null.");
            }

            Uri myquery = CreateQueryOnBook(book);

            Rootobject root = ExecuteGoogleRequest(myquery);

            root.File = new FileInfo(book.File);

            return(FetchBooksInfoFromResponse(root));
        }
示例#2
0
        private Uri CreateQueryOnBook(PocoBook book)
        {
            if (PocoBook.IsNullOrEmpty(book))
            {
                throw new ArgumentNullException(nameof(book), "Book cannot be null or empty");
            }

            string endpoint = "https://www.googleapis.com/books/v1/volumes?q=###&maxResults=40&country=IT";

            string query;

            if (!string.IsNullOrEmpty(book.Isbnsearch))
            {
                query    = "isbn:" + book.Isbnsearch.Replace("-", "").Replace("ISBN", "", true, null).Replace(" ", "");
                endpoint = endpoint.Replace("###", query);
                return(new Uri(endpoint));
            }

            if (!string.IsNullOrEmpty(book.SearchPhrase))
            {
                query    = string.Format(" \"{0}\" ", book.SearchPhrase);
                endpoint = endpoint.Replace("###", query);
                return(new Uri(endpoint));
            }

            if (book.Authors == null || book.Authors.Count == 0)
            {
                query    = string.Format("intitle:{0}", book.SearchTitle);
                endpoint = endpoint.Replace("###", query);
                return(new Uri(endpoint));
            }

            query    = string.Format("intitle:{0}&inauthor:{1}", book.SearchTitle, string.Join(", ", book.Authors));
            endpoint = endpoint.Replace("###", query);
            return(new Uri(endpoint));
        }