Beispiel #1
0
 private static void DisplaySearchResults(WeatherAPIResult model)
 {
     Console.WriteLine($"\nTemperature (F): {model.Main.Temperature}");
     Console.WriteLine($"Humidity: {model.Main.Humidity}%");
     Console.WriteLine($"Pressure: {model.Main.Pressure}");
     Console.WriteLine("\nPress any key to continue...");
     Console.ReadKey();
 }
Beispiel #2
0
        private static void DoWeatherSearch(string zipcode, string apiKey)
        {
            WeatherAPIResult model = null;

            HttpClient client = new HttpClient();

            string uri = $"http://api.openweathermap.org/data/2.5/weather?" +
                         $"zip={zipcode},us&units=imperial&appid={apiKey}";

            var task = client.GetAsync(uri)
                       .ContinueWith((taskForResponse) =>
            {
                HttpResponseMessage response = taskForResponse.Result;
                var processJson = response.Content.ReadAsAsync <WeatherAPIResult>();
                processJson.Wait();
                model = processJson.Result;
            });

            task.Wait();
            DisplaySearchResults(model);
        }