openapp_sdk_core/resources/
devices.rs1use std::sync::Arc;
4
5use reqwest::Method;
6
7use super::JsonValue;
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<JsonValue>, SdkError> {
24 self.transport
25 .request_json::<(), Vec<JsonValue>>(RequestSpec {
26 method: Method::GET,
27 path: "/devices",
28 ..Default::default()
29 })
30 .await
31 }
32
33 pub async fn create(&self, body: &JsonValue) -> Result<JsonValue, SdkError> {
34 self.transport
35 .request_json::<JsonValue, JsonValue>(RequestSpec {
36 method: Method::POST,
37 path: "/devices",
38 body: Some(body),
39 ..Default::default()
40 })
41 .await
42 }
43
44 pub async fn get(&self, id: &str) -> Result<JsonValue, SdkError> {
45 let path = format!("/devices/{id}");
46 self.transport
47 .request_json::<(), JsonValue>(RequestSpec {
48 method: Method::GET,
49 path: &path,
50 ..Default::default()
51 })
52 .await
53 }
54
55 pub async fn update(&self, id: &str, body: &JsonValue) -> Result<JsonValue, SdkError> {
56 let path = format!("/devices/{id}");
57 self.transport
58 .request_json::<JsonValue, JsonValue>(RequestSpec {
59 method: Method::PUT,
60 path: &path,
61 body: Some(body),
62 ..Default::default()
63 })
64 .await
65 }
66
67 pub async fn delete(&self, id: &str) -> Result<(), SdkError> {
68 let path = format!("/devices/{id}");
69 self.transport
70 .request_json::<(), ()>(RequestSpec {
71 method: Method::DELETE,
72 path: &path,
73 ..Default::default()
74 })
75 .await
76 }
77
78 pub async fn purge(&self, id: &str) -> Result<(), SdkError> {
79 let path = format!("/devices/{id}/purge");
80 self.transport
81 .request_json::<(), ()>(RequestSpec {
82 method: Method::DELETE,
83 path: &path,
84 ..Default::default()
85 })
86 .await
87 }
88
89 pub async fn restore(&self, id: &str) -> Result<JsonValue, SdkError> {
90 let path = format!("/devices/{id}/restore");
91 self.transport
92 .request_json::<(), JsonValue>(RequestSpec {
93 method: Method::POST,
94 path: &path,
95 ..Default::default()
96 })
97 .await
98 }
99
100 pub async fn door_restrictions(&self, id: &str) -> Result<JsonValue, SdkError> {
101 let path = format!("/devices/{id}/door-restrictions");
102 self.transport
103 .request_json::<(), JsonValue>(RequestSpec {
104 method: Method::GET,
105 path: &path,
106 ..Default::default()
107 })
108 .await
109 }
110
111 pub async fn metadata_definition(&self, id: &str) -> Result<JsonValue, SdkError> {
112 let path = format!("/devices/{id}/metadata-definition");
113 self.transport
114 .request_json::<(), JsonValue>(RequestSpec {
115 method: Method::GET,
116 path: &path,
117 ..Default::default()
118 })
119 .await
120 }
121}