Class WeatherController
- Namespace
- SimpleWeather
- Assembly
- SimpleWeather.dll
Provides high level weather APIs backed by the OpenWeather One Call endpoints.
public class WeatherController : IDisposable
- Inheritance
-
WeatherController
- Implements
- Inherited Members
Constructors
WeatherController(string?)
Initializes a new instance of the WeatherController class.
public WeatherController(string? apiKey = null)
Parameters
apiKeystringOptional OpenWeather API key used for authenticated requests.
Methods
Dispose()
Disposes the underlying HttpClient instance and suppresses finalization.
public void Dispose()
GetCurrentWeatherAsync(LatLong, string, CancellationToken)
Asynchronously gets the current weather for the specified coordinates.
public Task<CurrentWeather> GetCurrentWeatherAsync(LatLong coordinates, string units = "metric", CancellationToken cancellationToken = default)
Parameters
coordinatesLatLongThe coordinates of the location
unitsstringUnits of measurement. Standard, metric, and imperial units are available. Default is "metric"
cancellationTokenCancellationTokenToken used to cancel the HTTP request.
Returns
- Task<CurrentWeather>
A task representing the asynchronous operation whose result is a CurrentWeather for the specified coordinates.
GetCurrentWeatherAsync(double, double, string, CancellationToken)
Returns an object that contains all the relevant data for the current weather at the specified latitude and longitude.
public Task<CurrentWeather> GetCurrentWeatherAsync(double lat, double lon, string units = "metric", CancellationToken cancellationToken = default)
Parameters
latdoubleLatitude of the location
londoubleLongitude of the location
unitsstringUnits of measurement. Standard, metric, and imperial units are available. Default is "metric"
cancellationTokenCancellationTokenToken used to cancel the HTTP request.
Returns
- Task<CurrentWeather>
A CurrentWeather object for the specified coordinates
GetCurrentWeatherAsync(string, string?, string?, string, CancellationToken)
Returns an object that contains all the relevant data for the current weather in a given city.
public Task<CurrentWeather> GetCurrentWeatherAsync(string cityName, string? stateCode = null, string? countryCode = null, string units = "metric", CancellationToken cancellationToken = default)
Parameters
cityNamestringThe name of the city
stateCodestringThe state code (optional, for US cities)
countryCodestringThe country code (optional, e.g. "US", "GB")
unitsstringUnits of measurement. Standard, metric, and imperial units are available. Default is "metric"
cancellationTokenCancellationTokenToken used to cancel the HTTP request.
Returns
- Task<CurrentWeather>
A CurrentWeather object for the specified city
GetCurrentWeatherByPostCodeAsync(string, string, string, CancellationToken)
Returns an object that contains all the relevant data for the current weather at the specified postal/zip code and country code.
public Task<CurrentWeather> GetCurrentWeatherByPostCodeAsync(string postCode, string countryCode, string units = "metric", CancellationToken cancellationToken = default)
Parameters
postCodestringThe postal or zip code
countryCodestringThe country code (e.g. "US", "GB")
unitsstringUnits of measurement. Standard, metric, and imperial units are available. Default is "metric"
cancellationTokenCancellationTokenToken used to cancel the HTTP request.
Returns
- Task<CurrentWeather>
A CurrentWeather object for the specified postal/zip code
GetWeatherForecastAsync(LatLong, string, CancellationToken)
Asynchronously gets the weather forecast for the specified coordinates.
public Task<WeatherForecast> GetWeatherForecastAsync(LatLong coordinates, string units = "metric", CancellationToken cancellationToken = default)
Parameters
coordinatesLatLongThe coordinates of the location
unitsstringUnits of measurement. Standard, metric, and imperial units are available. Default is "metric"
cancellationTokenCancellationTokenToken used to cancel the HTTP request.
Returns
- Task<WeatherForecast>
A task representing the asynchronous operation whose result is a WeatherForecast for the specified coordinates.
GetWeatherForecastAsync(double, double, string, CancellationToken)
Returns an object that contains all the relevant weather forecast data for a given latitude and longitude.
public Task<WeatherForecast> GetWeatherForecastAsync(double lat, double lon, string units = "metric", CancellationToken cancellationToken = default)
Parameters
latdoubleLatitude of the location
londoubleLongitude of the location
unitsstringUnits of measurement. Standard, metric, and imperial units are available. Default is "metric"
cancellationTokenCancellationTokenToken used to cancel the HTTP request.
Returns
- Task<WeatherForecast>
A WeatherForecast object for the specified coordinates
GetWeatherForecastAsync(string, string?, string?, string, CancellationToken)
Returns an object that contains all the relevant weather forecast data for a given city.
public Task<WeatherForecast> GetWeatherForecastAsync(string cityName, string? stateCode = null, string? countryCode = null, string units = "metric", CancellationToken cancellationToken = default)
Parameters
cityNamestringThe name of the city
stateCodestringThe state code (optional, for US cities)
countryCodestringThe country code (optional, e.g. "US", "GB")
unitsstringUnits of measurement. Standard, metric, and imperial units are available. Default is "metric"
cancellationTokenCancellationTokenToken used to cancel the HTTP request.
Returns
- Task<WeatherForecast>
A WeatherForecast object for the specified city
GetWeatherForecastByPostCodeAsync(string, string, string, CancellationToken)
Returns an object that contains all the relevant weather forecast data for the specified postal/zip code and country code.
public Task<WeatherForecast> GetWeatherForecastByPostCodeAsync(string postCode, string countryCode, string units = "metric", CancellationToken cancellationToken = default)
Parameters
postCodestringThe postal or zip code
countryCodestringThe country code (e.g. "US", "GB")
unitsstringUnits of measurement. Standard, metric, and imperial units are available. Default is "metric"
cancellationTokenCancellationTokenToken used to cancel the HTTP request.
Returns
- Task<WeatherForecast>
A WeatherForecast object for the specified postal/zip code