Beispiel #1
0
        /// <summary>
        /// Get weather information by name
        /// </summary>
        /// <typeparam name="T">Generic parameter</typeparam>
        /// <param name="cityName">The city name</param>
        /// <param name="units">The units</param>
        /// <param name="language">The language</param>
        /// <returns>Information about weather</returns>
        internal async Task <T> GetByName <T>(string cityName, Units units = Units.Standard, Language language = Language.en)
        {
            ArgumentValidator.ArgumentStringNotEmpty(cityName, "cityName");

            var requestUrl = OpenWeatherMapUrl + "?q=" + cityName + "&appid=" + ApiKey + AddMetricSystem(units) + AddLanguage(language);

            var response = GetRequest(requestUrl);

            var stringResponse = await response.Content.ReadAsStringAsync();

            var weather = JObject.Parse(stringResponse).ToObject <T>();

            return(weather);
        }