Example #1
0
        public async Task <BookValuation> GetBooksAsync(string title)
        {
            var composer = new HttpBookRequestComposer(title);

            if (!composer.IsCorrectRequest)
            {
                await HttpRequestComposer.DisplayAlertAsync();

                return(null);
            }
            try
            {
                var response = await _httpClient.GetAsync(composer.UrlRequest);

                if (!response.IsSuccessStatusCode)
                {
                    return(HandleNotSuccessfulResponse());
                }
                var content = await response.Content.ReadAsStringAsync();

                _bookValuation = JsonSerializer.Deserialize <BookValuation>(content);
                UnitOfWork.Books.SaveItems(_bookValuation?.Books);
                return(_bookValuation);
            }
            catch (Exception e)
            {
                return(HandleNotSuccessfulResponse());
            }
        }
Example #2
0
        public async Task <ICollection <Hit> > GetImagesAsync()
        {
            var composer = new HttpImageRequestComposer();

            if (!composer.IsCorrectRequest)
            {
                await HttpRequestComposer.DisplayAlertAsync();

                return(null);
            }

            var response = await _httpClient.GetAsync(composer.UrlRequest);

            if (!response.IsSuccessStatusCode)
            {
                var list = UnitOfWork.Hits.GetItems();
                if (list is not null)
                {
                    return(list);
                }
                HttpResponseHelper.DisplayNotSuccessfulStatusCodeAlert(response);
                return(null);
            }

            var content = await response.Content.ReadAsStringAsync();

            var hits = JsonSerializer.Deserialize <GalleryResponse>(content)?.Hits;

            UnitOfWork.Hits.SaveItems(hits);
            return(hits);
        }