예제 #1
0
        public async Task <Root> GetForecast(string city, string state = null, string isoCountryCode = null)
        {
            if (string.IsNullOrWhiteSpace(city))
            {
                throw new ArgumentNullException(nameof(city), "City name must be provided");
            }

            state ??= _config.State;
            isoCountryCode ??= _config.IsoCountryCode;

            var url = _urlBuilder.BuildWeatherUrl(city, state, isoCountryCode);
            var res = await _client.GetAsync(url);

            if (!res.IsSuccessStatusCode)
            {
                throw new OpenWeatherClientException(res);
            }

            var jsonContent = await res.Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <Root>(jsonContent));
        }