An asynchronous .NET 5.0 library for interacting with OpenWeatherMap
Supports:
Add the following to your service collection:
services.AddOpenWeatherMap("YOUR_ACCESS_KEY");
Then just inject IOpenWeatherMap
to use it.
OpenWeatherMap openWeatherMap = new OpenWeatherMap("YOUR_ACCESS_KEY");
Caching is built in but disabled by default. To use caching you can specify the amount of time (in seconds) you wish the call to be cached for when initializing OpenWeatherMap
. The following example will cache the call for 60 seconds.
new OpenWeatherMap("YOUR_ACCESS_KEY", 60);
var currentWeatherModel = await openWeatherMap.QueryAsync<CurrentWeatherModel>(40.12, 96.66);
var currentWeatherModel = await openWeatherMap.QueryAsync<CurrentWeatherModel>("london");
var oneCallWeatherModel = await openWeatherMap.QueryAsync<OneCallWeatherModel>(40.12, 96.66);
var currentWeatherModel = await openWeatherMap.QueryAsync<CurrentWeatherModel>(40.12, 96.66, units: Units.Metric);
var currentWeatherModel = await openWeatherMap.QueryAsync<CurrentWeatherModel>(40.12, 96.66, language: Language.Spanish);