cnb 0.2.2

CNB (cnb.cool) API client for Rust — typed, async, production-ready
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
// @generated DO NOT EDIT.
//
// Generated from the CNB OpenAPI specification by `cnb-codegen`.
// Run `cargo run -p cnb-codegen --manifest-path codegen/Cargo.toml \
//      -- --spec codegen/spec/swagger.json --out src` to refresh.

#![allow(clippy::all)]
#![allow(missing_docs)]
#![allow(unused_imports)]
#![allow(unused_mut)]

use reqwest::Method;
use serde::Serialize;

use crate::error::{ApiError, Result};
use crate::http::HttpInner;
use crate::models;

// `Organizations` resource client (generated, 12 operations).

/// Resource client.
#[derive(Debug, Clone)]
pub struct OrganizationsClient {
    inner: HttpInner,
}

impl OrganizationsClient {
    /// Construct a new resource client. Normally obtained
    /// via [`crate::ApiClient`] rather than directly.
    pub fn new(inner: HttpInner) -> Self {
        Self { inner }
    }

    /// 创建新组织。Create new organization.
    ///
    /// `POST /groups`
    pub async fn create_organization(
        &self,
        body: &crate::models::CreateGroupReq,
    ) -> Result<serde_json::Value> {
        let path = "/groups".to_string();
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute_with_body::<serde_json::Value, _>(Method::POST, url, body)
            .await
    }

    /// 删除指定组织。Delete the specified organization.
    ///
    /// `DELETE /{group}`
    pub async fn delete_organization(&self, group: String) -> Result<serde_json::Value> {
        let path = format!("/{}", group);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute::<serde_json::Value>(Method::DELETE, url)
            .await
    }

    /// 获取指定组织信息。Get information for the specified organization.
    ///
    /// `GET /{group}`
    pub async fn get_group(&self, group: String) -> Result<crate::models::OrganizationAccess> {
        let path = format!("/{}", group);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute::<crate::models::OrganizationAccess>(Method::GET, url)
            .await
    }

    /// 获取指定组织的配置详情。Get the configuration details for the specified organization.
    ///
    /// `GET /{slug}/-/settings`
    pub async fn get_group_setting(
        &self,
        slug: String,
    ) -> Result<crate::models::OrganizationSettingWithParent> {
        let path = format!("/{}/-/settings", slug);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute::<crate::models::OrganizationSettingWithParent>(Method::GET, url)
            .await
    }

