clientapi_pbs/apis/
access_ticket_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AccessTicketCreateTicketError {
22 Status400(models::PbsError),
23 Status401(models::PbsError),
24 Status403(models::PbsError),
25 Status404(models::PbsError),
26 Status500(models::PbsError),
27 Status501(models::PbsError),
28 Status503(models::PbsError),
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum AccessTicketDeleteTicketError {
36 Status400(models::PbsError),
37 Status401(models::PbsError),
38 Status403(models::PbsError),
39 Status404(models::PbsError),
40 Status500(models::PbsError),
41 Status501(models::PbsError),
42 Status503(models::PbsError),
43 UnknownValue(serde_json::Value),
44}
45
46
47pub async fn access_ticket_create_ticket(configuration: &configuration::Configuration, access_ticket_create_ticket_request: models::AccessTicketCreateTicketRequest) -> Result<models::AccessTicketCreateTicketResponse, Error<AccessTicketCreateTicketError>> {
49 let p_body_access_ticket_create_ticket_request = access_ticket_create_ticket_request;
51
52 let uri_str = format!("{}/access/ticket", configuration.base_path);
53 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
54
55 if let Some(ref user_agent) = configuration.user_agent {
56 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
57 }
58 req_builder = req_builder.json(&p_body_access_ticket_create_ticket_request);
59
60 let req = req_builder.build()?;
61 let resp = configuration.client.execute(req).await?;
62
63 let status = resp.status();
64 let content_type = resp
65 .headers()
66 .get("content-type")
67 .and_then(|v| v.to_str().ok())
68 .unwrap_or("application/octet-stream");
69 let content_type = super::ContentType::from(content_type);
70
71 if !status.is_client_error() && !status.is_server_error() {
72 let content = resp.text().await?;
73 match content_type {
74 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
75 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTicketCreateTicketResponse`"))),
76 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AccessTicketCreateTicketResponse`")))),
77 }
78 } else {
79 let content = resp.text().await?;
80 let entity: Option<AccessTicketCreateTicketError> = serde_json::from_str(&content).ok();
81 Err(Error::ResponseError(ResponseContent { status, content, entity }))
82 }
83}
84
85pub async fn access_ticket_delete_ticket(configuration: &configuration::Configuration, ) -> Result<models::AccessTicketDeleteTicketResponse, Error<AccessTicketDeleteTicketError>> {
87
88 let uri_str = format!("{}/access/ticket", configuration.base_path);
89 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
90
91 if let Some(ref user_agent) = configuration.user_agent {
92 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
93 }
94
95 let req = req_builder.build()?;
96 let resp = configuration.client.execute(req).await?;
97
98 let status = resp.status();
99 let content_type = resp
100 .headers()
101 .get("content-type")
102 .and_then(|v| v.to_str().ok())
103 .unwrap_or("application/octet-stream");
104 let content_type = super::ContentType::from(content_type);
105
106 if !status.is_client_error() && !status.is_server_error() {
107 let content = resp.text().await?;
108 match content_type {
109 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
110 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTicketDeleteTicketResponse`"))),
111 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::AccessTicketDeleteTicketResponse`")))),
112 }
113 } else {
114 let content = resp.text().await?;
115 let entity: Option<AccessTicketDeleteTicketError> = serde_json::from_str(&content).ok();
116 Err(Error::ResponseError(ResponseContent { status, content, entity }))
117 }
118}
119