Skip to main content

openapp_sdk_core/resources/
devices.rs

1//! `Devices` resource group.
2
3use std::sync::Arc;
4
5use reqwest::Method;
6
7use super::types;
8use crate::{
9    error::SdkError,
10    transport::{RequestSpec, Transport},
11};
12
13#[derive(Debug, Clone)]
14pub struct DevicesClient {
15    transport: Arc<Transport>,
16}
17
18impl DevicesClient {
19    pub(crate) fn new(transport: Arc<Transport>) -> Self {
20        Self { transport }
21    }
22
23    pub async fn list(&self) -> Result<Vec<types::DeviceResponse>, SdkError> {
24        self.transport
25            .request_json::<(), Vec<types::DeviceResponse>>(RequestSpec {
26                method: Method::GET,
27                path: "/devices",
28                ..Default::default()
29            })
30            .await
31    }
32
33    pub async fn create(
34        &self,
35        body: &types::CreateDeviceRequest,
36    ) -> Result<types::DeviceResponse, SdkError> {
37        self.transport
38            .request_json::<types::CreateDeviceRequest, types::DeviceResponse>(RequestSpec {
39                method: Method::POST,
40                path: "/devices",
41                body: Some(body),
42                ..Default::default()
43            })
44            .await
45    }
46
47    pub async fn get(&self, id: &str) -> Result<types::DeviceResponse, SdkError> {
48        let path = format!("/devices/{id}");
49        self.transport
50            .request_json::<(), types::DeviceResponse>(RequestSpec {
51                method: Method::GET,
52                path: &path,
53                ..Default::default()
54            })
55            .await
56    }
57
58    pub async fn update(
59        &self,
60        id: &str,
61        body: &types::UpdateDeviceRequest,
62    ) -> Result<types::DeviceResponse, SdkError> {
63        let path = format!("/devices/{id}");
64        self.transport
65            .request_json::<types::UpdateDeviceRequest, types::DeviceResponse>(RequestSpec {
66                method: Method::PUT,
67                path: &path,
68                body: Some(body),
69                ..Default::default()
70            })
71            .await
72    }
73
74    pub async fn delete(&self, id: &str) -> Result<(), SdkError> {
75        let path = format!("/devices/{id}");
76        self.transport
77            .request_json::<(), ()>(RequestSpec {
78                method: Method::DELETE,
79                path: &path,
80                ..Default::default()
81            })
82            .await
83    }
84
85    pub async fn purge(&self, id: &str) -> Result<(), SdkError> {
86        let path = format!("/devices/{id}/purge");
87        self.transport
88            .request_json::<(), ()>(RequestSpec {
89                method: Method::DELETE,
90                path: &path,
91                ..Default::default()
92            })
93            .await
94    }
95
96    pub async fn restore(&self, id: &str) -> Result<types::DeviceResponse, SdkError> {
97        let path = format!("/devices/{id}/restore");
98        self.transport
99            .request_json::<(), types::DeviceResponse>(RequestSpec {
100                method: Method::POST,
101                path: &path,
102                ..Default::default()
103            })
104            .await
105    }
106
107    pub async fn door_restrictions(
108        &self,
109        id: &str,
110    ) -> Result<types::DoorRestrictionsResponse, SdkError> {
111        let path = format!("/devices/{id}/door-restrictions");
112        self.transport
113            .request_json::<(), types::DoorRestrictionsResponse>(RequestSpec {
114                method: Method::GET,
115                path: &path,
116                ..Default::default()
117            })
118            .await
119    }
120
121    pub async fn metadata_definition(
122        &self,
123        id: &str,
124    ) -> Result<types::DeviceMetadataDefinitionResponse, SdkError> {
125        let path = format!("/devices/{id}/metadata-definition");
126        self.transport
127            .request_json::<(), types::DeviceMetadataDefinitionResponse>(RequestSpec {
128                method: Method::GET,
129                path: &path,
130                ..Default::default()
131            })
132            .await
133    }
134}