Пример #1
0
        public IHttpActionResult GetCurrentWeatherByZip(string zip)
        {
            string url = baseUrl + "weather?units=metric&appid=" + apiKey + "&zip=" + zip;

            string responseText = GetResponseText(url);

            WeatherZipResponse response = JsonConvert.DeserializeObject <WeatherZipResponse>(responseText);

            // If the response is an error, then we give only the code and the error message
            if (response.Cod != "200")
            {
                WeatherErrorResponse errorResponse = new WeatherErrorResponse {
                    Cod = response.Cod, Message = response.Message
                };
                return(Json(errorResponse));
            }

            return(Json(response));
        }
Пример #2
0
        public IHttpActionResult GetForecast(string city)
        {
            string url = baseUrl + "forecast?units=metric&appid=" + apiKey + "&q=" + city;

            string responseText = GetResponseText(url);

            WeatherForecastResponse response = JsonConvert.DeserializeObject <WeatherForecastResponse>(responseText);

            // If the response is an error, then we give only the code and the error message
            if (response.Cod != "200")
            {
                WeatherErrorResponse errorResponse = new WeatherErrorResponse {
                    Cod = response.Cod, Message = response.Message
                };
                return(Json(errorResponse));
            }

            return(Json(response));
        }