1use reqwest;
12
13use super::{configuration, Error};
14use crate::apis::ResponseContent;
15use serde::{Deserialize, Serialize};
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum AcceptInviteError {
21 UnknownValue(serde_json::Value),
22}
23
24#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum AddUserToOrgError {
28 UnknownValue(serde_json::Value),
29}
30
31#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum CreateOrganizationError {
35 UnknownValue(serde_json::Value),
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum DeleteOrganizationError {
42 UnknownValue(serde_json::Value),
43}
44
45#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum GetOrganizationError {
49 UnknownValue(serde_json::Value),
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum ListInvitesError {
56 UnknownValue(serde_json::Value),
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum ListOrganizationsError {
63 UnknownValue(serde_json::Value),
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum ListUsersInOrgError {
70 UnknownValue(serde_json::Value),
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize)]
75#[serde(untagged)]
76pub enum RemoveUserFromOrgError {
77 UnknownValue(serde_json::Value),
78}
79
80#[derive(Debug, Clone, Serialize, Deserialize)]
82#[serde(untagged)]
83pub enum UpdateOrganizationError {
84 UnknownValue(serde_json::Value),
85}
86
87#[derive(Debug, Clone, Serialize, Deserialize)]
89#[serde(untagged)]
90pub enum UpdateUserInOrgError {
91 UnknownValue(serde_json::Value),
92}
93
94pub async fn accept_invite(
95 configuration: &configuration::Configuration,
96 workspace: &str,
97 org: &str,
98 code: &str,
99) -> Result<(), Error<AcceptInviteError>> {
100 let local_var_configuration = configuration;
101
102 let local_var_client = &local_var_configuration.client;
103
104 let local_var_uri_str = format!(
105 "{}/workspaces/{workspace}/orgs/{org}/invites/{code}/accept",
106 local_var_configuration.base_path,
107 workspace = crate::apis::urlencode(workspace),
108 org = crate::apis::urlencode(org),
109 code = crate::apis::urlencode(code)
110 );
111 let mut local_var_req_builder =
112 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
113
114 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
115 local_var_req_builder =
116 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
117 }
118
119 let local_var_req = local_var_req_builder.build()?;
120 let local_var_resp = local_var_client.execute(local_var_req).await?;
121
122 let local_var_status = local_var_resp.status();
123 let local_var_content = local_var_resp.text().await?;
124
125 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
126 Ok(())
127 } else {
128 let local_var_entity: Option<AcceptInviteError> =
129 serde_json::from_str(&local_var_content).ok();
130 let local_var_error = ResponseContent {
131 status: local_var_status,
132 content: local_var_content,
133 entity: local_var_entity,
134 };
135 Err(Error::ResponseError(local_var_error))
136 }
137}
138
139pub async fn add_user_to_org(
140 configuration: &configuration::Configuration,
141 workspace: &str,
142 org: &str,
143 add_user_to_org_request: crate::models::AddUserToOrgRequest,
144) -> Result<crate::models::User, Error<AddUserToOrgError>> {
145 let local_var_configuration = configuration;
146
147 let local_var_client = &local_var_configuration.client;
148
149 let local_var_uri_str = format!(
150 "{}/workspaces/{workspace}/orgs/{org}/users",
151 local_var_configuration.base_path,
152 workspace = crate::apis::urlencode(workspace),
153 org = crate::apis::urlencode(org)
154 );
155 let mut local_var_req_builder =
156 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
157
158 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
159 local_var_req_builder =
160 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
161 }
162 local_var_req_builder = local_var_req_builder.json(&add_user_to_org_request);
163
164 let local_var_req = local_var_req_builder.build()?;
165 let local_var_resp = local_var_client.execute(local_var_req).await?;
166
167 let local_var_status = local_var_resp.status();
168 let local_var_content = local_var_resp.text().await?;
169
170 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
171 serde_json::from_str(&local_var_content).map_err(Error::from)
172 } else {
173 let local_var_entity: Option<AddUserToOrgError> =
174 serde_json::from_str(&local_var_content).ok();
175 let local_var_error = ResponseContent {
176 status: local_var_status,
177 content: local_var_content,
178 entity: local_var_entity,
179 };
180 Err(Error::ResponseError(local_var_error))
181 }
182}
183
184pub async fn create_organization(
185 configuration: &configuration::Configuration,
186 workspace: &str,
187 create_organization_request: crate::models::CreateOrganizationRequest,
188) -> Result<crate::models::Organization, Error<CreateOrganizationError>> {
189 let local_var_configuration = configuration;
190
191 let local_var_client = &local_var_configuration.client;
192
193 let local_var_uri_str = format!(
194 "{}/workspaces/{workspace}/orgs",
195 local_var_configuration.base_path,
196 workspace = crate::apis::urlencode(workspace)
197 );
198 let mut local_var_req_builder =
199 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
200
201 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
202 local_var_req_builder =
203 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
204 }
205 local_var_req_builder = local_var_req_builder.json(&create_organization_request);
206
207 let local_var_req = local_var_req_builder.build()?;
208 let local_var_resp = local_var_client.execute(local_var_req).await?;
209
210 let local_var_status = local_var_resp.status();
211 let local_var_content = local_var_resp.text().await?;
212
213 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
214 serde_json::from_str(&local_var_content).map_err(Error::from)
215 } else {
216 let local_var_entity: Option<CreateOrganizationError> =
217 serde_json::from_str(&local_var_content).ok();
218 let local_var_error = ResponseContent {
219 status: local_var_status,
220 content: local_var_content,
221 entity: local_var_entity,
222 };
223 Err(Error::ResponseError(local_var_error))
224 }
225}
226
227pub async fn delete_organization(
228 configuration: &configuration::Configuration,
229 workspace: &str,
230 org: &str,
231) -> Result<(), Error<DeleteOrganizationError>> {
232 let local_var_configuration = configuration;
233
234 let local_var_client = &local_var_configuration.client;
235
236 let local_var_uri_str = format!(
237 "{}/workspaces/{workspace}/orgs/{org}",
238 local_var_configuration.base_path,
239 workspace = crate::apis::urlencode(workspace),
240 org = crate::apis::urlencode(org)
241 );
242 let mut local_var_req_builder =
243 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
244
245 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
246 local_var_req_builder =
247 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
248 }
249
250 let local_var_req = local_var_req_builder.build()?;
251 let local_var_resp = local_var_client.execute(local_var_req).await?;
252
253 let local_var_status = local_var_resp.status();
254 let local_var_content = local_var_resp.text().await?;
255
256 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
257 Ok(())
258 } else {
259 let local_var_entity: Option<DeleteOrganizationError> =
260 serde_json::from_str(&local_var_content).ok();
261 let local_var_error = ResponseContent {
262 status: local_var_status,
263 content: local_var_content,
264 entity: local_var_entity,
265 };
266 Err(Error::ResponseError(local_var_error))
267 }
268}
269
270pub async fn get_organization(
271 configuration: &configuration::Configuration,
272 workspace: &str,
273 org: &str,
274) -> Result<crate::models::Organization, Error<GetOrganizationError>> {
275 let local_var_configuration = configuration;
276
277 let local_var_client = &local_var_configuration.client;
278
279 let local_var_uri_str = format!(
280 "{}/workspaces/{workspace}/orgs/{org}",
281 local_var_configuration.base_path,
282 workspace = crate::apis::urlencode(workspace),
283 org = crate::apis::urlencode(org)
284 );
285 let mut local_var_req_builder =
286 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
287
288 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
289 local_var_req_builder =
290 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
291 }
292
293 let local_var_req = local_var_req_builder.build()?;
294 let local_var_resp = local_var_client.execute(local_var_req).await?;
295
296 let local_var_status = local_var_resp.status();
297 let local_var_content = local_var_resp.text().await?;
298
299 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
300 serde_json::from_str(&local_var_content).map_err(Error::from)
301 } else {
302 let local_var_entity: Option<GetOrganizationError> =
303 serde_json::from_str(&local_var_content).ok();
304 let local_var_error = ResponseContent {
305 status: local_var_status,
306 content: local_var_content,
307 entity: local_var_entity,
308 };
309 Err(Error::ResponseError(local_var_error))
310 }
311}
312
313pub async fn list_invites(
314 configuration: &configuration::Configuration,
315 workspace: &str,
316 org: &str,
317) -> Result<Vec<crate::models::Invite>, Error<ListInvitesError>> {
318 let local_var_configuration = configuration;
319
320 let local_var_client = &local_var_configuration.client;
321
322 let local_var_uri_str = format!(
323 "{}/workspaces/{workspace}/orgs/{org}/invites",
324 local_var_configuration.base_path,
325 workspace = crate::apis::urlencode(workspace),
326 org = crate::apis::urlencode(org)
327 );
328 let mut local_var_req_builder =
329 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
330
331 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
332 local_var_req_builder =
333 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
334 }
335
336 let local_var_req = local_var_req_builder.build()?;
337 let local_var_resp = local_var_client.execute(local_var_req).await?;
338
339 let local_var_status = local_var_resp.status();
340 let local_var_content = local_var_resp.text().await?;
341
342 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
343 serde_json::from_str(&local_var_content).map_err(Error::from)
344 } else {
345 let local_var_entity: Option<ListInvitesError> =
346 serde_json::from_str(&local_var_content).ok();
347 let local_var_error = ResponseContent {
348 status: local_var_status,
349 content: local_var_content,
350 entity: local_var_entity,
351 };
352 Err(Error::ResponseError(local_var_error))
353 }
354}
355
356pub async fn list_organizations(
357 configuration: &configuration::Configuration,
358 workspace: &str,
359) -> Result<Vec<crate::models::Organization>, Error<ListOrganizationsError>> {
360 let local_var_configuration = configuration;
361
362 let local_var_client = &local_var_configuration.client;
363
364 let local_var_uri_str = format!(
365 "{}/workspaces/{workspace}/orgs",
366 local_var_configuration.base_path,
367 workspace = crate::apis::urlencode(workspace)
368 );
369 let mut local_var_req_builder =
370 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
371
372 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
373 local_var_req_builder =
374 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
375 }
376
377 let local_var_req = local_var_req_builder.build()?;
378 let local_var_resp = local_var_client.execute(local_var_req).await?;
379
380 let local_var_status = local_var_resp.status();
381 let local_var_content = local_var_resp.text().await?;
382
383 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
384 serde_json::from_str(&local_var_content).map_err(Error::from)
385 } else {
386 let local_var_entity: Option<ListOrganizationsError> =
387 serde_json::from_str(&local_var_content).ok();
388 let local_var_error = ResponseContent {
389 status: local_var_status,
390 content: local_var_content,
391 entity: local_var_entity,
392 };
393 Err(Error::ResponseError(local_var_error))
394 }
395}
396
397pub async fn list_users_in_org(
398 configuration: &configuration::Configuration,
399 workspace: &str,
400 org: &str,
401) -> Result<Vec<crate::models::User>, Error<ListUsersInOrgError>> {
402 let local_var_configuration = configuration;
403
404 let local_var_client = &local_var_configuration.client;
405
406 let local_var_uri_str = format!(
407 "{}/workspaces/{workspace}/orgs/{org}/users",
408 local_var_configuration.base_path,
409 workspace = crate::apis::urlencode(workspace),
410 org = crate::apis::urlencode(org)
411 );
412 let mut local_var_req_builder =
413 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
414
415 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
416 local_var_req_builder =
417 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
418 }
419
420 let local_var_req = local_var_req_builder.build()?;
421 let local_var_resp = local_var_client.execute(local_var_req).await?;
422
423 let local_var_status = local_var_resp.status();
424 let local_var_content = local_var_resp.text().await?;
425
426 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
427 serde_json::from_str(&local_var_content).map_err(Error::from)
428 } else {
429 let local_var_entity: Option<ListUsersInOrgError> =
430 serde_json::from_str(&local_var_content).ok();
431 let local_var_error = ResponseContent {
432 status: local_var_status,
433 content: local_var_content,
434 entity: local_var_entity,
435 };
436 Err(Error::ResponseError(local_var_error))
437 }
438}
439
440pub async fn remove_user_from_org(
441 configuration: &configuration::Configuration,
442 workspace: &str,
443 org: &str,
444 user: &str,
445) -> Result<(), Error<RemoveUserFromOrgError>> {
446 let local_var_configuration = configuration;
447
448 let local_var_client = &local_var_configuration.client;
449
450 let local_var_uri_str = format!(
451 "{}/workspaces/{workspace}/orgs/{org}/users/{user}",
452 local_var_configuration.base_path,
453 workspace = crate::apis::urlencode(workspace),
454 org = crate::apis::urlencode(org),
455 user = crate::apis::urlencode(user)
456 );
457 let mut local_var_req_builder =
458 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
459
460 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
461 local_var_req_builder =
462 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
463 }
464
465 let local_var_req = local_var_req_builder.build()?;
466 let local_var_resp = local_var_client.execute(local_var_req).await?;
467
468 let local_var_status = local_var_resp.status();
469 let local_var_content = local_var_resp.text().await?;
470
471 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
472 Ok(())
473 } else {
474 let local_var_entity: Option<RemoveUserFromOrgError> =
475 serde_json::from_str(&local_var_content).ok();
476 let local_var_error = ResponseContent {
477 status: local_var_status,
478 content: local_var_content,
479 entity: local_var_entity,
480 };
481 Err(Error::ResponseError(local_var_error))
482 }
483}
484
485pub async fn update_organization(
486 configuration: &configuration::Configuration,
487 workspace: &str,
488 org: &str,
489 update_organization_request: crate::models::UpdateOrganizationRequest,
490) -> Result<crate::models::Organization, Error<UpdateOrganizationError>> {
491 let local_var_configuration = configuration;
492
493 let local_var_client = &local_var_configuration.client;
494
495 let local_var_uri_str = format!(
496 "{}/workspaces/{workspace}/orgs/{org}",
497 local_var_configuration.base_path,
498 workspace = crate::apis::urlencode(workspace),
499 org = crate::apis::urlencode(org)
500 );
501 let mut local_var_req_builder =
502 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
503
504 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
505 local_var_req_builder =
506 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
507 }
508 local_var_req_builder = local_var_req_builder.json(&update_organization_request);
509
510 let local_var_req = local_var_req_builder.build()?;
511 let local_var_resp = local_var_client.execute(local_var_req).await?;
512
513 let local_var_status = local_var_resp.status();
514 let local_var_content = local_var_resp.text().await?;
515
516 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
517 serde_json::from_str(&local_var_content).map_err(Error::from)
518 } else {
519 let local_var_entity: Option<UpdateOrganizationError> =
520 serde_json::from_str(&local_var_content).ok();
521 let local_var_error = ResponseContent {
522 status: local_var_status,
523 content: local_var_content,
524 entity: local_var_entity,
525 };
526 Err(Error::ResponseError(local_var_error))
527 }
528}
529
530pub async fn update_user_in_org(
531 configuration: &configuration::Configuration,
532 workspace: &str,
533 org: &str,
534 user: &str,
535 update_organization_membership_request: crate::models::UpdateOrganizationMembershipRequest,
536) -> Result<crate::models::User, Error<UpdateUserInOrgError>> {
537 let local_var_configuration = configuration;
538
539 let local_var_client = &local_var_configuration.client;
540
541 let local_var_uri_str = format!(
542 "{}/workspaces/{workspace}/orgs/{org}/users/{user}",
543 local_var_configuration.base_path,
544 workspace = crate::apis::urlencode(workspace),
545 org = crate::apis::urlencode(org),
546 user = crate::apis::urlencode(user)
547 );
548 let mut local_var_req_builder =
549 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
550
551 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
552 local_var_req_builder =
553 local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
554 }
555 local_var_req_builder = local_var_req_builder.json(&update_organization_membership_request);
556
557 let local_var_req = local_var_req_builder.build()?;
558 let local_var_resp = local_var_client.execute(local_var_req).await?;
559
560 let local_var_status = local_var_resp.status();
561 let local_var_content = local_var_resp.text().await?;
562
563 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
564 serde_json::from_str(&local_var_content).map_err(Error::from)
565 } else {
566 let local_var_entity: Option<UpdateUserInOrgError> =
567 serde_json::from_str(&local_var_content).ok();
568 let local_var_error = ResponseContent {
569 status: local_var_status,
570 content: local_var_content,
571 entity: local_var_entity,
572 };
573 Err(Error::ResponseError(local_var_error))
574 }
575}