asterisk-rs-ari 0.8.0

Async Rust client for the Asterisk REST Interface (ARI)
Documentation
//! endpoint query operations (read-only).

use crate::client::{AriClient, url_encode};
use crate::error::Result;
pub use crate::event::Endpoint;

/// list all endpoints
pub async fn list(client: &AriClient) -> Result<Vec<Endpoint>> {
    client.get("/endpoints").await
}

/// list endpoints for a specific technology
pub async fn list_by_tech(client: &AriClient, tech: &str) -> Result<Vec<Endpoint>> {
    client
        .get(&format!("/endpoints/{}", url_encode(tech)))
        .await
}

/// get a specific endpoint
pub async fn get(client: &AriClient, tech: &str, resource: &str) -> Result<Endpoint> {
    client
        .get(&format!(
            "/endpoints/{}/{}",
            url_encode(tech),
            url_encode(resource)
        ))
        .await
}

/// send a message to some technology uri or endpoint
pub async fn send_message(client: &AriClient, to: &str, from: &str, body: &str) -> Result<()> {
    client
        .put_empty(&format!(
            "/endpoints/sendMessage?to={}&from={}&body={}",
            url_encode(to),
            url_encode(from),
            url_encode(body)
        ))
        .await
}

/// refer an endpoint or technology uri to some technology uri or endpoint
pub async fn refer(client: &AriClient, to: &str, from: &str, refer_to: &str) -> Result<()> {
    client
        .post_empty(&format!(
            "/endpoints/refer?to={}&from={}&refer_to={}",
            url_encode(to),
            url_encode(from),
            url_encode(refer_to)
        ))
        .await
}

/// send a message to an endpoint
pub async fn send_message_to_endpoint(
    client: &AriClient,
    tech: &str,
    resource: &str,
    from: &str,
    body: &str,
) -> Result<()> {
    client
        .put_empty(&format!(
            "/endpoints/{}/{}/sendMessage?from={}&body={}",
            url_encode(tech),
            url_encode(resource),
            url_encode(from),
            url_encode(body)
        ))
        .await
}

/// refer an endpoint to some technology uri or endpoint
pub async fn refer_to_endpoint(
    client: &AriClient,
    tech: &str,
    resource: &str,
    from: &str,
    refer_to: &str,
) -> Result<()> {
    client
        .post_empty(&format!(
            "/endpoints/{}/{}/refer?from={}&refer_to={}",
            url_encode(tech),
            url_encode(resource),
            url_encode(from),
            url_encode(refer_to)
        ))
        .await
}