    /// 获取指定用户拥有权限的顶层组织列表。 Get a list of top-level organizations that the specified user has permissions to access.
    ///
    /// `GET /users/{username}/groups`
    pub async fn get_groups_by_user_id(
        &self,
        username: String,
        query: &GetGroupsByUserIDQuery,
    ) -> Result<crate::models::OrganizationUnion> {
        let path = format!("/users/{}/groups", username);
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(ref v) = query.search {
                pairs.append_pair("search", v);
            }
            if let Some(v) = query.page {
                pairs.append_pair("page", &v.to_string());
            }
            if let Some(v) = query.page_size {
                pairs.append_pair("page_size", &v.to_string());
            }
            drop(pairs);
        }
        self.inner
            .execute::<crate::models::OrganizationUnion>(Method::GET, url)
            .await
    }

    /// 查询当前用户在指定组织下拥有指定权限的子组织列表。Get the list of sub-organizations that the current user has access to in the specified organization.
    ///
    /// `GET /user/groups/{slug}`
    pub async fn list_groups(
        &self,
        slug: String,
        query: &ListGroupsQuery,
    ) -> Result<Vec<crate::models::OrganizationAccess>> {
        let path = format!("/user/groups/{}", slug);
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(v) = query.page {
                pairs.append_pair("page", &v.to_string());
            }
            if let Some(v) = query.page_size {
                pairs.append_pair("page_size", &v.to_string());
            }
            if let Some(v) = query.access {
                pairs.append_pair("access", &v.to_string());
            }
            drop(pairs);
        }
        self.inner
            .execute::<Vec<crate::models::OrganizationAccess>>(Method::GET, url)
            .await
    }

    /// 获取指定组织下的子组织列表。Get the list of sub-organizations under the specified organization.
    ///
    /// `GET /{slug}/-/sub-groups`
    pub async fn list_subgroups(
        &self,
        slug: String,
        query: &ListSubgroupsQuery,
    ) -> Result<Vec<crate::models::OrganizationUnion>> {
        let path = format!("/{}/-/sub-groups", slug);
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(ref v) = query.search {
                pairs.append_pair("search", v);
            }
            if let Some(v) = query.page {
                pairs.append_pair("page", &v.to_string());
            }
            if let Some(v) = query.page_size {
                pairs.append_pair("page_size", &v.to_string());
            }
            drop(pairs);
        }
        self.inner
            .execute::<Vec<crate::models::OrganizationUnion>>(Method::GET, url)
            .await
    }

    /// 获取当前用户拥有权限的顶层组织列表。Get top-level organizations list that the current user has access to.
    ///
    /// `GET /user/groups`
    pub async fn list_top_groups(
        &self,
        query: &ListTopGroupsQuery,
    ) -> Result<Vec<crate::models::OrganizationAccess>> {
        let path = "/user/groups".to_string();
        let mut url = self.inner.url(&path)?;
        {
            let mut pairs = url.query_pairs_mut();
            if let Some(v) = query.page {
                pairs.append_pair("page", &v.to_string());
            }
            if let Some(v) = query.page_size {
                pairs.append_pair("page_size", &v.to_string());
            }
            if let Some(ref v) = query.search {
                pairs.append_pair("search", v);
            }
            if let Some(ref v) = query.role {
                pairs.append_pair("role", v);
            }
            drop(pairs);
        }
        self.inner
            .execute::<Vec<crate::models::OrganizationAccess>>(Method::GET, url)
            .await
    }

    /// 转移组织。Transfer an organization.
    ///
    /// `POST /{group}/-/transfer`
    pub async fn transfer_group(
        &self,
        group: String,
        body: &crate::models::TransferSlugReq,
    ) -> Result<serde_json::Value> {
        let path = format!("/{}/-/transfer", group);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute_with_body::<serde_json::Value, _>(Method::POST, url, body)
            .await
    }

    /// 更新指定组织的配置。Updates the configuration for the specified organization.
    ///
    /// `PUT /{slug}/-/settings`
    pub async fn update_group_setting(
        &self,
        slug: String,
        body: &crate::models::GroupSettingReq,
    ) -> Result<serde_json::Value> {
        let path = format!("/{}/-/settings", slug);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute_with_body::<serde_json::Value, _>(Method::PUT, url, body)
            .await
    }

    /// 更新组织信息, 可更新的内容为: 组织描述, 组织展示名称, 组织网站, 组织联系邮箱。Updates organization information including: description, display name, website URL and contact email.
    ///
    /// `PUT /{group}`
    pub async fn update_organization(
        &self,
        group: String,
        body: &crate::models::UpdateGroupReq,
    ) -> Result<serde_json::Value> {
        let path = format!("/{}", group);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute_with_body::<serde_json::Value, _>(Method::PUT, url, body)
            .await
    }

    /// 发起一个上传 logo 的请求,返回上传文件的url,请使用 put 发起流式上传。Initiate a request to upload logo,returns upload URL.Use PUT to initiate a stream upload.
    ///
    /// `POST /{group}/-/upload/logos`
    pub async fn upload_logos(
        &self,
        group: String,
        body: &crate::models::UploadRequestParams,
    ) -> Result<crate::models::UploadAssetsResponse> {
        let path = format!("/{}/-/upload/logos", group);
        let mut url = self.inner.url(&path)?;
        self.inner
            .execute_with_body::<crate::models::UploadAssetsResponse, _>(Method::POST, url, body)
            .await
    }
}

