Ejemplo n.º 1
0
        public OpenWeatherMapApi(WeatherApiRequest weatherApiRequest)
        {
            _weatherApiRequest = weatherApiRequest;

            if (_weatherApiRequest.NoOfDays < 0 || _weatherApiRequest.NoOfDays > 5)
            {
                throw new Exception(Constants.MAX_NUMBER_OF_DAYS_SUPPORTED_ERROR);
            }
        }
Ejemplo n.º 2
0
        private IWeatherApi GetWeatherApi()
        {
            WeatherApiRequest weatherApiRequest = new WeatherApiRequest()
            {
                ApiKey                  = _appsettingsManager.ApiKey,
                NoOfDays                = _appsettingsManager.NumberOfDays,
                HotWeatherThreshold     = _appsettingsManager.HotWeatherThreshold,
                MessageForRain          = _appsettingsManager.MessageForRain,
                MessageForHotWeather    = _appsettingsManager.MessageForHotWeather,
                MessageForNormalWeather = _appsettingsManager.MessageForNormalWeather
            };

            return(new WeatherApiFactory().GetWeatherApi(_appsettingsManager.ExternalWeatherApiName, weatherApiRequest));
        }
Ejemplo n.º 3
0
        public IWeatherApi GetWeatherApi(string externalWeatherApiName, WeatherApiRequest weatherApiRequest)
        {
            if (weatherApiRequest == null)
            {
                throw new ArgumentNullException("weatherApiRequest", "weatherApiRequest is a required parameter.");
            }

            switch (externalWeatherApiName)
            {
            case "OpenWeatherMap":
                _weatherApi = new OpenWeatherMapApi(weatherApiRequest);
                break;

            default:
                throw new Exception(string.Format("External Weather API {0} is not supported.", externalWeatherApiName));
            }
            return(_weatherApi);
        }
Ejemplo n.º 4
0
        public IActionResult GetFeature([FromQuery] WeatherApiRequest req)
        {
            var features = new FeatureRepository(_fmiService).GetSnowDepthAndTemperature(req.city, req.startTime, req.endTime);

            return(Ok(features));
        }