Beispiel #1
0
        private async Task <OmdbSearchResults> GetSearchResultsFromResponseAsync(HttpResponseMessage response)
        {
            OmdbSearchResults results = null;
            string            json    = await response.Content.ReadAsStringAsync();

            try
            {
                results = JsonSerializer.Deserialize <OmdbSearchResults>(json);
            }
            catch (Exception e)
            {
                throw;
            }
            return(results);
        }
Beispiel #2
0
        public async Task <ICollection <Movie> > SearchAsync(string searchTag, int?year = null)
        {
            using (var client = new HttpClient())
            {
                string url = baseUrl + $"&s={searchTag}";
                if (year != null)
                {
                    url += $"&y={year}";
                }
                try
                {
                    HttpResponseMessage response = await client.GetAsync(url);

                    OmdbSearchResults results = await GetSearchResultsFromResponseAsync(response);

                    return(results.ConvertToMovies());
                }
                catch (Exception e)
                {
                    // TODO: Log
                    return(null);
                }
            }
        }