Crates.io | apialerts |
lib.rs | apialerts |
version | 1.0.0 |
source | src |
created_at | 2024-07-04 02:54:55.874382 |
updated_at | 2024-08-30 01:58:15.707584 |
description | A Rust client for the API Alerts service |
homepage | |
repository | https://github.com/apialerts/apialerts-rust |
max_upload_size | |
id | 1291278 |
size | 11,148 |
This is a simple API for sending alerts to the API Alerts service.
Add this to your Cargo.toml
:
[dependencies]
apialerts = "1.0.0"
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()]);
//...
}