asterisk_ari/apis/device_stats/
mod.rs

1pub mod models;
2
3use crate::apis::client::Client;
4use serde::Serialize;
5
6pub struct DeviceStats<'c> {
7    client: &'c Client,
8}
9
10impl<'c> DeviceStats<'c> {
11    pub fn new(client: &'c Client) -> Self {
12        Self { client }
13    }
14}
15
16impl DeviceStats<'_> {
17    pub async fn list(&self) -> crate::errors::Result<Vec<models::DeviceState>> {
18        self.client.get("/deviceStates").await
19    }
20
21    /// Retrieve the current state of a device
22    pub async fn get(
23        &self,
24        device_name: impl Into<String> + Send,
25    ) -> crate::errors::Result<models::DeviceState> {
26        self.client
27            .get(format!("/deviceStates/{}", device_name.into()).as_str())
28            .await
29    }
30
31    /// Change the state of a device controlled by ARI. (Note - implicitly creates the device state).
32    pub async fn change(
33        &self,
34        device_name: impl Into<String> + Send,
35        state: State,
36    ) -> crate::errors::Result<()> {
37        self.client
38            .put_with_query(
39                format!("/deviceStates/{}", device_name.into()).as_str(),
40                vec![] as Vec<String>,
41                &[("deviceState", state)],
42            )
43            .await
44    }
45
46    pub async fn destroy(
47        &self,
48        device_name: impl Into<String> + Send,
49    ) -> crate::errors::Result<()> {
50        self.client
51            .delete(format!("/deviceStates/{}", device_name.into()).as_str())
52            .await
53    }
54}
55
56#[derive(Clone, Debug, PartialEq, Serialize)]
57pub enum State {
58    #[serde(rename = "NOT_INUSE")]
59    NotInuse,
60    #[serde(rename = "INUSE")]
61    Inuse,
62    #[serde(rename = "BUSY")]
63    Busy,
64    #[serde(rename = "INVALID")]
65    Invalid,
66    #[serde(rename = "UNAVAILABLE")]
67    Unavailable,
68    #[serde(rename = "RINGING")]
69    Ringing,
70    #[serde(rename = "RINGINUSE")]
71    Ringinuse,
72    #[serde(rename = "ONHOLD")]
73    OnHold,
74}