static async Task Main() { PokeApiClient client = new PokeApiClient(); try { // Pokemon result = await client.GetPokemonByName("BULBASAUR"); Pokemon result = await client.GetPokemonById(1); Console.WriteLine($"Pokemon Id: {result.Id}" + $"\nName: {result.Name}" + $"\nWeight (in hectograms): {result.Weight}" + $"\nHeight (in inches): {result.Height}"); } catch (ArgumentException) { Console.WriteLine("I'm sorry, that Pokemon does not exist"); } catch (HttpRequestException) { Console.WriteLine("Please try again later."); } Console.ReadKey(); }
static async Task Main(string[] args) { PokeApiClient client = new PokeApiClient(); try { //Pokemon result = await client.GetPokemonByName("Bulbasaur"); Pokemon result = await client.GetPokemonById(1); Console.WriteLine($"Pokemon ID: {result.Id} " + $"\n Name: {result.Name} " + $"\n Weight: {result.Weight}lbs" + $"\n Height: {result.Height}in"); } catch (ArgumentException) { Console.WriteLine("That Pokemon does not exist"); } catch (HttpRequestException) { Console.WriteLine("Please try again later."); } Console.ReadKey(); }
/// <summary> /// Get pokemon by id /// Moves will be sorted in alphabetical order /// </summary> /// <param name="desiredId"></param> /// <returns></returns> public static async Task <Pokemon> GetById(int desiredId) { PokeApiClient myClient = new PokeApiClient(); Pokemon result = await myClient.GetPokemonById(desiredId); result.moves.OrderBy(m => m.move.name); return(result); }
/// <summary> /// Get Pokemon by ID, /// moves will be sorted alphabetically. /// </summary> /// <param name="id"></param> /// <returns></returns> public static async Task <Pokemon> GetByID(int id) { PokeApiClient myClient = new PokeApiClient(); Pokemon result = await myClient.GetPokemonById(id); // sorts moves by name, alphabetically result.moves.OrderBy(m => m.move.name); return(result); }
/// <summary> /// Get a pokemon by id, moves will be sorted in alphabetical order /// </summary> /// <param name="desiredId"></param> /// <returns></returns> public static async Task <Pokemon> GetById(int desiredId) { //Instantiate a PokeApiClient to access the client class PokeApiClient myClient = new PokeApiClient(); //Get a pokemon by it's id Pokemon result = await myClient.GetPokemonById(desiredId); //Sort moves by name alphabetically result.moves.OrderBy(m => m.move.name); return(result); }
static async Task Main() { PokeApiClient client = new PokeApiClient(); try { //Pokemon result = await client.GetPokemonByName("charizard"); Pokemon result = await client.GetPokemonById(6); Console.WriteLine($"Pokemon Id: {result.Id} \n" + $"Name: {result.Name} \n" + $"Weight: {result.Weight} Hectograms\n" + $"Height: {result.Height} Inches"); Console.ReadKey(); } catch (ArgumentException) { Console.WriteLine("That pokemon does not exist"); } catch (HttpRequestException) { Console.WriteLine("Please try again later"); } }