public async Task <TranslatedResponse> TranslateToShakespearStyleAsync(string pokemonName)
        {
            if (string.IsNullOrWhiteSpace(pokemonName))
            {
                throw new ApplicationException("Pokemon name must be passed in the URI as a parameter.");
            }

            PokemonDetail details = await this.pokemonAPIService.GetPokemanDetailsAsync(pokemonName);

            PokemonSpeciesDetail speciesDetail = await this.pokemonAPIService.GetPokemanSpeciesDetailsAsync(details.Species.Url.PathAndQuery);

            string description = speciesDetail.FlavorTextEntries.FirstOrDefault(x => x.Version.Name == "ruby")?.FlavorText.Replace("\n", "").Replace("\r", "");

            if (string.IsNullOrWhiteSpace(description))
            {
                throw new ApplicationException($"No details found for Pokemon {pokemonName}");
            }

            TranslateResponse translateResponse = await this.translateAPIService.GetShakespeareDescriptionAsync(description);

            TranslatedResponse translatedResponse = this.mapper.Map <TranslatedResponse>(translateResponse);

            translatedResponse.Name = pokemonName;

            return(translatedResponse);
        }
Esempio n. 2
0
        private async void LoadDetails(string url)
        {
            using (HttpClient http = new HttpClient())
            {
                HttpResponseMessage message = await http.GetAsync(url);

                if (message.IsSuccessStatusCode)
                {
                    string content = await message.Content.ReadAsStringAsync();

                    Selected      = JsonConvert.DeserializeObject <PokemonDetail>(content);
                    LbNom.Content = Selected.Name;
                }
            }
        }
 public DetailsPage(PokemonDetail details)
 {
     InitializeComponent();
     BindingContext = details;
 }