Skip to main content

openapp_sdk_core/resources/
orgs.rs

1//! `Orgs` resource group.
2
3use 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 OrgsClient {
15    transport: Arc<Transport>,
16}
17
18impl OrgsClient {
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: "/orgs",
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: "/orgs",
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!("/orgs/{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!("/orgs/{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!("/orgs/{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!("/orgs/{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 permissions(&self, id: &str) -> Result<JsonValue, SdkError> {
90        let path = format!("/orgs/{id}/permissions");
91        self.transport
92            .request_json::<(), JsonValue>(RequestSpec {
93                method: Method::GET,
94                path: &path,
95                ..Default::default()
96            })
97            .await
98    }
99
100    pub async fn users(&self, org_id: &str) -> Result<Vec<JsonValue>, SdkError> {
101        let path = format!("/orgs/{org_id}/users");
102        self.transport
103            .request_json::<(), Vec<JsonValue>>(RequestSpec {
104                method: Method::GET,
105                path: &path,
106                ..Default::default()
107            })
108            .await
109    }
110}