IsraelHomeFrontCommandAPI 2.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package IsraelHomeFrontCommandAPI --version 2.0.1                
NuGet\Install-Package IsraelHomeFrontCommandAPI -Version 2.0.1                
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="IsraelHomeFrontCommandAPI" Version="2.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IsraelHomeFrontCommandAPI --version 2.0.1                
#r "nuget: IsraelHomeFrontCommandAPI, 2.0.1"                
#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.
// Install IsraelHomeFrontCommandAPI as a Cake Addin
#addin nuget:?package=IsraelHomeFrontCommandAPI&version=2.0.1

// Install IsraelHomeFrontCommandAPI as a Cake Tool
#tool nuget:?package=IsraelHomeFrontCommandAPI&version=2.0.1                

IsraelHomeFrontCommandAPI

Overview

IsraelHomeFrontCommandAPI is a C# library designed to interact with the Israel Home Front Command API. It provides methods to retrieve active alerts and the alert history for the past 24 hours, including detailed error handling and response types.

Features

  • Retrieve current active alerts from the Home Front Command API.
  • Fetch alert history for the past 24 hours.
  • Robust error handling for HTTP requests and JSON serialization.
  • Easy-to-use response models.

Installation

You can install this library via NuGet Package Manager. Use the following command in the Package Manager Console:

Install-Package IsraelHomeFrontCommandAPI

Or add it to your .csproj file:

<PackageReference Include="IsraelHomeFrontCommandAPI" Version="ENTER_THE_LAST" />

Usage

Initialize the Client

To use the API client, create an instance of HomeFrontCommandClient:

using IsraelHomeFrontCommandAPI;

var client = new HomeFrontCommandClient();

Retrieve Active Alerts

To get the current active alerts, use the GetActiveAlertsAsync method:

var activeAlertsResponse = await client.GetActiveAlertsAsync();

if (activeAlertsResponse.AlertType != AlertType.None)
{
    Console.WriteLine($"Active alert type: {activeAlertsResponse.AlertType}");
}
else
{
    Console.WriteLine("No active alerts at the moment.");
}

Retrieve Alert History

To fetch the alert history for the last 24 hours, use the GetAlertsHistoryLastDayAsync method:

var alertHistory = await client.GetAlertsHistoryLastDayAsync();

if (alertHistory.Count > 0)
{
    foreach (var alert in alertHistory)
    {
        Console.WriteLine($"Alert Date: {alert.AlertDateIst}, Type: {alert.AlertType}, City: {alert.City}");
    }
}
else
{
    Console.WriteLine("No alerts found in the last 24 hours.");
}

Error Handling

The library throws specific exceptions for different error scenarios:

  • HttpRequestException: When the request to the API fails.
  • JsonSerializationException: When deserialization of the JSON response fails.
  • Exception: For any other unforeseen errors.

You can catch these exceptions as follows:

try
{
    var activeAlertsResponse = await client.GetActiveAlertsAsync();
}
catch (HttpRequestException ex)
{
    Console.WriteLine($"HTTP Request Error: {ex.Message}");
}
catch (JsonSerializationException ex)
{
    Console.WriteLine($"JSON Serialization Error: {ex.Message}");
}
catch (Exception ex)
{
    Console.WriteLine($"An unknown error occurred: {ex.Message}");
}

Contributing

Contributions are welcome! If you have suggestions for improvements or bug fixes, please create an issue or submit a pull request.

License

This project is licensed under the MIT License

Acknowledgments

Notes

  • The examples in the usage section demonstrate how to handle both active alerts and alert history, with basic output to the console.
  • Make sure that the example code is tested and works as expected.
  • You can add more detailed examples if needed, such as using the library in different application types (e.g., console apps, ASP.NET apps, etc.).

Feel free to ask if you want to expand on any specific part or add additional examples!

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