/// Query parameters for the matching method on the resource client.
#[derive(Debug, Clone, Default, Serialize)]
#[non_exhaustive]
pub struct GetGroupsByUserIDQuery {
    /// Filter organizations.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub search: Option<String>,
    /// Pagination page number
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page: Option<i64>,
    /// Pagination page size
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page_size: Option<i64>,
}

impl GetGroupsByUserIDQuery {
    /// Construct an empty query.
    pub fn new() -> Self {
        Self::default()
    }
    /// Set `search` query parameter.
    pub fn search(mut self, v: impl Into<String>) -> Self {
        self.search = Some(v.into());
        self
    }
    /// Set `page` query parameter.
    pub fn page(mut self, v: impl Into<i64>) -> Self {
        self.page = Some(v.into());
        self
    }
    /// Set `page_size` query parameter.
    pub fn page_size(mut self, v: impl Into<i64>) -> Self {
        self.page_size = Some(v.into());
        self
    }
}

/// Query parameters for the matching method on the resource client.
#[derive(Debug, Clone, Default, Serialize)]
#[non_exhaustive]
pub struct ListGroupsQuery {
    /// Pagination page number
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page: Option<i64>,
    /// Pagination page size
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page_size: Option<i64>,
    /// access level
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub access: Option<i64>,
}

impl ListGroupsQuery {
    /// Construct an empty query.
    pub fn new() -> Self {
        Self::default()
    }
    /// Set `page` query parameter.
    pub fn page(mut self, v: impl Into<i64>) -> Self {
        self.page = Some(v.into());
        self
    }
    /// Set `page_size` query parameter.
    pub fn page_size(mut self, v: impl Into<i64>) -> Self {
        self.page_size = Some(v.into());
        self
    }
    /// Set `access` query parameter.
    pub fn access(mut self, v: impl Into<i64>) -> Self {
        self.access = Some(v.into());
        self
    }
}

/// Query parameters for the matching method on the resource client.
#[derive(Debug, Clone, Default, Serialize)]
#[non_exhaustive]
pub struct ListSubgroupsQuery {
    /// Filter organization
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub search: Option<String>,
    /// Pagination page number
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page: Option<i64>,
    /// Pagination page size
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page_size: Option<i64>,
}

impl ListSubgroupsQuery {
    /// Construct an empty query.
    pub fn new() -> Self {
        Self::default()
    }
    /// Set `search` query parameter.
    pub fn search(mut self, v: impl Into<String>) -> Self {
        self.search = Some(v.into());
        self
    }
    /// Set `page` query parameter.
    pub fn page(mut self, v: impl Into<i64>) -> Self {
        self.page = Some(v.into());
        self
    }
    /// Set `page_size` query parameter.
    pub fn page_size(mut self, v: impl Into<i64>) -> Self {
        self.page_size = Some(v.into());
        self
    }
}

/// Query parameters for the matching method on the resource client.
#[derive(Debug, Clone, Default, Serialize)]
#[non_exhaustive]
pub struct ListTopGroupsQuery {
    /// Pagination page number
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page: Option<i64>,
    /// Pagination page size
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub page_size: Option<i64>,
    /// Filter by organizations.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub search: Option<String>,
    /// Filter by role.
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub role: Option<String>,
}

impl ListTopGroupsQuery {
    /// Construct an empty query.
    pub fn new() -> Self {
        Self::default()
    }
    /// Set `page` query parameter.
    pub fn page(mut self, v: impl Into<i64>) -> Self {
        self.page = Some(v.into());
        self
    }
    /// Set `page_size` query parameter.
    pub fn page_size(mut self, v: impl Into<i64>) -> Self {
        self.page_size = Some(v.into());
        self
    }
    /// Set `search` query parameter.
    pub fn search(mut self, v: impl Into<String>) -> Self {
        self.search = Some(v.into());
        self
    }
    /// Set `role` query parameter.
    pub fn role(mut self, v: impl Into<String>) -> Self {
        self.role = Some(v.into());
        self
    }
}