Table of Contents

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

apiKey string

Optional 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

coordinates LatLong

The coordinates of the location

units string

Units of measurement. Standard, metric, and imperial units are available. Default is "metric"

cancellationToken CancellationToken

Token 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

lat double

Latitude of the location

lon double

Longitude of the location

units string

Units of measurement. Standard, metric, and imperial units are available. Default is "metric"

cancellationToken CancellationToken

Token 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

cityName string

The name of the city

stateCode string

The state code (optional, for US cities)

countryCode string

The country code (optional, e.g. "US", "GB")

units string

Units of measurement. Standard, metric, and imperial units are available. Default is "metric"

cancellationToken CancellationToken

Token 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

postCode string

The postal or zip code

countryCode string

The country code (e.g. "US", "GB")

units string

Units of measurement. Standard, metric, and imperial units are available. Default is "metric"

cancellationToken CancellationToken

Token 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

coordinates LatLong

The coordinates of the location

units string

Units of measurement. Standard, metric, and imperial units are available. Default is "metric"

cancellationToken CancellationToken

Token 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

lat double

Latitude of the location

lon double

Longitude of the location

units string

Units of measurement. Standard, metric, and imperial units are available. Default is "metric"

cancellationToken CancellationToken

Token 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

cityName string

The name of the city

stateCode string

The state code (optional, for US cities)

countryCode string

The country code (optional, e.g. "US", "GB")

units string

Units of measurement. Standard, metric, and imperial units are available. Default is "metric"

cancellationToken CancellationToken

Token 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

postCode string

The postal or zip code

countryCode string

The country code (e.g. "US", "GB")

units string

Units of measurement. Standard, metric, and imperial units are available. Default is "metric"

cancellationToken CancellationToken

Token used to cancel the HTTP request.

Returns

Task<WeatherForecast>

A WeatherForecast object for the specified postal/zip code