public async Task <IActionResult> Index(int?id) { // if no pokemon id is passed in then default to first pokemon. // Below is shorter syntax logic to using a if / else statement. // coelesce expression would be == id ?? 1 to shorten below statement even more. int pokemonId = (id.HasValue) ? id.Value : 1; PokemonClient client = new PokemonClient(); PokemonResponse data = await client.GetPokemonAsync(pokemonId); var pokemon = new SinglePokedexEntry { PokedexId = data.id, Weight = data.weight, Height = data.height, ProfileImageUrl = data.sprites.front_default, Name = data.name, Abilities = new List <string>() }; foreach (var currentAbility in data.abilities) { pokemon.Abilities.Add(currentAbility.ability.name); } return(View(pokemon)); }
public async Task <PokemonDto> GetPokemon(string name, bool translate = false) { var pokemonClient = new PokemonClient(_textTranslator); //return await pokemonClient.GetPokemon(name); return(await pokemonClient.GetPokemonUsingStreams(name, translate)); }
public async Task <IActionResult> Index(int?id) { // If no PokemonID is passed in, // default to the first pokemon int pokemonId = id ?? 1; PokemonClient client = new PokemonClient(); PokemonResponse response = await client.GetPokemonAsync(pokemonId); var pokemon = new SinglePokedexEntry { PokedexId = response.id, Weight = response.weight, Height = response.height, ProfileImageUrl = response.sprites.front_default, Name = response.name, //Abilities = new List<Ability>(response.abilities) Abilities = new List <string>() }; foreach (var currAbility in response.abilities) { pokemon.Abilities.Add(currAbility.ability.name); } return(View()); }
public async Task GetPokemon() { var client = new PokemonClient(); var b = await client.GetPokemonAsync("bulbasaur"); Assert.AreEqual("bulbasaur", b.Name); Assert.AreEqual("bulbasaur", b.Species); }
public async Task GetPokemonSpecies() { var client = new PokemonClient(); var b = await client.GetPokemonSpeciesAsync("bulbasaur"); Assert.AreEqual("bulbasaur", b.Name); Assert.IsTrue(b.FlavorText.StartsWith("Bulbasaur can be seen napping")); }
public void Setup() { var client = HttpClientFactory.Create(); client.BaseAddress = new Uri("https://pokeapi.co"); client.DefaultRequestHeaders.Add("Accept", "Application/json"); client.DefaultRequestHeaders.Add("User-Agent", "Pokemon API"); pokemonClient = new PokemonClient(client, Mock.Of <ILogger <PokemonClient> >()); }
static async Task Main(string[] args) { PokemonClient client = new PokemonClient(); PokemonResponse result = await client.GetPokemonAsync(1); Console.WriteLine($"Name: {result.name}"); Console.WriteLine($"Weight: {result.weight}"); Console.WriteLine("\n\n" + "Abilities" + "\n"); foreach (var ability in result.abilities) { Console.WriteLine(ability.ability.name); Console.WriteLine($"More information at: {ability.ability.url}"); } Console.ReadKey(); }
static async Task Main(string[] args) { var client = new PokemonClient("https://graphql-pokemon.now.sh/graphql"); var data = await client.Query(); var name = (IPokemonName)data.Pokemon; Console.WriteLine(name.Name); var data2 = await client.GetPokemon(name.Name); Console.WriteLine(data2.Pokemon.Name); await client.AddPokemon(new PokemonInput() { }); }
public static async Task RequestPokemonById() { PokemonClient client = new PokemonClient(); int id; Console.Write("What is the Pokedex Number of the pokemon you are attempting to search? "); string searchtype = Console.ReadLine(); try { id = Convert.ToInt32(searchtype); PokemonResponse pr = await client.GetPokemon(id); Console.WriteLine($"{pr.name} | Pokedex No: {id}"); Console.WriteLine($"{pr.name}'s Typing's"); Console.WriteLine("====================="); foreach (var types in pr.types) { Console.WriteLine(types.type.name); } Console.WriteLine(); Console.WriteLine($"{pr.name}'s Abilites's"); Console.WriteLine("======================="); foreach (var abilities in pr.abilities) { if (!abilities.is_hidden) { Console.WriteLine("Normal Ability: " + abilities.ability.name); } else { Console.WriteLine("Hidden Ability: " + abilities.ability.name); } } Console.ReadKey(); } catch { Console.WriteLine("Sorry, but this is not a correct id or this pokemon does not exist."); Console.Write("Press Any Key To Exit...."); Console.ReadKey(); } }
public static async Task RequestPokemonByName() { PokemonClient client = new PokemonClient(); Console.Write("What is the name of the pokemon you are attempting to search for? "); string search = Console.ReadLine().ToLower(); try { PokemonResponse pr = await client.GetPokemon(search); Console.WriteLine($"{pr.name} | Pokedex No: {pr.id}"); Console.WriteLine($"{pr.name}'s Typing's"); Console.WriteLine("====================="); foreach (var types in pr.types) { Console.WriteLine(types.type.name); } Console.WriteLine(); Console.WriteLine($"{pr.name}'s Abilites's"); Console.WriteLine("======================="); foreach (var abilities in pr.abilities) { if (!abilities.is_hidden) { Console.WriteLine("Normal Ability: " + abilities.ability.name); } else { Console.WriteLine("Hidden Ability: " + abilities.ability.name); } } Console.ReadKey(); } catch { Console.WriteLine("Sorry, but the pokemon you attempted to search for does not exist or spelling error's were made."); Console.Write("Press Any Key To Exit...."); Console.ReadKey(); } }
public PokemonController(PokemonClient _client) { client = _client; }