# pipestreamr

Rust SDK and CLI for the [PipeStreamr](https://pipestreamr.com) unified events API.

## Installation

```sh
cargo install pipestreamr
```

## CLI Usage

```sh
export PIPESTREAMR_API_KEY="ps_your_key"
export PIPESTREAMR_URL="https://api.pipestreamr.com"  # optional

# List all events
pipestreamr events --limit 10

# List only messages
pipestreamr events --type message --platform discord

# List only logs
pipestreamr events --type log --severity 9 --service my-app

# Get a single event
pipestreamr event <uuid>

# View stats
pipestreamr stats

# Health check
pipestreamr health
```

## Library Usage

```rust
use pipestreamr::{PipeStreamrClient, EventQuery};

#[tokio::main]
async fn main() -> Result<(), pipestreamr::Error> {
    let client = PipeStreamrClient::new(
        "https://api.pipestreamr.com",
        "ps_your_api_key",
    );

    // List messages
    let response = client.list_events(&EventQuery {
        event_type: Some("message".into()),
        platform: Some("discord".into()),
        limit: Some(10),
        ..Default::default()
    }).await?;

    for evt in &response.events {
        println!("[{}] {}: {}",
            evt.platform.as_deref().unwrap_or("?"),
            evt.from_name.as_deref().unwrap_or("?"),
            evt.body.as_deref().unwrap_or(""),
        );
    }

    // List logs
    let logs = client.list_events(&EventQuery {
        event_type: Some("log".into()),
        severity: Some(13), // WARN and above
        ..Default::default()
    }).await?;

    for evt in &logs.events {
        println!("[{}] {}",
            evt.severity_text.as_deref().unwrap_or("?"),
            evt.body.as_deref().unwrap_or(""),
        );
    }

    // Get stats
    let stats = client.stats().await?;
    println!("Total messages: {}", stats.total);

    Ok(())
}
```

## License

MIT
