Ejemplo n.º 1
0
        public override async Task <WeatherResponse> GetWeather(string city, string country)
        {
            var request = new OpenWeatherRequest()
            {
                City = city,
                Key  = weatherServiceOptions.Key
            };

            var response = await webProvider
                           .RequestGetAsync <OpenWeatherResponse>(weatherServiceOptions.Url, request);

            if (response == null)
            {
                throw new Exception(ErrorCodes.CITY_NOT_FOUND.ToString());
            }

            return(new WeatherResponse(response.Main.Temperature, response.Wind.Speed, (int)response.Wind.Direction,
                                       DateTimeOffset.FromUnixTimeSeconds(response.EpochTime).DateTime, WeatherServicesList.OpenWeatherMap));
        }
 public async Task <ServiceResult <OpenWeatherResponse> > GetCurrentWeatherForecast(OpenWeatherRequest request, CancellationToken cancellationToken)
 {
     return(await _httpClient.GenericRequest <OpenWeatherRequest, OpenWeatherResponse>(ClientApi, string.Concat("weather?", StringExtensions
                                                                                                                .ParseObjectToQueryString(request, true)), cancellationToken, MethodType.Get, request));
 }