1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum AttemptOrganizationDomainVerificationError {
20 Status400(models::ClerkErrors),
21 Status401(models::ClerkErrors),
22 Status403(models::ClerkErrors),
23 Status404(models::ClerkErrors),
24 Status422(models::ClerkErrors),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum CreateOrganizationDomainError {
32 Status401(models::ClerkErrors),
33 Status403(models::ClerkErrors),
34 Status404(models::ClerkErrors),
35 Status422(models::ClerkErrors),
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum DeleteOrganizationDomainError {
43 Status401(models::ClerkErrors),
44 Status403(models::ClerkErrors),
45 Status404(models::ClerkErrors),
46 Status422(models::ClerkErrors),
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetOrganizationDomainError {
54 Status401(models::ClerkErrors),
55 Status403(models::ClerkErrors),
56 Status404(models::ClerkErrors),
57 Status422(models::ClerkErrors),
58 UnknownValue(serde_json::Value),
59}
60
61#[derive(Debug, Clone, Serialize, Deserialize)]
63#[serde(untagged)]
64pub enum ListOrganizationDomainsError {
65 Status401(models::ClerkErrors),
66 Status403(models::ClerkErrors),
67 Status422(models::ClerkErrors),
68 UnknownValue(serde_json::Value),
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(untagged)]
74pub enum PrepareOrganizationDomainVerificationError {
75 Status401(models::ClerkErrors),
76 Status403(models::ClerkErrors),
77 Status404(models::ClerkErrors),
78 Status422(models::ClerkErrors),
79 UnknownValue(serde_json::Value),
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(untagged)]
85pub enum UpdateOrganizationDomainEnrollmentModeError {
86 Status401(models::ClerkErrors),
87 Status403(models::ClerkErrors),
88 Status404(models::ClerkErrors),
89 Status422(models::ClerkErrors),
90 UnknownValue(serde_json::Value),
91}
92
93pub async fn attempt_organization_domain_verification(
95 configuration: &configuration::Configuration,
96 organization_id: &str,
97 domain_id: &str,
98 code: &str,
99) -> Result<
100 models::ClientClientWrappedOrganizationDomain,
101 Error<AttemptOrganizationDomainVerificationError>,
102> {
103 let p_path_organization_id = organization_id;
105 let p_path_domain_id = domain_id;
106 let p_form_code = code;
107
108 let uri_str = format!("{}/v1/organizations/{organization_id}/domains/{domain_id}/attempt_affiliation_verification", configuration.base_path, organization_id=crate::apis::urlencode(p_path_organization_id), domain_id=crate::apis::urlencode(p_path_domain_id));
109 let mut req_builder = configuration
110 .client
111 .request(reqwest::Method::POST, &uri_str);
112
113 if let Some(ref apikey) = configuration.api_key {
114 let key = apikey.key.clone();
115 let value = match apikey.prefix {
116 Some(ref prefix) => format!("{prefix} {key}"),
117 None => key,
118 };
119 req_builder = req_builder.query(&[("__dev_session", value)]);
120 }
121 if let Some(ref user_agent) = configuration.user_agent {
122 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
123 }
124 if let Some(ref apikey) = configuration.api_key {
125 let key = apikey.key.clone();
126 let value = match apikey.prefix {
127 Some(ref prefix) => format!("{prefix} {key}"),
128 None => key,
129 };
130 req_builder = req_builder.header("__session", value);
131 };
132 let mut multipart_form_params = std::collections::HashMap::new();
133 multipart_form_params.insert("code", p_form_code.to_string());
134 req_builder = req_builder.form(&multipart_form_params);
135
136 let req = req_builder.build()?;
137 let resp = configuration.client.execute(req).await?;
138
139 let status = resp.status();
140 let content_type = resp
141 .headers()
142 .get("content-type")
143 .and_then(|v| v.to_str().ok())
144 .unwrap_or("application/octet-stream");
145 let content_type = super::ContentType::from(content_type);
146
147 if !status.is_client_error() && !status.is_server_error() {
148 let content = resp.text().await?;
149 match content_type {
150 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
151 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedOrganizationDomain`"))),
152 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedOrganizationDomain`")))),
153 }
154 } else {
155 let content = resp.text().await?;
156 let entity: Option<AttemptOrganizationDomainVerificationError> =
157 serde_json::from_str(&content).ok();
158 Err(Error::ResponseError(ResponseContent {
159 status,
160 content,
161 entity,
162 }))
163 }
164}
165
166pub async fn create_organization_domain(
168 configuration: &configuration::Configuration,
169 organization_id: &str,
170 name: &str,
171) -> Result<models::ClientClientWrappedOrganizationDomain, Error<CreateOrganizationDomainError>> {
172 let p_path_organization_id = organization_id;
174 let p_form_name = name;
175
176 let uri_str = format!(
177 "{}/v1/organizations/{organization_id}/domains",
178 configuration.base_path,
179 organization_id = crate::apis::urlencode(p_path_organization_id)
180 );
181 let mut req_builder = configuration
182 .client
183 .request(reqwest::Method::POST, &uri_str);
184
185 if let Some(ref apikey) = configuration.api_key {
186 let key = apikey.key.clone();
187 let value = match apikey.prefix {
188 Some(ref prefix) => format!("{prefix} {key}"),
189 None => key,
190 };
191 req_builder = req_builder.query(&[("__dev_session", value)]);
192 }
193 if let Some(ref user_agent) = configuration.user_agent {
194 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
195 }
196 if let Some(ref apikey) = configuration.api_key {
197 let key = apikey.key.clone();
198 let value = match apikey.prefix {
199 Some(ref prefix) => format!("{prefix} {key}"),
200 None => key,
201 };
202 req_builder = req_builder.header("__session", value);
203 };
204 let mut multipart_form_params = std::collections::HashMap::new();
205 multipart_form_params.insert("name", p_form_name.to_string());
206 req_builder = req_builder.form(&multipart_form_params);
207
208 let req = req_builder.build()?;
209 let resp = configuration.client.execute(req).await?;
210
211 let status = resp.status();
212 let content_type = resp
213 .headers()
214 .get("content-type")
215 .and_then(|v| v.to_str().ok())
216 .unwrap_or("application/octet-stream");
217 let content_type = super::ContentType::from(content_type);
218
219 if !status.is_client_error() && !status.is_server_error() {
220 let content = resp.text().await?;
221 match content_type {
222 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
223 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedOrganizationDomain`"))),
224 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedOrganizationDomain`")))),
225 }
226 } else {
227 let content = resp.text().await?;
228 let entity: Option<CreateOrganizationDomainError> = serde_json::from_str(&content).ok();
229 Err(Error::ResponseError(ResponseContent {
230 status,
231 content,
232 entity,
233 }))
234 }
235}
236
237pub async fn delete_organization_domain(
239 configuration: &configuration::Configuration,
240 organization_id: &str,
241 domain_id: &str,
242) -> Result<models::ClientClientWrappedDeletedObject, Error<DeleteOrganizationDomainError>> {
243 let p_path_organization_id = organization_id;
245 let p_path_domain_id = domain_id;
246
247 let uri_str = format!(
248 "{}/v1/organizations/{organization_id}/domains/{domain_id}",
249 configuration.base_path,
250 organization_id = crate::apis::urlencode(p_path_organization_id),
251 domain_id = crate::apis::urlencode(p_path_domain_id)
252 );
253 let mut req_builder = configuration
254 .client
255 .request(reqwest::Method::DELETE, &uri_str);
256
257 if let Some(ref apikey) = configuration.api_key {
258 let key = apikey.key.clone();
259 let value = match apikey.prefix {
260 Some(ref prefix) => format!("{prefix} {key}"),
261 None => key,
262 };
263 req_builder = req_builder.query(&[("__dev_session", value)]);
264 }
265 if let Some(ref user_agent) = configuration.user_agent {
266 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
267 }
268 if let Some(ref apikey) = configuration.api_key {
269 let key = apikey.key.clone();
270 let value = match apikey.prefix {
271 Some(ref prefix) => format!("{prefix} {key}"),
272 None => key,
273 };
274 req_builder = req_builder.header("__session", value);
275 };
276
277 let req = req_builder.build()?;
278 let resp = configuration.client.execute(req).await?;
279
280 let status = resp.status();
281 let content_type = resp
282 .headers()
283 .get("content-type")
284 .and_then(|v| v.to_str().ok())
285 .unwrap_or("application/octet-stream");
286 let content_type = super::ContentType::from(content_type);
287
288 if !status.is_client_error() && !status.is_server_error() {
289 let content = resp.text().await?;
290 match content_type {
291 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
292 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedDeletedObject`"))),
293 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedDeletedObject`")))),
294 }
295 } else {
296 let content = resp.text().await?;
297 let entity: Option<DeleteOrganizationDomainError> = serde_json::from_str(&content).ok();
298 Err(Error::ResponseError(ResponseContent {
299 status,
300 content,
301 entity,
302 }))
303 }
304}
305
306pub async fn get_organization_domain(
308 configuration: &configuration::Configuration,
309 organization_id: &str,
310 domain_id: &str,
311) -> Result<models::ClientClientWrappedOrganizationDomain, Error<GetOrganizationDomainError>> {
312 let p_path_organization_id = organization_id;
314 let p_path_domain_id = domain_id;
315
316 let uri_str = format!(
317 "{}/v1/organizations/{organization_id}/domains/{domain_id}",
318 configuration.base_path,
319 organization_id = crate::apis::urlencode(p_path_organization_id),
320 domain_id = crate::apis::urlencode(p_path_domain_id)
321 );
322 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
323
324 if let Some(ref apikey) = configuration.api_key {
325 let key = apikey.key.clone();
326 let value = match apikey.prefix {
327 Some(ref prefix) => format!("{prefix} {key}"),
328 None => key,
329 };
330 req_builder = req_builder.query(&[("__dev_session", value)]);
331 }
332 if let Some(ref user_agent) = configuration.user_agent {
333 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
334 }
335 if let Some(ref apikey) = configuration.api_key {
336 let key = apikey.key.clone();
337 let value = match apikey.prefix {
338 Some(ref prefix) => format!("{prefix} {key}"),
339 None => key,
340 };
341 req_builder = req_builder.header("__session", value);
342 };
343
344 let req = req_builder.build()?;
345 let resp = configuration.client.execute(req).await?;
346
347 let status = resp.status();
348 let content_type = resp
349 .headers()
350 .get("content-type")
351 .and_then(|v| v.to_str().ok())
352 .unwrap_or("application/octet-stream");
353 let content_type = super::ContentType::from(content_type);
354
355 if !status.is_client_error() && !status.is_server_error() {
356 let content = resp.text().await?;
357 match content_type {
358 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
359 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedOrganizationDomain`"))),
360 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedOrganizationDomain`")))),
361 }
362 } else {
363 let content = resp.text().await?;
364 let entity: Option<GetOrganizationDomainError> = serde_json::from_str(&content).ok();
365 Err(Error::ResponseError(ResponseContent {
366 status,
367 content,
368 entity,
369 }))
370 }
371}
372
373pub async fn list_organization_domains(
375 configuration: &configuration::Configuration,
376 organization_id: &str,
377 limit: Option<i64>,
378 offset: Option<i64>,
379 verified: Option<bool>,
380 enrollment_mode: Option<&str>,
381) -> Result<models::ClientClientWrappedOrganizationDomains, Error<ListOrganizationDomainsError>> {
382 let p_path_organization_id = organization_id;
384 let p_query_limit = limit;
385 let p_query_offset = offset;
386 let p_query_verified = verified;
387 let p_query_enrollment_mode = enrollment_mode;
388
389 let uri_str = format!(
390 "{}/v1/organizations/{organization_id}/domains",
391 configuration.base_path,
392 organization_id = crate::apis::urlencode(p_path_organization_id)
393 );
394 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
395
396 if let Some(ref param_value) = p_query_limit {
397 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
398 }
399 if let Some(ref param_value) = p_query_offset {
400 req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
401 }
402 if let Some(ref param_value) = p_query_verified {
403 req_builder = req_builder.query(&[("verified", ¶m_value.to_string())]);
404 }
405 if let Some(ref param_value) = p_query_enrollment_mode {
406 req_builder = req_builder.query(&[("enrollment_mode", ¶m_value.to_string())]);
407 }
408 if let Some(ref apikey) = configuration.api_key {
409 let key = apikey.key.clone();
410 let value = match apikey.prefix {
411 Some(ref prefix) => format!("{prefix} {key}"),
412 None => key,
413 };
414 req_builder = req_builder.query(&[("__dev_session", value)]);
415 }
416 if let Some(ref user_agent) = configuration.user_agent {
417 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
418 }
419 if let Some(ref apikey) = configuration.api_key {
420 let key = apikey.key.clone();
421 let value = match apikey.prefix {
422 Some(ref prefix) => format!("{prefix} {key}"),
423 None => key,
424 };
425 req_builder = req_builder.header("__session", value);
426 };
427
428 let req = req_builder.build()?;
429 let resp = configuration.client.execute(req).await?;
430
431 let status = resp.status();
432 let content_type = resp
433 .headers()
434 .get("content-type")
435 .and_then(|v| v.to_str().ok())
436 .unwrap_or("application/octet-stream");
437 let content_type = super::ContentType::from(content_type);
438
439 if !status.is_client_error() && !status.is_server_error() {
440 let content = resp.text().await?;
441 match content_type {
442 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
443 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedOrganizationDomains`"))),
444 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedOrganizationDomains`")))),
445 }
446 } else {
447 let content = resp.text().await?;
448 let entity: Option<ListOrganizationDomainsError> = serde_json::from_str(&content).ok();
449 Err(Error::ResponseError(ResponseContent {
450 status,
451 content,
452 entity,
453 }))
454 }
455}
456
457pub async fn prepare_organization_domain_verification(
459 configuration: &configuration::Configuration,
460 organization_id: &str,
461 domain_id: &str,
462 affiliation_email_address: &str,
463) -> Result<
464 models::ClientClientWrappedOrganizationDomain,
465 Error<PrepareOrganizationDomainVerificationError>,
466> {
467 let p_path_organization_id = organization_id;
469 let p_path_domain_id = domain_id;
470 let p_form_affiliation_email_address = affiliation_email_address;
471
472 let uri_str = format!("{}/v1/organizations/{organization_id}/domains/{domain_id}/prepare_affiliation_verification", configuration.base_path, organization_id=crate::apis::urlencode(p_path_organization_id), domain_id=crate::apis::urlencode(p_path_domain_id));
473 let mut req_builder = configuration
474 .client
475 .request(reqwest::Method::POST, &uri_str);
476
477 if let Some(ref apikey) = configuration.api_key {
478 let key = apikey.key.clone();
479 let value = match apikey.prefix {
480 Some(ref prefix) => format!("{prefix} {key}"),
481 None => key,
482 };
483 req_builder = req_builder.query(&[("__dev_session", value)]);
484 }
485 if let Some(ref user_agent) = configuration.user_agent {
486 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
487 }
488 if let Some(ref apikey) = configuration.api_key {
489 let key = apikey.key.clone();
490 let value = match apikey.prefix {
491 Some(ref prefix) => format!("{prefix} {key}"),
492 None => key,
493 };
494 req_builder = req_builder.header("__session", value);
495 };
496 let mut multipart_form_params = std::collections::HashMap::new();
497 multipart_form_params.insert(
498 "affiliation_email_address",
499 p_form_affiliation_email_address.to_string(),
500 );
501 req_builder = req_builder.form(&multipart_form_params);
502
503 let req = req_builder.build()?;
504 let resp = configuration.client.execute(req).await?;
505
506 let status = resp.status();
507 let content_type = resp
508 .headers()
509 .get("content-type")
510 .and_then(|v| v.to_str().ok())
511 .unwrap_or("application/octet-stream");
512 let content_type = super::ContentType::from(content_type);
513
514 if !status.is_client_error() && !status.is_server_error() {
515 let content = resp.text().await?;
516 match content_type {
517 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
518 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedOrganizationDomain`"))),
519 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedOrganizationDomain`")))),
520 }
521 } else {
522 let content = resp.text().await?;
523 let entity: Option<PrepareOrganizationDomainVerificationError> =
524 serde_json::from_str(&content).ok();
525 Err(Error::ResponseError(ResponseContent {
526 status,
527 content,
528 entity,
529 }))
530 }
531}
532
533pub async fn update_organization_domain_enrollment_mode(
535 configuration: &configuration::Configuration,
536 organization_id: &str,
537 domain_id: &str,
538 enrollment_mode: &str,
539 delete_pending: Option<bool>,
540) -> Result<
541 models::ClientClientWrappedOrganizationDomain,
542 Error<UpdateOrganizationDomainEnrollmentModeError>,
543> {
544 let p_path_organization_id = organization_id;
546 let p_path_domain_id = domain_id;
547 let p_form_enrollment_mode = enrollment_mode;
548 let p_form_delete_pending = delete_pending;
549
550 let uri_str = format!(
551 "{}/v1/organizations/{organization_id}/domains/{domain_id}/update_enrollment_mode",
552 configuration.base_path,
553 organization_id = crate::apis::urlencode(p_path_organization_id),
554 domain_id = crate::apis::urlencode(p_path_domain_id)
555 );
556 let mut req_builder = configuration
557 .client
558 .request(reqwest::Method::POST, &uri_str);
559
560 if let Some(ref apikey) = configuration.api_key {
561 let key = apikey.key.clone();
562 let value = match apikey.prefix {
563 Some(ref prefix) => format!("{prefix} {key}"),
564 None => key,
565 };
566 req_builder = req_builder.query(&[("__dev_session", value)]);
567 }
568 if let Some(ref user_agent) = configuration.user_agent {
569 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
570 }
571 if let Some(ref apikey) = configuration.api_key {
572 let key = apikey.key.clone();
573 let value = match apikey.prefix {
574 Some(ref prefix) => format!("{prefix} {key}"),
575 None => key,
576 };
577 req_builder = req_builder.header("__session", value);
578 };
579 let mut multipart_form_params = std::collections::HashMap::new();
580 multipart_form_params.insert("enrollment_mode", p_form_enrollment_mode.to_string());
581 if let Some(param_value) = p_form_delete_pending {
582 multipart_form_params.insert("delete_pending", param_value.to_string());
583 }
584 req_builder = req_builder.form(&multipart_form_params);
585
586 let req = req_builder.build()?;
587 let resp = configuration.client.execute(req).await?;
588
589 let status = resp.status();
590 let content_type = resp
591 .headers()
592 .get("content-type")
593 .and_then(|v| v.to_str().ok())
594 .unwrap_or("application/octet-stream");
595 let content_type = super::ContentType::from(content_type);
596
597 if !status.is_client_error() && !status.is_server_error() {
598 let content = resp.text().await?;
599 match content_type {
600 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
601 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClientClientWrappedOrganizationDomain`"))),
602 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClientClientWrappedOrganizationDomain`")))),
603 }
604 } else {
605 let content = resp.text().await?;
606 let entity: Option<UpdateOrganizationDomainEnrollmentModeError> =
607 serde_json::from_str(&content).ok();
608 Err(Error::ResponseError(ResponseContent {
609 status,
610 content,
611 entity,
612 }))
613 }
614}