public IDayWeather GetCurrentWeather(Coordinates coord) { IDayWeather currentWeather = this.history.getCurrentWeatherResponse(coord); if (currentWeather != null) { return(currentWeather); } var baseUrl = "https://api.openweathermap.org"; var url = "data/2.5/weather?" + $"lat={coord.Lat}&lon={coord.Lon}&appid={this.Key}"; using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseUrl); client.DefaultRequestHeaders.Add("User-Agent", "Anything"); client.DefaultRequestHeaders.Accept .Add(new MediaTypeWithQualityHeaderValue("application/json")); var response = client.GetAsync(url).Result; response.EnsureSuccessStatusCode(); currentWeather = response.Content.ReadAsAsync <OwmCurrentDayWeather>().Result; } this.history.addCurrentWeatherResponse(coord, currentWeather); return(currentWeather); }
public void addCurrentWeatherResponse(Coordinates coord, IDayWeather response) { var key = coord.ToString(); this.CurrentWeatherHistory.Remove(key); var val = new OwmApiCurrentWeatherResponse(); val.Date = DateTime.Now; val.Value = response; this.CurrentWeatherHistory.Add(key, val); }