openapp_sdk_core/resources/
orgs.rs1use 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 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<types::PaginatedResponse, SdkError> {
24 self.transport
25 .request_json::<(), types::PaginatedResponse>(RequestSpec {
26 method: Method::GET,
27 path: "/orgs",
28 ..Default::default()
29 })
30 .await
31 }
32
33 pub async fn create(
34 &self,
35 body: &types::CreateOrganizationRequest,
36 ) -> Result<types::OrganizationResponse, SdkError> {
37 self.transport
38 .request_json::<types::CreateOrganizationRequest, types::OrganizationResponse>(
39 RequestSpec {
40 method: Method::POST,
41 path: "/orgs",
42 body: Some(body),
43 ..Default::default()
44 },
45 )
46 .await
47 }
48
49 pub async fn get(&self, id: &str) -> Result<types::OrganizationResponse, SdkError> {
50 let path = format!("/orgs/{id}");
51 self.transport
52 .request_json::<(), types::OrganizationResponse>(RequestSpec {
53 method: Method::GET,
54 path: &path,
55 ..Default::default()
56 })
57 .await
58 }
59
60 pub async fn update(
61 &self,
62 id: &str,
63 body: &types::UpdateOrganizationRequest,
64 ) -> Result<types::OrganizationResponse, SdkError> {
65 let path = format!("/orgs/{id}");
66 self.transport
67 .request_json::<types::UpdateOrganizationRequest, types::OrganizationResponse>(
68 RequestSpec {
69 method: Method::PUT,
70 path: &path,
71 body: Some(body),
72 ..Default::default()
73 },
74 )
75 .await
76 }
77
78 pub async fn delete(&self, id: &str) -> Result<(), SdkError> {
79 let path = format!("/orgs/{id}");
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 purge(&self, id: &str) -> Result<(), SdkError> {
90 let path = format!("/orgs/{id}/purge");
91 self.transport
92 .request_json::<(), ()>(RequestSpec {
93 method: Method::DELETE,
94 path: &path,
95 ..Default::default()
96 })
97 .await
98 }
99
100 pub async fn permissions(&self, id: &str) -> Result<types::OrgPermissionsResponse, SdkError> {
101 let path = format!("/orgs/{id}/permissions");
102 self.transport
103 .request_json::<(), types::OrgPermissionsResponse>(RequestSpec {
104 method: Method::GET,
105 path: &path,
106 ..Default::default()
107 })
108 .await
109 }
110
111 pub async fn users(&self, org_id: &str) -> Result<types::PaginatedResponse, SdkError> {
112 let path = format!("/orgs/{org_id}/users");
113 self.transport
114 .request_json::<(), types::PaginatedResponse>(RequestSpec {
115 method: Method::GET,
116 path: &path,
117 ..Default::default()
118 })
119 .await
120 }
121}