コード例 #1
0
        private async Task <OpenWeatherOneCallDomainModel> GetOneCallApiDataModel(int zipcode)
        {
            //ToDo: Get Lat, Lon from zipcode
            string latitude  = "48.14";
            string longitude = "11.58";
            string language  = "de";

            _url = $"https://api.openweathermap.org/data/2.5/onecall?lat={latitude}&lon={longitude}&lang={language}&appid={_apiKey}";

            try
            {
                HttpResponseMessage response = await _httpClient.GetAsync(_url);

                if (response.IsSuccessStatusCode)
                {
                    var json = await response.Content.ReadAsStringAsync();

                    var weatherForecastModel = JsonConvert.DeserializeObject <OpenWeatherOneCallApiDataModel>(json);
                    OpenWeatherOneCallDomainModel openWeatherOneCallDomainModel = new OpenWeatherOneCallDomainModel();
                    openWeatherOneCallDomainModel.HourlyValuesDomainModel   = GetHourlyValuesDomainModelFromOneCallApiDataModel(weatherForecastModel);
                    openWeatherOneCallDomainModel.ThreeDayValuesDomainModel = GetThreeDayValuesDomainModelFromOneCallApiDataModel(weatherForecastModel);
                    openWeatherOneCallDomainModel.FourteenDayValuesDomain   = GetFourteenDayValuesDomainModelFromOneCallApiDataModel(weatherForecastModel);
                    return(openWeatherOneCallDomainModel);
                }
                else
                {
                    throw new HttpRequestException(response.ReasonPhrase);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #2
0
 private async Task GetOpenWeatherOneCallDomainModel(int zipcode)
 {
     _openWeatherOneCallDomainModel = await GetOneCallApiDataModel(zipcode);
 }