Пример #1
0
        public async Task <PokeAPIPokemon> GetPokemonByNameAsync(string name)
        {
            HttpClient http = new HttpClient();

            HttpResponseMessage pokemonByNameReq = await http.GetAsync("https://pokeapi.co/api/v2/pokemon/" + name);

            if (pokemonByNameReq.IsSuccessStatusCode)
            {
                string resBody = await pokemonByNameReq.Content.ReadAsStringAsync();

                PokeAPIPokemon requestedPokemon = JsonConvert.DeserializeObject <PokeAPIPokemon>(resBody);

                return(requestedPokemon);
            }
            return(new PokeAPIPokemon());
        }
Пример #2
0
        static void Main(string[] args)
        {
            //SWAPIHelper swapiHelper = new SWAPIHelper();
            //// SWAPI
            //// Create a method in SWAPI Helper that gets a vehicle's name, mass, and cost by ID
            //SWAPIVehicleModel sandCrawler = swapiHelper.GetVehicleByIDAsync(4).Result;

            //Console.WriteLine(sandCrawler.Name);
            //Console.WriteLine(sandCrawler.Model);
            //Console.WriteLine(sandCrawler.Cost_In_Credits);



            // PokeAPI
            // Create a PokeAPIHelper class that can get a pokemon's name, weight, and height by it's name
            PokeAPIHelper pokeAPIHelper = new PokeAPIHelper();

            PokeAPIPokemon empoleon = pokeAPIHelper.GetPokemonByNameAsync("empoleon").Result;

            Console.WriteLine(empoleon.Name);
            Console.WriteLine(empoleon.Height);
            Console.WriteLine(empoleon.Weight);



            //SWAPIPerson lukeSkywalker = swapiHelper.GetPersonByIDAsync(1).Result;

            //Console.WriteLine("Name: " + lukeSkywalker.Name);
            //Console.WriteLine("Height: " + lukeSkywalker.Height);
            //Console.WriteLine("Mass: " + lukeSkywalker.Mass);

            //Console.ReadKey();

            // Get people and starships by ID
            Console.ReadKey();
        }