OpenWeatherMapAPI.ClientLibrary
2.1.0
dotnet add package OpenWeatherMapAPI.ClientLibrary --version 2.1.0
NuGet\Install-Package OpenWeatherMapAPI.ClientLibrary -Version 2.1.0
<PackageReference Include="OpenWeatherMapAPI.ClientLibrary" Version="2.1.0" />
<PackageVersion Include="OpenWeatherMapAPI.ClientLibrary" Version="2.1.0" />
<PackageReference Include="OpenWeatherMapAPI.ClientLibrary" />
paket add OpenWeatherMapAPI.ClientLibrary --version 2.1.0
#r "nuget: OpenWeatherMapAPI.ClientLibrary, 2.1.0"
#:package OpenWeatherMapAPI.ClientLibrary@2.1.0
#addin nuget:?package=OpenWeatherMapAPI.ClientLibrary&version=2.1.0
#tool nuget:?package=OpenWeatherMapAPI.ClientLibrary&version=2.1.0
OpenWeatherMapAPI
A wrapper library for OpenWeatherMap API built in .NET Core 3.1 Currently, the package supports the following endpoints:
- Current Weather Data:
- By geographic coordinates
- Air Pollution:
- By geographic coordinates
And the following API versions were tested:
- v2.5
Installation
Package Manager:
Install-Package OpenWeatherMapAPI.ClientLibrary
.NET CLI:
dotnet add package OpenWeatherMapAPI.ClientLibrary
Setup
When using dependency injection in .NET Core 3.X, you can register type like so, by registering a type in the ConfigureServices()
method. Outside of the DI registration, the OpenWeatherMapAPIClientConfiguration.APIKey
is required, and the rest of the config is optional and has default values:
Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
OpenWeatherMapAPIClientConfiguration.APIKey = "MY_API_KEY"
OpenWeatherMapAPIClientConfiguration.APIURL = "API_URL_TO_USE" // OPTIONAL
OpenWeatherMapAPIClientConfiguration.APIVersion = "API_VERSION_TO_USE" // OPTIONAL
services.AddScoped<IOpenWeatherMapAPIClient, OpenWeatherMapAPIClient>();
}
MyClass.cs:
public class MyClass
{
private readonly IOpenWeatherMapAPIClient _api;
public MyService(IOpenWeatherMapAPIClient api)
{
_api = api;
}
}
Alternatively, you don't have to inject/instantiate the whole API client and only choose services that you need, by injecting i.e. ICurrentWeatherDataService
.
You can control which version of OpenWeatherMap API you're using by providing an optional OpenWeatherMapAPIClientConfiguration.APIVersion
parameter to your global Startup
config and using OpenWeatherMapAPI.Models.Shared.Constants
class (i.e. Constants.Ver2_5
), or provide the version yourself. You can do the same with the API URL by providing a OpenWeatherMapAPIClientConfiguration.APIVersion
in your config. Similarly, this is optional as the default value is provided automatically.
Usage
The example project that uses the below code can be found under OpenWeatherMapAPI.SystemTests
. Feel free to clone and play around!
Quickstart:
OpenWeatherMapAPIClientConfiguration.APIKey = "MY_API_KEY"
var apiClient = new OpenWeatherMapAPIClient();
var currentWeather = apiClient.CurrentWeatherData;
var request = new ByGeographicCoordinatesRequest()
{
Latitude = 53.7998,
Longitude = 1.5584
};
var result = await currentWeather.ByGeographicCoordinatesAsync(request);
// {"coord":{"lon":1.5584,"lat":53.7998},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"base":"stations","main":{"temp":286.48,"feels_like":286.11,"temp_min":286.48,"temp_max":286.48,"pressure":1015,"humidity":86},"visibility":10000,"wind":{"speed":9.68,"deg":180},"clouds":{"all":100},"dt":1634563421,"sys":{"type":2,"id":2029944,"country":"GB","sunrise":1634538410,"sunset":1634575838},"timezone":0,"id":2650519,"name":"Easington","cod":200}
Testing
Some Integration and System tests are available in the repo, but make sure you update the OpenWeatherMapAPI.TestResources.BaseConstants.APIkey
constant.
Development
In order to add a new service to the library, you'll need to:
- Add a new endpoint constant in
OpenWeatherMapAPI.Models.Shared.Constants
- Add a new folder under
OpenWeatherMapAPI.Models
with your new service name. In that folder, add a POCO response class - For each method you're adding, also add a request class in the above namespace (if not existing yet)
- Add a folder under
OpenWeatherMapAPI.Services
with the new service you're adding and add a concrete class and an abstract interface. Derive your class fromAPIGateway
class. Don't call the API yourself - use your service to construct the request object you need to pass on and use theExecuteGetAsync<T>
method to do the calling for you - Add your new interface to the
OpenWeatherMapAPIClient
andIOpenWeatherMapAPIClient
as a property - Following the existing structure, add any sample requests/responses to
OpenWeatherMapAPI.TestResources
project, add integration tests inOpenWeatherMapAPI.IntegrationTests
project and a logic for system tests inOpenWeatherMapAPI.SystemTests
Deployment
Use tags for versioning. Check the current iteration (tag) and in cmd:
git checkout [test/master]
git pull
git tag v[Major].[Minor].[Patch]-[beta if test branch]
git push origin [version]
Then, push the code to test and merge into master.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Flurl.Http (>= 3.2.0)
- Newtonsoft.Json (>= 13.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
2.1.0 | 733 | 10/28/2021 |
2.1.0-beta | 302 | 10/28/2021 |
2.0.15-beta | 301 | 10/28/2021 |
2.0.9-beta | 309 | 10/28/2021 |
2.0.8-beta | 294 | 10/28/2021 |
2.0.7-beta | 299 | 10/28/2021 |
2.0.6-beta | 320 | 10/28/2021 |
2.0.5-beta | 317 | 10/28/2021 |
2.0.4-beta | 326 | 10/28/2021 |
2.0.3-beta | 316 | 10/28/2021 |
2.0.1-beta | 309 | 10/28/2021 |
2.0.0 | 400 | 10/19/2021 |
2.0.0-beta | 305 | 10/19/2021 |
1.1.0 | 417 | 10/19/2021 |
1.1.0-beta | 311 | 10/18/2021 |
1.0.0 | 453 | 10/18/2021 |