use std::sync::Arc;
use serde_json::json;
use crate::error::Result;
use crate::http::Config;
use crate::types::{
list_query, Audience, AudienceListItem, DeleteAudienceResponse, List, ListOptions,
};
#[derive(Clone)]
pub struct Audiences(pub(crate) Arc<Config>);
impl Audiences {
pub async fn create(&self, name: impl Into<String>) -> Result<Audience> {
let name: String = name.into();
self.0
.post(&["audiences"], &json!({ "name": name }), None)
.await
}
pub async fn get(&self, id: &str) -> Result<Audience> {
self.0.get(&["audiences", id], &[]).await
}
pub async fn list(&self, options: Option<&ListOptions>) -> Result<List<AudienceListItem>> {
self.0.get(&["audiences"], &list_query(options)).await
}
pub async fn delete(&self, id: &str) -> Result<DeleteAudienceResponse> {
self.0.delete(&["audiences", id]).await
}
}