public ResponseWeatherViewModel GetWeatherAPI() { HttpWebRequest apiRequest = WebRequest.Create("https://api.openweathermap.org/data/2.5/weather?zip=" + GetFarmerZipCode() + "," + COUNTRY_CODE + "&appid=" + apiKey + "&units=" + MEASUREMENT_UNITS) as HttpWebRequest; string apiResponse = ""; using (HttpWebResponse response = apiRequest.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(response.GetResponseStream()); apiResponse = reader.ReadToEnd(); } ResponseWeatherViewModel responseWeatherViewModel = JsonConvert.DeserializeObject <ResponseWeatherViewModel>(apiResponse); return(responseWeatherViewModel); }
// GET: WeatherAPI public ViewResult WeatherWidget() { ResponseWeatherViewModel weatherView = GetWeatherAPI(); return(View(weatherView)); }