ralertsinua-geo

Crates.ioralertsinua-geo
lib.rsralertsinua-geo
version0.5.2
sourcesrc
created_at2024-05-05 19:07:32.538917
updated_at2024-05-20 20:06:35.064418
descriptionGeo compatibility layer for alerts.in.ua
homepage
repositoryhttps://github.com/voiceapiai/ralertsinua
max_upload_size
id1230467
size131,174
Vadym Parakonnyi (voznik)

documentation

README

Quality Gate Status Coverage Status Crates.io Version Crates.io License docs.rs Stand With Ukraine

ralertsinua-geo

Rust async API wrapper (reqwest) & TUI (ratatui) for alerts.in.ua

screencast

Introduction

The Alerts.in.ua API Client is a Rust library that simplifies access to the alerts.in.ua API service. It provides real-time information about air raid alerts and other potential threats.

Installation

To install the Alerts.in.ua API Client, run the following command in your terminal:

cargo add ralertsinua-geo

Usage

⚠️ Before you can use this library, you need to obtain an API token by submitting an API request form.

Here's an basic example of how to use the library to get a list of active alerts:

Async:

use ralertsinua_geo::AlertsInUaGeo;
// Initialize the client
geo_client = AlertsInUaGeo();

/// The API for the AlertsInUaClient
pub trait AlertsInUaGeo: WithBoundingRect + Sync + Send + core::fmt::Debug {
    fn boundary(&self) -> CountryBoundary;
    fn locations(&self) -> [Location; 27];
    fn get_location_by_uid(&self, uid: i32) -> Option<Location>;
    fn get_location_by_name(&self, name: &str) -> Option<Location>;
}

Location

The Location struct represents a Ukraine's administrative unit lv4

/// Ukraine's administrative unit lv4  - *oblast*
#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
pub struct Location {
    /// OSM Relation Id
    pub relation_id: String,
    /// Alerts.in.ua "uid"
    pub location_uid: i32,
    /// "state" or "city" or "special"
    pub location_type: String,
    /// Geometry for boundary (Polygon or MultiPolygon)
    pub geometry: Geometry,
    /// Name in uk
    pub name: String,
    /// Name in en
    pub name_en: String,

    /// And some functions from traits
    fn geometry(&self) -> &Geometry;
    fn boundary(&self) -> &Polygon;
    fn center(&self) -> (f64, f64);
    /// To be used in TUI when , implements `Shape`
    fn draw(&self, painter: &mut Painter);

License

MIT 2024

*[TUI]: Terminal User Interface

Commit count: 16

cargo fmt