//Ensuring the weather API works public WeatherAPI.root DegreeCelsius(string cityName) { try { WeatherAPI.root degree = callWeatherAPI(cityName); return(degree); } catch (Exception e) { throw new Exception($"Error while deserializing 'TyresXML.xml' to obtain a TyresTemplateConfig Template", e); } }
//Get or Retrieve data from weather API private WeatherAPI.root callWeatherAPI(string cityName) { const string APIKEY = "00de00fb067e141f266ecf6b31f2cd5e"; try { using (WebClient web = new WebClient()) { string url = string.Format("http://api.openweathermap.org/data/2.5/weather?q={0}&appid={1}", cityName, APIKEY); var json = web.DownloadString(url); var result = JsonConvert.DeserializeObject <WeatherAPI.root>(json); WeatherAPI.root output = result; return(output); } } catch (Exception e) { throw new Exception("Error in Organise Temperature and message is: " + e.Message); } }