WeatherSDK 0.0.5
dotnet add package WeatherSDK --version 0.0.5
NuGet\Install-Package WeatherSDK -Version 0.0.5
<PackageReference Include="WeatherSDK" Version="0.0.5" />
<PackageVersion Include="WeatherSDK" Version="0.0.5" />
<PackageReference Include="WeatherSDK" />
paket add WeatherSDK --version 0.0.5
#r "nuget: WeatherSDK, 0.0.5"
#:package WeatherSDK@0.0.5
#addin nuget:?package=WeatherSDK&version=0.0.5
#tool nuget:?package=WeatherSDK&version=0.0.5
WeatherSDK
Introduction
The WeatherSDK provides a simple and flexible way to retrieve weather information for a given city from the OpenWeatherMap API. It supports caching of weather data and has two modes of operation: OnDemend and Polling.
Contents
Features
In
OnDemendmode, the SDK updates weather information only on customer requests (defalut operation mode). InPollingmode, the SDK requests new weather information for all stored locations.The WeatherSDK Stores weather information about requested cities and returns the stored value if it is still relevant (considered up to date if less than 10 minutes have passed).
Creating two copies of an instance with the same
API_KEYis not possible. The system will return the original instance.SKD caches information for a maximum of 10 cities at a time.
Methods throw exceptions with a description of the reason in case of failure.
Provides a method to delete an instance.
Installation
WeatherSDK package is available in NuGet.
The SDK use .Net8 (LTS) Framework
Usage
- Create C# project with .Net8 Framework
- Install
WeatherSDKfrom NuGet package manager. - Create instance of SDK by
CreateInstance("YOUR_API_KEY", OnDemend/Polling)method and pass parameters. - To get weather of the city call
GetCityWeather(CityName)method.
Example
using WeatherSDK;
try
{
WeatherInfoSDK instance = WeatherInfoSDK.CreateInstance("YOUR_API_KEY", WeatherInfoSDK.SDKMode.Polling);
string weather = await instance.GetCityWeather("CityName");
// By default the SDK works on-demand mode
WeatherInfoSDK secondInstance = WeatherInfoSDK.CreateInstance("YOUR_API_KEY_2");
string weather = await instance.GetCityWeather("CityName");
}
catch (UnauthorizedAccessException ex)
{
// Handle unauthorized exception
}
catch (NotFoundExcpetion ex)
{
// Handle not fount exception
}
catch (Exception ex)
{
// Handle exception
}
Exceptions
The Weather API SDK handles exceptions to provide meaningful error messages and help developers troubleshoot issues. Here's an overview of the exceptions that may be thrown by the SDK and how to handle them:
1. Empty or Invalid API Key
- Exception Type:
UnauthorizedExcpetion - Description: Throws when trying to create an SDK instance with an empty or invalid API key.
- Handling: Ensure that you provide a valid API key when creating instance of the SDK.
try
{
// Empty API key
var weatherApiSdk = WeatherApiSdk.GetInstance("");
}
catch (UnauthorizedExcpetion ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
2. Not Found
- Exception Type:
NotFoundExcpetion - Description: Throws when the requested city is not found in the OpenWeatherMap database.
- Handling: Catch this exception and handle it appropriately based on your application's logic.
try
{
var weatherData = await weatherApiSdk.GetWeatherDataAsync("NonexistentCity");
}
catch (NotFoundExcpetion ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
3. Request Failure
- Exception Type:
BaseWeatherSDKException - Description: Throws when there is a failure in making the API request, such as network issues or server errors.
- Handling: Wrap API calls in a try-catch block and catch this exception to handle request failures.
Example:
try
{
var weatherData = await weatherApiSdk.GetCityWeather("CityName");
// Process weatherData
}
catch (BaseWeatherSDKException ex)
{
Console.WriteLine($"Error: {ex.Message}");
}
Upload new version of SDK
To upload a new version of a package, please run the ".\push_package_to_nuget.ps1" PowerShell script on a Windows operating system. This script requires the following parameters:
- Package name
- NuGet
API-KEY - Path to the relevant package build version.
In path parameter don't need to mention build file
example: WeatherSDK\WeatherSDK\bin\Debug
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. 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. |
-
net8.0
- Newtonsoft.Json (>= 13.0.3)
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 |
|---|