1use 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 DeleteClientsByIdSuperadminError {
22 Status401(),
23 Status403(),
24 Status404(),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum GetClientsByIdSuperadminError {
32 Status401(),
33 Status403(),
34 Status404(),
35 UnknownValue(serde_json::Value),
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum GetClientsSuperadminError {
42 Status401(),
43 Status403(),
44 UnknownValue(serde_json::Value),
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum PostClientsSuperadminError {
51 Status401(),
52 Status403(),
53 UnknownValue(serde_json::Value),
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum PutClientsByIdSuperadminError {
60 Status401(),
61 Status403(),
62 Status404(),
63 UnknownValue(serde_json::Value),
64}
65
66
67pub async fn delete_clients_by_id_superadmin(configuration: &configuration::Configuration, id: &str) -> Result<(), Error<DeleteClientsByIdSuperadminError>> {
68 let p_id = id;
70
71 let uri_str = format!("{}/clients/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
72 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
73
74 if let Some(ref user_agent) = configuration.user_agent {
75 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
76 }
77 if let Some(ref token) = configuration.oauth_access_token {
78 req_builder = req_builder.bearer_auth(token.to_owned());
79 };
80
81 let req = req_builder.build()?;
82 let resp = configuration.client.execute(req).await?;
83
84 let status = resp.status();
85
86 if !status.is_client_error() && !status.is_server_error() {
87 Ok(())
88 } else {
89 let content = resp.text().await?;
90 let entity: Option<DeleteClientsByIdSuperadminError> = serde_json::from_str(&content).ok();
91 Err(Error::ResponseError(ResponseContent { status, content, entity }))
92 }
93}
94
95pub async fn get_clients_by_id_superadmin(configuration: &configuration::Configuration, id: &str) -> Result<models::Client, Error<GetClientsByIdSuperadminError>> {
96 let p_id = id;
98
99 let uri_str = format!("{}/clients/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
100 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
101
102 if let Some(ref user_agent) = configuration.user_agent {
103 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
104 }
105 if let Some(ref token) = configuration.oauth_access_token {
106 req_builder = req_builder.bearer_auth(token.to_owned());
107 };
108
109 let req = req_builder.build()?;
110 let resp = configuration.client.execute(req).await?;
111
112 let status = resp.status();
113 let content_type = resp
114 .headers()
115 .get("content-type")
116 .and_then(|v| v.to_str().ok())
117 .unwrap_or("application/octet-stream");
118 let content_type = super::ContentType::from(content_type);
119
120 if !status.is_client_error() && !status.is_server_error() {
121 let content = resp.text().await?;
122 match content_type {
123 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
124 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Client`"))),
125 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::Client`")))),
126 }
127 } else {
128 let content = resp.text().await?;
129 let entity: Option<GetClientsByIdSuperadminError> = serde_json::from_str(&content).ok();
130 Err(Error::ResponseError(ResponseContent { status, content, entity }))
131 }
132}
133
134pub async fn get_clients_superadmin(configuration: &configuration::Configuration, ) -> Result<models::ListWrapperClient, Error<GetClientsSuperadminError>> {
136
137 let uri_str = format!("{}/clients", configuration.base_path);
138 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
139
140 if let Some(ref user_agent) = configuration.user_agent {
141 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
142 }
143 if let Some(ref token) = configuration.oauth_access_token {
144 req_builder = req_builder.bearer_auth(token.to_owned());
145 };
146
147 let req = req_builder.build()?;
148 let resp = configuration.client.execute(req).await?;
149
150 let status = resp.status();
151 let content_type = resp
152 .headers()
153 .get("content-type")
154 .and_then(|v| v.to_str().ok())
155 .unwrap_or("application/octet-stream");
156 let content_type = super::ContentType::from(content_type);
157
158 if !status.is_client_error() && !status.is_server_error() {
159 let content = resp.text().await?;
160 match content_type {
161 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
162 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListWrapperClient`"))),
163 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::ListWrapperClient`")))),
164 }
165 } else {
166 let content = resp.text().await?;
167 let entity: Option<GetClientsSuperadminError> = serde_json::from_str(&content).ok();
168 Err(Error::ResponseError(ResponseContent { status, content, entity }))
169 }
170}
171
172pub async fn post_clients_superadmin(configuration: &configuration::Configuration, new_client: models::NewClient) -> Result<models::Client, Error<PostClientsSuperadminError>> {
174 let p_new_client = new_client;
176
177 let uri_str = format!("{}/clients", configuration.base_path);
178 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
179
180 if let Some(ref user_agent) = configuration.user_agent {
181 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
182 }
183 if let Some(ref token) = configuration.oauth_access_token {
184 req_builder = req_builder.bearer_auth(token.to_owned());
185 };
186 req_builder = req_builder.json(&p_new_client);
187
188 let req = req_builder.build()?;
189 let resp = configuration.client.execute(req).await?;
190
191 let status = resp.status();
192 let content_type = resp
193 .headers()
194 .get("content-type")
195 .and_then(|v| v.to_str().ok())
196 .unwrap_or("application/octet-stream");
197 let content_type = super::ContentType::from(content_type);
198
199 if !status.is_client_error() && !status.is_server_error() {
200 let content = resp.text().await?;
201 match content_type {
202 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
203 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Client`"))),
204 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::Client`")))),
205 }
206 } else {
207 let content = resp.text().await?;
208 let entity: Option<PostClientsSuperadminError> = serde_json::from_str(&content).ok();
209 Err(Error::ResponseError(ResponseContent { status, content, entity }))
210 }
211}
212
213pub async fn put_clients_by_id_superadmin(configuration: &configuration::Configuration, id: &str, client_update: models::ClientUpdate) -> Result<models::Client, Error<PutClientsByIdSuperadminError>> {
214 let p_id = id;
216 let p_client_update = client_update;
217
218 let uri_str = format!("{}/clients/{id}", configuration.base_path, id=crate::apis::urlencode(p_id));
219 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
220
221 if let Some(ref user_agent) = configuration.user_agent {
222 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
223 }
224 if let Some(ref token) = configuration.oauth_access_token {
225 req_builder = req_builder.bearer_auth(token.to_owned());
226 };
227 req_builder = req_builder.json(&p_client_update);
228
229 let req = req_builder.build()?;
230 let resp = configuration.client.execute(req).await?;
231
232 let status = resp.status();
233 let content_type = resp
234 .headers()
235 .get("content-type")
236 .and_then(|v| v.to_str().ok())
237 .unwrap_or("application/octet-stream");
238 let content_type = super::ContentType::from(content_type);
239
240 if !status.is_client_error() && !status.is_server_error() {
241 let content = resp.text().await?;
242 match content_type {
243 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
244 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Client`"))),
245 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::Client`")))),
246 }
247 } else {
248 let content = resp.text().await?;
249 let entity: Option<PutClientsByIdSuperadminError> = serde_json::from_str(&content).ok();
250 Err(Error::ResponseError(ResponseContent { status, content, entity }))
251 }
252}
253