WeatherSDK 0.0.5

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package WeatherSDK --version 0.0.5
                    
NuGet\Install-Package WeatherSDK -Version 0.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WeatherSDK" Version="0.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WeatherSDK" Version="0.0.5" />
                    
Directory.Packages.props
<PackageReference Include="WeatherSDK" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WeatherSDK --version 0.0.5
                    
#r "nuget: WeatherSDK, 0.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WeatherSDK@0.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WeatherSDK&version=0.0.5
                    
Install as a Cake Addin
#tool nuget:?package=WeatherSDK&version=0.0.5
                    
Install as a Cake Tool

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

  1. In OnDemend mode, the SDK updates weather information only on customer requests (defalut operation mode). In Polling mode, the SDK requests new weather information for all stored locations.

  2. 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).

  3. Creating two copies of an instance with the same API_KEY is not possible. The system will return the original instance.

  4. SKD caches information for a maximum of 10 cities at a time.

  5. Methods throw exceptions with a description of the reason in case of failure.

  6. Provides a method to delete an instance.

Installation

WeatherSDK package is available in NuGet.

The SDK use .Net8 (LTS) Framework

Usage

  1. Create C# project with .Net8 Framework
  2. Install WeatherSDK from NuGet package manager.
  3. Create instance of SDK by CreateInstance("YOUR_API_KEY", OnDemend/Polling) method and pass parameters.
  4. 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:

  1. Package name
  2. NuGet API-KEY
  3. Path to the relevant package build version.

In path parameter don't need to mention build file example: WeatherSDK\WeatherSDK\bin\Debug

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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