Ejemplo n.º 1
0
        public override async Task <WeatherData> GetDataAsync(CancellationToken cancellationToken)
        {
            var response = await _httpClient.GetAsync($"https://api.openweathermap.org/data/2.5/weather?id={_cityId}&appid={_apiKey}&units=metric", cancellationToken);

            if (response.IsSuccessStatusCode)
            {
                var info = JsonSerializer.Deserialize <WeatherInfoJson>(await response.Content.ReadAsStringAsync());
                return(new WeatherData(info.Temperature, info.Humidity, Status.OK));
            }

            return(WeatherData.Error($"Code: {response.StatusCode}"));
        }