Exemplo n.º 1
0
        public async Task <GetMultipleResponse <Movie> > DiscoverMoviesAsync(DiscoverMoviesRequest request)
        {
            return(await ExecuteAsync <GetMultipleResponse <Movie> >(request, async response =>
            {
                var uriQuery = $"api_key={_v3Key}&page={request.page}&with_genres={string.Join(',', request.genres.ToArray())}&include_adult={request.includeAdult}&language={request.language}&region={request.region}";
                var getResponse = await _httpClient.GetAsync($"{_baseAddress}/discover/movie?{uriQuery}");

                if (getResponse.IsSuccessStatusCode)
                {
                    var tmdbResponse = JsonConvert.DeserializeObject <TMDbResponse <Movie> >(await getResponse.Content.ReadAsStringAsync());;
                    response.Page = tmdbResponse.page;
                    response.Results = tmdbResponse.results;
                    response.TotalPages = tmdbResponse.total_pages;
                    //response.TotalResults = tmdbResponse.total_results;
                }
                else
                {
                    throw new ApiException(await getResponse.Content.ReadAsStringAsync(), statusCode: (int)getResponse.StatusCode);
                }
            }));
        }
Exemplo n.º 2
0
 public async Task <IActionResult> DiscoverMovies([FromQuery, FromRoute] DiscoverMoviesRequest request)
 {
     return(Ok(await _client.DiscoverMoviesAsync(request)));
 }