Пример #1
0
        public async Task <WeatherData> GetWeather(double latitude, double longitude)
        {
            UriBuilder builder = new UriBuilder(_baseEndpoint)
            {
                Path  = $"forecast/{_serviceKey}/{latitude.ToString(CultureInfo.InvariantCulture)},{longitude.ToString(CultureInfo.InvariantCulture)}",
                Query = $"exclude=[minutely,hourly,daily,alerts,flags]&units={_unit}&lang={_lang}"
            };

            DarkskyDTO weatherResponse = await _requestService.GetAsync <DarkskyDTO>(builder.Uri);

            DarkskyMapper darkskyMapper = new DarkskyMapper();
            WeatherData   weather       = darkskyMapper.ToDomainEntity(weatherResponse, _runtimeContext.CityName);

            return(weather);
        }
Пример #2
0
        public async Task <WeatherForecast> GetForecast(double latitude, double longitude, int days)
        {
            UriBuilder builder = new UriBuilder(_baseEndpoint)
            {
                Path  = $"forecast/{_serviceKey}/{latitude.ToString(CultureInfo.InvariantCulture)},{longitude.ToString(CultureInfo.InvariantCulture)}",
                Query = $"exclude=[currently,minutely,hourly,alerts,flags]&units={_unit}&lang={_lang}"
            };

            DarkskyForecastDTO weatherResponse = await _requestService.GetAsync <DarkskyForecastDTO>(builder.Uri);

            DarkskyMapper   darkskyMapper   = new DarkskyMapper();
            WeatherForecast weatherForecast = darkskyMapper.ToDomainEntities(weatherResponse, _runtimeContext.CityName);

            var indexOfTodaysWeahterItem = weatherForecast.WeatherList.FindIndex(x => x.Date.Date == DateTime.Now.Date);

            weatherForecast.WeatherList = weatherForecast.WeatherList.GetRange(indexOfTodaysWeahterItem, days);

            return(weatherForecast);
        }