use crate::client::{url_encode, AriClient};
use crate::error::Result;
use crate::event::Playback;
#[derive(Debug, Clone)]
pub struct PlaybackHandle {
id: String,
client: AriClient,
}
impl PlaybackHandle {
pub fn new(id: impl Into<String>, client: AriClient) -> Self {
Self {
id: id.into(),
client,
}
}
pub fn id(&self) -> &str {
&self.id
}
pub async fn control(&self, operation: &str) -> Result<()> {
self.client
.post_empty(&format!(
"/playbacks/{}/control?operation={}",
url_encode(&self.id),
url_encode(operation)
))
.await
}
pub async fn stop(&self) -> Result<()> {
self.client
.delete(&format!("/playbacks/{}", url_encode(&self.id)))
.await
}
pub async fn get(&self) -> Result<Playback> {
self.client
.get(&format!("/playbacks/{}", url_encode(&self.id)))
.await
}
}