apialerts

Crates.ioapialerts
lib.rsapialerts
version1.0.0
sourcesrc
created_at2024-07-04 02:54:55.874382
updated_at2024-08-30 01:58:15.707584
descriptionA Rust client for the API Alerts service
homepage
repositoryhttps://github.com/apialerts/apialerts-rust
max_upload_size
id1291278
size11,148
Jared Hall (mononz)

documentation

README

API Alerts - Rust

This is a simple API for sending alerts to the API Alerts service.

Installation

Add this to your Cargo.toml:

[dependencies]
apialerts = "1.0.0"

Usage

use apialerts::{event::ApiAlertsEvent, ApiAlertsClient};

#[tokio::main]
async fn main() {
    let client = ApiAlertsClient::new("{API-KEY}".to_string());

    let event = ApiAlertsEvent::new(
        "rust channel".to_string(),
        "I've caught the rust bug".to_string(),
    );

    // Blocking - using futures
    match client.send(event) {
        Ok(_) => {}
        Err(e) => println!("Error sending alert: {:?}", e),
    }

    // OR

    // Async - using async-std
    match client.send_async(event).await {
        Ok(_) => {}
        Err(e) => println!("Error sending alert: {:?}", e),
    }
}

You can also use the update_config and update_api_key methods to update the configuration of the client.

ApiAlertsConfig is exposed as a struct, so you can easily create a new config with the default values.

use apialerts::{event::ApiAlertsEvent, ApiAlertsClient};

#[tokio::main]
async fn main() {
    let client = ApiAlertsClient::new("{API-KEY}".to_string())
        .update_config(ApiAlertsConfig::new_default_config())
        .update_api_key("{API-KEY}".to_string());

    //...
}

You can also set the tags and links on the alert event.

use apialerts::{event::ApiAlertsEvent, ApiAlertsClient};

#[tokio::main]
async fn main() {
    //...

    let event = ApiAlertsEvent::new(
        "rust channel".to_string(),
        "I've caught the rust bug".to_string(),
    )
    .set_tags(vec!["rust", "bug".to_string()])
    .set_links(vec!["https://github.com/apialerts/apialerts-rust".to_string()]);

    //...
}
Commit count: 8

cargo fmt