Exemplo n.º 1
0
        public async Task <WeatherForecast> GetForecast(double latitude, double longitude, int days)
        {
            UriBuilder builder = new UriBuilder(_baseEndpoint)
            {
                Path  = "v2.0/forecast/daily",
                Query = $"lat={latitude.ToString(CultureInfo.InvariantCulture)}&lon={longitude.ToString(CultureInfo.InvariantCulture)}&units={_unit}&days={days}&lang={_lang}&key={_serviceKey}"
            };

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

            WeatherbitMapper weatherbitMapper = new WeatherbitMapper();
            WeatherForecast  weatherForecast  = weatherbitMapper.ToDomainEntities(weatherResponse);

            return(weatherForecast);
        }
Exemplo n.º 2
0
        public async Task <WeatherForecast> GetForecast(string city, int days)
        {
            UriBuilder builder = new UriBuilder(_baseEndpoint)
            {
                Path  = "v2.0/forecast/daily",
                Query = $"city={city}&units={_unit}&days={days}&lang={_lang}&key={_serviceKey}"
            };

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

            WeatherbitMapper weatherbitMapper = new WeatherbitMapper();
            WeatherForecast  weatherForecast  = weatherbitMapper.ToDomainEntities(weatherResponse);

            return(weatherForecast);
        }
Exemplo n.º 3
0
        public WeatherForecast ToDomainEntities(WeatherbitForecastDTO weatherbitForecastDTO)
        {
            List <Weather> weatherList = new List <Weather>();

            foreach (var forecastWeather in weatherbitForecastDTO.data)
            {
                weatherList.Add(ToWeather(forecastWeather));
            }

            var city = ToWeatherCity(weatherbitForecastDTO);

            return(new WeatherForecast {
                City = city, WeatherList = weatherList
            });
        }