예제 #1
0
        public override async Task <(WeatherOutputModel, string)> GetCurrentWeather(string country, string city)
        {
            try
            {
                using var client = new HttpClient();
                var response =
                    await client.GetAsync($"{_config.BaseURL}?appid={_config.AppId}&q={city},{country}&units={_config.Units.ToString()}");

                if (!response.IsSuccessStatusCode)
                {
                    return(null, ErrorMessages.CannotGetWeatherData("OpenWeatherMap", $"{city},{country}"));
                }

                var content = await response.Content.ReadAsStringAsync();

                return(TransformResponse(content));
            }
            catch (Exception)
            {
                return(null, ErrorMessages.UncaughtError);
            }
        }
예제 #2
0
        public override async Task <(WeatherOutputModel, string)> GetCurrentWeather(string country, string city)
        {
            try
            {
                using var client = new HttpClient();
                var response =
                    await client.GetAsync($"{_config.BaseURL}?access_key={_config.AccessToken}&query={city}&units={GetUnitsParametrer(_config.Units)}");

                if (!response.IsSuccessStatusCode)
                {
                    return(null, ErrorMessages.CannotGetWeatherData("WeatherStack", city));
                }

                var content = await response.Content.ReadAsStringAsync();

                return(TransformResponse(content));
            }
            catch (Exception)
            {
                return(null, ErrorMessages.UncaughtError);
            }
        }