use crate::client::{AriClient, url_encode};
use crate::error::Result;
#[derive(Debug, Clone, serde::Deserialize)]
#[non_exhaustive]
pub struct Application {
pub name: String,
#[serde(default)]
pub channel_ids: Vec<String>,
#[serde(default)]
pub bridge_ids: Vec<String>,
#[serde(default)]
pub endpoint_ids: Vec<String>,
#[serde(default)]
pub device_names: Vec<String>,
#[serde(default)]
pub events_allowed: Vec<serde_json::Value>,
#[serde(default)]
pub events_disallowed: Vec<serde_json::Value>,
}
pub async fn list(client: &AriClient) -> Result<Vec<Application>> {
client.get("/applications").await
}
pub async fn get(client: &AriClient, app_name: &str) -> Result<Application> {
client
.get(&format!("/applications/{}", url_encode(app_name)))
.await
}
pub async fn subscribe(
client: &AriClient,
application_name: &str,
event_source: &str,
) -> Result<Application> {
client
.post(
&format!(
"/applications/{}/subscription?eventSource={}",
url_encode(application_name),
url_encode(event_source)
),
&serde_json::json!({}),
)
.await
}
pub async fn unsubscribe(
client: &AriClient,
application_name: &str,
event_source: &str,
) -> Result<Application> {
client
.delete_with_response(&format!(
"/applications/{}/subscription?eventSource={}",
url_encode(application_name),
url_encode(event_source)
))
.await
}
pub async fn set_event_filter(
client: &AriClient,
application_name: &str,
filter: &serde_json::Value,
) -> Result<Application> {
client
.put(
&format!("/applications/{}/eventFilter", url_encode(application_name)),
filter,
)
.await
}