asterisk_ari/apis/mailboxes/
mod.rs

1pub mod models;
2
3use crate::apis::client::Client;
4
5pub struct Mailboxes<'c> {
6    client: &'c Client,
7}
8
9impl<'c> Mailboxes<'c> {
10    pub fn new(client: &'c Client) -> Self {
11        Self { client }
12    }
13}
14
15impl Mailboxes<'_> {
16    /// List all mailboxes.
17    pub async fn list(&self) -> crate::errors::Result<Vec<models::Mailbox>> {
18        self.client.get("/mailboxes").await
19    }
20
21    /// Retrieve the current state of a device
22    pub async fn get(
23        &self,
24        mailbox_name: impl Into<String> + Send,
25    ) -> crate::errors::Result<models::Mailbox> {
26        self.client
27            .get(format!("/mailboxes/{}", mailbox_name.into()).as_str())
28            .await
29    }
30
31    /// Change the state of a mailbox.
32    ///
33    /// Note - implicitly creates the mailbox.
34    pub async fn change(
35        &self,
36        mailbox_name: impl Into<String> + Send,
37        old_messages: u32,
38        new_messages: u32,
39    ) -> crate::errors::Result<()> {
40        self.client
41            .put_with_query(
42                format!("/mailboxes/{}", mailbox_name.into()).as_str(),
43                vec![] as Vec<String>,
44                &[("oldMessages", old_messages), ("newMessages", new_messages)],
45            )
46            .await
47    }
48
49    /// Destroy a mailbox.
50    pub async fn destroy(
51        &self,
52        mailbox_name: impl Into<String> + Send,
53    ) -> crate::errors::Result<()> {
54        self.client
55            .delete(format!("/mailboxes/{}", mailbox_name.into()).as_str())
56            .await
57    }
58}