public async Task <WeatherInfo> GetWeatherInfoAsync(GeoCoords coords) { string url = CreateWeatherQuery(coords); JObject data = null; using (var client = new HttpClient()) { var response = await client.GetAsync(url); var content = await response.Content.ReadAsStringAsync(); data = JObject.Parse(content); } JObject main = (JObject)data.GetValue("main"); double?clouds = ((JObject)data.GetValue("clouds")).GetValue("all").Value <double?>(); double?humidity = main.GetValue("humidity").Value <double?>(); double?pressure = main.GetValue("pressure").Value <double?>(); double?temperature = main.GetValue("temp").Value <double?>(); return(new WeatherInfo { Coordinates = coords, Clouds = clouds, Humidity = humidity, Perssure = pressure, Temperature = temperature, }); }
private string CreateWeatherQuery(GeoCoords coords) { return(CreateAuthenticatedQuery($"http://api.openweathermap.org/data/2.5/weather?lat={coords.Latitude}&lon={coords.Longitude}")); }