public async Task <ActionResult <ShakespeareResult> > Get([FromRoute] string pokemonName, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(pokemonName)) { return(BadRequest("Poke name required.")); } ShakespeareResult shakespeareResult = null; _logger.LogInformation("Pokemon API invoke started"); var pokemonResult = await _pokemonApiService.GetByName(pokemonName, cancellationToken).ConfigureAwait(false); _logger.LogInformation("Pokemon API invoke finished"); if (pokemonResult != null && pokemonResult.Text.Length > 0) { _logger.LogInformation("Shakespeare API invoke started"); var shakespeareApiResult = await _shakespeareApiService.Translate(System.Web.HttpUtility.HtmlEncode(pokemonResult.Text)); _logger.LogInformation("Shakespeare API invoke finished"); if (shakespeareApiResult != null) { shakespeareResult = new ShakespeareResult { Name = pokemonName, Description = shakespeareApiResult.Contents.Translated }; } } return(shakespeareResult is null ? (ActionResult <ShakespeareResult>)NotFound() : Ok(shakespeareResult)); }
public async Task <IPokemonModel> Translate( string pokemonName, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(pokemonName)) { throw new ArgumentNullException("Value cannot be null or whitespace.", nameof(pokemonName)); } IPokemon pokemon = await _pokemonApiService.GetByName(pokemonName, cancellationToken) .ConfigureAwait(false); if (pokemon is null) { return(default);