gsuite_api/
orgunits.rs

1use crate::Client;
2use crate::ClientResult;
3
4pub struct Orgunits {
5    pub client: Client,
6}
7
8impl Orgunits {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Orgunits { client }
12    }
13
14    /**
15     * This function performs a `GET` to the `/admin/directory/v1/customer/{customerId}/orgunits` endpoint.
16     *
17     * Retrieves a list of all organizational units for an account.
18     *
19     * **Parameters:**
20     *
21     * * `customer_id: &str` -- The unique ID for the customer's Google Workspace account. As an account administrator, you can also use the `my_customer` alias to represent your account's `customerId`. The `customerId` is also returned as part of the [Users resource](/admin-sdk/directory/v1/reference/users).
22     * * `org_unit_path: &str` -- The full path to the organizational unit or its unique ID. Returns the children of the specified organizational unit.
23     * * `type_: crate::types::DirectoryOrgunitsListType` -- Whether to return all sub-organizations or just immediate children.
24     */
25    pub async fn list(
26        &self,
27        customer_id: &str,
28        org_unit_path: &str,
29        type_: crate::types::DirectoryOrgunitsListType,
30    ) -> ClientResult<crate::Response<crate::types::OrgUnits>> {
31        let mut query_args: Vec<(String, String)> = Default::default();
32        if !org_unit_path.is_empty() {
33            query_args.push(("orgUnitPath".to_string(), org_unit_path.to_string()));
34        }
35        if !type_.to_string().is_empty() {
36            query_args.push(("type".to_string(), type_.to_string()));
37        }
38        let query_ = serde_urlencoded::to_string(&query_args).unwrap();
39        let url = self.client.url(
40            &format!(
41                "/admin/directory/v1/customer/{}/orgunits?{}",
42                crate::progenitor_support::encode_path(customer_id),
43                query_
44            ),
45            None,
46        );
47        self.client
48            .get(
49                &url,
50                crate::Message {
51                    body: None,
52                    content_type: None,
53                },
54            )
55            .await
56    }
57    /**
58     * This function performs a `POST` to the `/admin/directory/v1/customer/{customerId}/orgunits` endpoint.
59     *
60     * Adds an organizational unit.
61     *
62     * **Parameters:**
63     *
64     * * `customer_id: &str` -- The unique ID for the customer's Google Workspace account. As an account administrator, you can also use the `my_customer` alias to represent your account's `customerId`. The `customerId` is also returned as part of the [Users resource](/admin-sdk/directory/v1/reference/users).
65     */
66    pub async fn insert(
67        &self,
68        customer_id: &str,
69        body: &crate::types::OrgUnit,
70    ) -> ClientResult<crate::Response<crate::types::OrgUnit>> {
71        let url = self.client.url(
72            &format!(
73                "/admin/directory/v1/customer/{}/orgunits",
74                crate::progenitor_support::encode_path(customer_id),
75            ),
76            None,
77        );
78        self.client
79            .post(
80                &url,
81                crate::Message {
82                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
83                    content_type: Some("application/json".to_string()),
84                },
85            )
86            .await
87    }
88    /**
89     * This function performs a `GET` to the `/admin/directory/v1/customer/{customerId}/orgunits/{orgUnitPath}` endpoint.
90     *
91     * Retrieves an organizational unit.
92     *
93     * **Parameters:**
94     *
95     * * `customer_id: &str` -- The unique ID for the customer's Google Workspace account. As an account administrator, you can also use the `my_customer` alias to represent your account's `customerId`. The `customerId` is also returned as part of the [Users resource](/admin-sdk/directory/v1/reference/users).
96     * * `org_unit_path: &str` -- The full path of the organizational unit or its unique ID.
97     */
98    pub async fn get(
99        &self,
100        customer_id: &str,
101        org_unit_path: &str,
102    ) -> ClientResult<crate::Response<crate::types::OrgUnit>> {
103        let url = self.client.url(
104            &format!(
105                "/admin/directory/v1/customer/{}/orgunits/{}",
106                crate::progenitor_support::encode_path(customer_id),
107                crate::progenitor_support::encode_path(org_unit_path),
108            ),
109            None,
110        );
111        self.client
112            .get(
113                &url,
114                crate::Message {
115                    body: None,
116                    content_type: None,
117                },
118            )
119            .await
120    }
121    /**
122     * This function performs a `PUT` to the `/admin/directory/v1/customer/{customerId}/orgunits/{orgUnitPath}` endpoint.
123     *
124     * Updates an organizational unit.
125     *
126     * **Parameters:**
127     *
128     * * `customer_id: &str` -- The unique ID for the customer's Google Workspace account. As an account administrator, you can also use the `my_customer` alias to represent your account's `customerId`. The `customerId` is also returned as part of the [Users resource](/admin-sdk/directory/v1/reference/users).
129     * * `org_unit_path: &str` -- The full path of the organizational unit or its unique ID.
130     */
131    pub async fn update(
132        &self,
133        customer_id: &str,
134        org_unit_path: &str,
135        body: &crate::types::OrgUnit,
136    ) -> ClientResult<crate::Response<crate::types::OrgUnit>> {
137        let url = self.client.url(
138            &format!(
139                "/admin/directory/v1/customer/{}/orgunits/{}",
140                crate::progenitor_support::encode_path(customer_id),
141                crate::progenitor_support::encode_path(org_unit_path),
142            ),
143            None,
144        );
145        self.client
146            .put(
147                &url,
148                crate::Message {
149                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
150                    content_type: Some("application/json".to_string()),
151                },
152            )
153            .await
154    }
155    /**
156     * This function performs a `DELETE` to the `/admin/directory/v1/customer/{customerId}/orgunits/{orgUnitPath}` endpoint.
157     *
158     * Removes an organizational unit.
159     *
160     * **Parameters:**
161     *
162     * * `customer_id: &str` -- The unique ID for the customer's Google Workspace account. As an account administrator, you can also use the `my_customer` alias to represent your account's `customerId`. The `customerId` is also returned as part of the [Users resource](/admin-sdk/directory/v1/reference/users).
163     * * `org_unit_path: &str` -- The full path of the organizational unit or its unique ID.
164     */
165    pub async fn delete(
166        &self,
167        customer_id: &str,
168        org_unit_path: &str,
169    ) -> ClientResult<crate::Response<()>> {
170        let url = self.client.url(
171            &format!(
172                "/admin/directory/v1/customer/{}/orgunits/{}",
173                crate::progenitor_support::encode_path(customer_id),
174                crate::progenitor_support::encode_path(org_unit_path),
175            ),
176            None,
177        );
178        self.client
179            .delete(
180                &url,
181                crate::Message {
182                    body: None,
183                    content_type: None,
184                },
185            )
186            .await
187    }
188    /**
189     * This function performs a `PATCH` to the `/admin/directory/v1/customer/{customerId}/orgunits/{orgUnitPath}` endpoint.
190     *
191     * Updates an organizational unit. This method supports [patch semantics](/admin-sdk/directory/v1/guides/performance#patch)
192     *
193     * **Parameters:**
194     *
195     * * `customer_id: &str` -- The unique ID for the customer's Google Workspace account. As an account administrator, you can also use the `my_customer` alias to represent your account's `customerId`. The `customerId` is also returned as part of the [Users resource](/admin-sdk/directory/v1/reference/users).
196     * * `org_unit_path: &str` -- The full path of the organizational unit or its unique ID.
197     */
198    pub async fn patch(
199        &self,
200        customer_id: &str,
201        org_unit_path: &str,
202        body: &crate::types::OrgUnit,
203    ) -> ClientResult<crate::Response<crate::types::OrgUnit>> {
204        let url = self.client.url(
205            &format!(
206                "/admin/directory/v1/customer/{}/orgunits/{}",
207                crate::progenitor_support::encode_path(customer_id),
208                crate::progenitor_support::encode_path(org_unit_path),
209            ),
210            None,
211        );
212        self.client
213            .patch(
214                &url,
215                crate::Message {
216                    body: Some(reqwest::Body::from(serde_json::to_vec(body)?)),
217                    content_type: Some("application/json".to_string()),
218                },
219            )
220            .await
221    }
222}