openapp_sdk_core/resources/
zones.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 ZonesClient {
15 transport: Arc<Transport>,
16}
17
18impl ZonesClient {
19 pub(crate) fn new(transport: Arc<Transport>) -> Self {
20 Self { transport }
21 }
22
23 pub async fn create(&self, body: &JsonValue) -> Result<JsonValue, SdkError> {
24 self.transport
25 .request_json::<JsonValue, JsonValue>(RequestSpec {
26 method: Method::POST,
27 path: "/zones",
28 body: Some(body),
29 ..Default::default()
30 })
31 .await
32 }
33
34 pub async fn get(&self, id: &str) -> Result<JsonValue, SdkError> {
35 let path = format!("/zones/{id}");
36 self.transport
37 .request_json::<(), JsonValue>(RequestSpec {
38 method: Method::GET,
39 path: &path,
40 ..Default::default()
41 })
42 .await
43 }
44
45 pub async fn update(&self, id: &str, body: &JsonValue) -> Result<JsonValue, SdkError> {
46 let path = format!("/zones/{id}");
47 self.transport
48 .request_json::<JsonValue, JsonValue>(RequestSpec {
49 method: Method::PUT,
50 path: &path,
51 body: Some(body),
52 ..Default::default()
53 })
54 .await
55 }
56
57 pub async fn delete(&self, id: &str) -> Result<(), SdkError> {
58 let path = format!("/zones/{id}");
59 self.transport
60 .request_json::<(), ()>(RequestSpec {
61 method: Method::DELETE,
62 path: &path,
63 ..Default::default()
64 })
65 .await
66 }
67
68 pub async fn purge(&self, id: &str) -> Result<(), SdkError> {
69 let path = format!("/zones/{id}/purge");
70 self.transport
71 .request_json::<(), ()>(RequestSpec {
72 method: Method::DELETE,
73 path: &path,
74 ..Default::default()
75 })
76 .await
77 }
78
79 pub async fn by_integration(&self, integration_id: &str) -> Result<Vec<JsonValue>, SdkError> {
80 let path = format!("/integrations/{integration_id}/zones");
81 self.transport
82 .request_json::<(), Vec<JsonValue>>(RequestSpec {
83 method: Method::GET,
84 path: &path,
85 ..Default::default()
86 })
87 .await
88 }
89}