コード例 #1
0
        public async Task <IEnumerable <BookDetails> > SearchAsync(InternetBookSearchParams searchParams)
        {
            _uriHelper = new GoogleUriHelper(searchParams, _apiKey);
            string requestUri = _uriHelper.GetUri();

            var response = await _client.GetAsync(requestUri);

            response.EnsureSuccessStatusCode();
            string responseBody = await response.Content.ReadAsStringAsync();

            var result = JsonSerializer
                         .Deserialize <JsonBooksModel>(
                responseBody,
                options: new JsonSerializerOptions()
            {
                PropertyNameCaseInsensitive = true
            });

            return(result.Items.Select(b => new BookDetails()
            {
                Title = b.VolumeInfo.Title,
                Summary = b.VolumeInfo.Description,
                Authors = b.VolumeInfo.Authors,
                Isbn10 = b.VolumeInfo.IndustryIdentifiers.FirstOrDefault(i => i.Type == "ISBN_10")?.Identifier,
                Isbn13 = b.VolumeInfo.IndustryIdentifiers.FirstOrDefault(i => i.Type == "ISBN_13")?.Identifier,
                Thumbnail = b.VolumeInfo.ImageLinks?.SmallThumbnail,
                PageCount = b.VolumeInfo.PageCount,
                Publisher = b.VolumeInfo.Publisher,
                Languages = new List <string>()
                {
                    b.VolumeInfo.Language
                }
            }));
        }
コード例 #2
0
        public async Task <IEnumerable <BookDetails> > Find([FromQuery] InternetBookSearchParams searchParams)
        {
            var result = new List <BookDetails>();

            foreach (var service in internetBookServices)
            {
                var books = await service.SearchAsync(searchParams);

                result.AddRange(books);
            }
            return(result);
        }
コード例 #3
0
 public GoogleUriHelper(InternetBookSearchParams searchParams, string apiKey)
 {
     this._apiKey       = apiKey;
     this._searchParams = searchParams;
 }