Beispiel #1
0
 private static void ValidateWeatherData(WeatherServiceVM weatherData)
 {
     if (null == weatherData || null == weatherData.Main)
     {
         throw new Exception("Weather data not found.");
     }
 }
Beispiel #2
0
        public int GetTemperatureByLocation(string locale)
        {
            string url    = $@"{this._url}?q={locale}&appid={this._openWeatherApiKey}&units=metric";
            var    client = new RestClient(url);

            client.Timeout = -1;
            var           request  = new RestRequest(Method.GET);
            IRestResponse response = client.Execute(request);

            if (response.IsSuccessful)
            {
                WeatherServiceVM weatherData = JsonConvert.DeserializeObject <WeatherServiceVM>(response.Content);
                ValidateWeatherData(weatherData);

                return(weatherData.Main.temp);
            }
            else
            {
                throw new Exception(response.Content);
            }
        }