wirepusher

Crates.iowirepusher
lib.rswirepusher
version1.0.0-alpha.2
created_at2025-11-17 16:23:09.448719+00
updated_at2025-11-17 18:08:15.12492+00
descriptionOfficial Rust Client Library for WirePusher - Send push notifications with async/await support
homepagehttps://wirepusher.dev
repositoryhttps://gitlab.com/wirepusher/wirepusher-rust
max_upload_size
id1937112
size175,341
Carlos Hernandez (careduz)

documentation

https://docs.rs/wirepusher

README

WirePusher Rust Client Library

crates.io License: MIT

Official Rust client for WirePusher push notifications.

Installation

[dependencies]
wirepusher = "1.0.0-alpha.2"
tokio = { version = "1", features = ["full"] }

Quick Start

use wirepusher::Client;

#[tokio::main]
async fn main() -> Result<(), wirepusher::Error> {
    // Auto-load token from WIREPUSHER_TOKEN env var
    let client = Client::from_env()?;
    client.send("Deploy Complete", "Version 1.2.3 deployed").await?;

    // Or provide token explicitly
    let client = Client::new("YOUR_TOKEN")?;
    client.send("Alert", "Server CPU at 95%").await?;
    Ok(())
}

Features

use wirepusher::{Client, Notification};

#[tokio::main]
async fn main() -> Result<(), wirepusher::Error> {
    let client = Client::from_env()?;

    // Full parameters
    let notification = Notification::builder()
        .title("Deploy Complete")
        .message("Version 1.2.3 deployed")
        .notification_type("deployment")
        .tags(vec!["production".to_string(), "backend".to_string()])
        .image_url("https://example.com/success.png")
        .action_url("https://example.com/deploy/123")
        .build()?;

    client.send_notification(notification).await?;

    // AI-powered notifications (NotifAI)
    let response = client.notifai("deployment finished, v2.1.3 is live", None).await?;
    println!("Title: {}", response.notification.title);   // AI-generated
    println!("Message: {}", response.notification.message);

    // Encrypted messages
    let notification = Notification::builder()
        .title("Security Alert")
        .message("Sensitive data")
        .notification_type("security")
        .encryption_password("your_password")
        .build()?;
    client.send_notification(notification).await?;

    Ok(())
}

Configuration

// Environment variables (recommended)
// WIREPUSHER_TOKEN - API token (required if not passed to constructor)
// WIREPUSHER_TIMEOUT - Request timeout in seconds (default: 30)
// WIREPUSHER_MAX_RETRIES - Retry attempts (default: 3)

// Or explicit configuration
let client = Client::with_config("YOUR_TOKEN", 60, 5)?;

Error Handling

use wirepusher::{Client, Error};

#[tokio::main]
async fn main() {
    let client = Client::from_env().unwrap();

    match client.send("Title", "Message").await {
        Ok(response) => println!("Success: {}", response.message),
        Err(Error::Authentication { message, .. }) => {
            eprintln!("Invalid token: {}", message);
        }
        Err(Error::Validation { message, .. }) => {
            eprintln!("Invalid parameters: {}", message);
        }
        Err(Error::RateLimit { message, .. }) => {
            eprintln!("Rate limited: {}", message);
        }
        Err(e) => {
            if e.is_retryable() {
                eprintln!("Retryable error: {}", e);
            }
        }
    }
}

Automatic retry with exponential backoff for network errors, 5xx, and 429 (rate limit).

Smart Rate Limiting

let client = Client::from_env()?;
client.send("Alert", "Message").await?;

// Check rate limit status after any request
if let Some(rate_limit) = client.get_last_rate_limit() {
    println!("Remaining: {}/{}", rate_limit.remaining, rate_limit.limit);
    println!("Resets at: {}", rate_limit.reset);
}

Links

License

MIT

Commit count: 0

cargo fmt