IsraelHomeFrontCommandAPI 2.0.2
dotnet add package IsraelHomeFrontCommandAPI --version 2.0.2
NuGet\Install-Package IsraelHomeFrontCommandAPI -Version 2.0.2
<PackageReference Include="IsraelHomeFrontCommandAPI" Version="2.0.2" />
paket add IsraelHomeFrontCommandAPI --version 2.0.2
#r "nuget: IsraelHomeFrontCommandAPI, 2.0.2"
// Install IsraelHomeFrontCommandAPI as a Cake Addin #addin nuget:?package=IsraelHomeFrontCommandAPI&version=2.0.2 // Install IsraelHomeFrontCommandAPI as a Cake Tool #tool nuget:?package=IsraelHomeFrontCommandAPI&version=2.0.2
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="2.0.1" />
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
- Israel Home Front Command for providing the API.
- Newtonsoft.Json for JSON serialization.
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 | 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. |
-
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.