public static async Task Main() { // Create a new WeatherAPI API client with API key. var weatherApiClient = new WeatherAPIClient(Environment.GetEnvironmentVariable("API_KEY")); var request = new ForecastRequestEntity() .WithCityName("London") .WithAlerts(true) .WithDays(5); var forecastResponse = await weatherApiClient.Forecast.GetForecastAsync(request).ConfigureAwait(false); var stringFormat = "The forecast in {0}, {1} is:"; Console.WriteLine(string.Format(stringFormat, forecastResponse.Location.Name, forecastResponse.Location.Country)); foreach (var forecast in forecastResponse.Forecast.ForecastDay) { Console.WriteLine($"{forecast.Date} - {forecast.Day.Condition.Description}"); } // Keeps the console window open at the end of the program. Console.ReadLine(); }
/// <summary> /// Gets the forecast. /// </summary> /// <param name="request">The request configuration.</param> public virtual Task <TForecastResponseEntity> GetForecastAsync <TForecastResponseEntity>(ForecastRequestEntity request, CancellationToken cancellationToken = default) where TForecastResponseEntity : class { return(ApiRequestor.RequestJsonSerializedAsync <TForecastResponseEntity>(HttpMethod.Get, "forecast.json", request.GetQueryParameters(), null, cancellationToken)); }
/// <summary> /// Gets the forecast. /// </summary> /// <param name="request">The request configuration.</param> public virtual Task <ForecastResponseEntity> GetForecastAsync(ForecastRequestEntity request, CancellationToken cancellationToken = default) { return(((IForecastOperations)this).GetForecastAsync <ForecastResponseEntity>(request, cancellationToken)); }