openapp_sdk_core/resources/
integrations.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 IntegrationsClient {
15 transport: Arc<Transport>,
16}
17
18impl IntegrationsClient {
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: "/integrations",
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: "/integrations",
38 body: Some(body),
39 ..Default::default()
40 })
41 .await
42 }
43
44 pub async fn provider_types(&self) -> Result<Vec<JsonValue>, SdkError> {
45 self.transport
46 .request_json::<(), Vec<JsonValue>>(RequestSpec {
47 method: Method::GET,
48 path: "/integrations/provider-types",
49 ..Default::default()
50 })
51 .await
52 }
53
54 pub async fn provider_definition(&self, provider_type: &str) -> Result<JsonValue, SdkError> {
55 let path = format!("/integrations/provider-types/{provider_type}/definition");
56 self.transport
57 .request_json::<(), JsonValue>(RequestSpec {
58 method: Method::GET,
59 path: &path,
60 ..Default::default()
61 })
62 .await
63 }
64
65 pub async fn get(&self, id: &str) -> Result<JsonValue, SdkError> {
66 let path = format!("/integrations/{id}");
67 self.transport
68 .request_json::<(), JsonValue>(RequestSpec {
69 method: Method::GET,
70 path: &path,
71 ..Default::default()
72 })
73 .await
74 }
75
76 pub async fn update(&self, id: &str, body: &JsonValue) -> Result<JsonValue, SdkError> {
77 let path = format!("/integrations/{id}");
78 self.transport
79 .request_json::<JsonValue, JsonValue>(RequestSpec {
80 method: Method::PUT,
81 path: &path,
82 body: Some(body),
83 ..Default::default()
84 })
85 .await
86 }
87
88 pub async fn purge(&self, id: &str) -> Result<(), SdkError> {
89 let path = format!("/integrations/{id}/purge");
90 self.transport
91 .request_json::<(), ()>(RequestSpec {
92 method: Method::DELETE,
93 path: &path,
94 ..Default::default()
95 })
96 .await
97 }
98
99 pub async fn restore(&self, id: &str) -> Result<JsonValue, SdkError> {
100 let path = format!("/integrations/{id}/restore");
101 self.transport
102 .request_json::<(), JsonValue>(RequestSpec {
103 method: Method::POST,
104 path: &path,
105 ..Default::default()
106 })
107 .await
108 }
109
110 pub async fn device_metadata_schema(&self, id: &str) -> Result<JsonValue, SdkError> {
111 let path = format!("/integrations/{id}/device-metadata-schema");
112 self.transport
113 .request_json::<(), JsonValue>(RequestSpec {
114 method: Method::GET,
115 path: &path,
116 ..Default::default()
117 })
118 .await
119 }
120
121 pub async fn discovered_devices(&self, id: &str) -> Result<Vec<JsonValue>, SdkError> {
122 let path = format!("/integrations/{id}/discovered-devices");
123 self.transport
124 .request_json::<(), Vec<JsonValue>>(RequestSpec {
125 method: Method::GET,
126 path: &path,
127 ..Default::default()
128 })
129 .await
130 }
131
132 pub async fn entities(&self, id: &str) -> Result<Vec<JsonValue>, SdkError> {
133 let path = format!("/integrations/{id}/entities");
134 self.transport
135 .request_json::<(), Vec<JsonValue>>(RequestSpec {
136 method: Method::GET,
137 path: &path,
138 ..Default::default()
139 })
140 .await
141 }
142
143 pub async fn ops(&self, id: &str) -> Result<Vec<JsonValue>, SdkError> {
144 let path = format!("/integrations/{id}/ops");
145 self.transport
146 .request_json::<(), Vec<JsonValue>>(RequestSpec {
147 method: Method::GET,
148 path: &path,
149 ..Default::default()
150 })
151 .await
152 }
153
154 pub async fn run_op(
155 &self,
156 id: &str,
157 op_id: &str,
158 body: &JsonValue,
159 ) -> Result<JsonValue, SdkError> {
160 let path = format!("/integrations/{id}/ops/{op_id}");
161 self.transport
162 .request_json::<JsonValue, JsonValue>(RequestSpec {
163 method: Method::POST,
164 path: &path,
165 body: Some(body),
166 ..Default::default()
167 })
168 .await
169 }
170
171 pub async fn list_access_portals(&self, id: &str) -> Result<Vec<JsonValue>, SdkError> {
174 let path = format!("/integrations/{id}/access-portals");
175 self.transport
176 .request_json::<(), Vec<JsonValue>>(RequestSpec {
177 method: Method::GET,
178 path: &path,
179 ..Default::default()
180 })
181 .await
182 }
183
184 pub async fn create_access_portal(
185 &self,
186 id: &str,
187 body: &JsonValue,
188 ) -> Result<JsonValue, SdkError> {
189 let path = format!("/integrations/{id}/access-portals");
190 self.transport
191 .request_json::<JsonValue, JsonValue>(RequestSpec {
192 method: Method::POST,
193 path: &path,
194 body: Some(body),
195 ..Default::default()
196 })
197 .await
198 }
199
200 pub async fn get_access_portal(&self, portal_id: &str) -> Result<JsonValue, SdkError> {
201 let path = format!("/integrations/access-portals/{portal_id}");
202 self.transport
203 .request_json::<(), JsonValue>(RequestSpec {
204 method: Method::GET,
205 path: &path,
206 ..Default::default()
207 })
208 .await
209 }
210
211 pub async fn update_access_portal(
212 &self,
213 id: &str,
214 portal_id: &str,
215 body: &JsonValue,
216 ) -> Result<JsonValue, SdkError> {
217 let path = format!("/integrations/{id}/access-portals/{portal_id}");
218 self.transport
219 .request_json::<JsonValue, JsonValue>(RequestSpec {
220 method: Method::PUT,
221 path: &path,
222 body: Some(body),
223 ..Default::default()
224 })
225 .await
226 }
227
228 pub async fn delete_access_portal(&self, id: &str, portal_id: &str) -> Result<(), SdkError> {
229 let path = format!("/integrations/{id}/access-portals/{portal_id}");
230 self.transport
231 .request_json::<(), ()>(RequestSpec {
232 method: Method::DELETE,
233 path: &path,
234 ..Default::default()
235 })
236 .await
237 }
238
239 pub async fn update_access_invite(
240 &self,
241 id: &str,
242 invite_link_id: &str,
243 body: &JsonValue,
244 ) -> Result<JsonValue, SdkError> {
245 let path = format!("/integrations/{id}/access-invites/{invite_link_id}");
246 self.transport
247 .request_json::<JsonValue, JsonValue>(RequestSpec {
248 method: Method::PUT,
249 path: &path,
250 body: Some(body),
251 ..Default::default()
252 })
253 .await
254 }
255
256 pub async fn delete_access_invite(
257 &self,
258 id: &str,
259 invite_link_id: &str,
260 ) -> Result<(), SdkError> {
261 let path = format!("/integrations/{id}/access-invites/{invite_link_id}");
262 self.transport
263 .request_json::<(), ()>(RequestSpec {
264 method: Method::DELETE,
265 path: &path,
266 ..Default::default()
267 })
268 .await
269 }
270
271 pub async fn restore_access_invite(
272 &self,
273 id: &str,
274 invite_link_id: &str,
275 ) -> Result<JsonValue, SdkError> {
276 let path = format!("/integrations/{id}/access-invites/{invite_link_id}/restore");
277 self.transport
278 .request_json::<(), JsonValue>(RequestSpec {
279 method: Method::POST,
280 path: &path,
281 ..Default::default()
282 })
283 .await
284 }
285}