static async Task RunAsync() { Options opt = RunMenu(); string url = GetRequestURL(opt); try { if (opt.type == "weather?") //<- this is filled in at menu { WeatherCurrentMessage msg = await GetCurrentWeatherAsync(url); ShowWeather(msg); } else { WeatherForecastMessage msg = await GetForecastWeatherAsync(url); ShowWeather(msg); } } catch (Exception e) { Console.WriteLine(e.Message); } }
static async Task <WeatherForecastMessage> GetForecastWeatherAsync(string path) { WeatherForecastMessage weather = null; var uri = new Uri(path); HttpResponseMessage response = await http.GetAsync(uri.AbsoluteUri); if (response.IsSuccessStatusCode) { weather = await response.Content.ReadAsAsync <WeatherForecastMessage>(); } return(weather); }
static void ShowWeather(WeatherForecastMessage weather) { Console.Clear(); Console.WriteLine("Forecast Weather =>"); Console.WriteLine($"Name: {weather.city.name}, Date: {epoch2string(weather.list[0].dt)}, Length: {weather.list.Length}"); }