1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17#[derive(Clone, Debug)]
19pub struct CreateApiKeyParams {
20 pub create_api_key_request: models::CreateApiKeyRequest
21}
22
23#[derive(Clone, Debug)]
25pub struct DeleteApiKeyByIdParams {
26 pub api_key_id: String
28}
29
30#[derive(Clone, Debug)]
32pub struct GetApiKeyByIdParams {
33 pub api_key_id: String
35}
36
37#[derive(Clone, Debug)]
39pub struct ListApiKeysParams {
40 pub limit: Option<u8>,
42 pub cursor: Option<String>
44}
45
46#[derive(Clone, Debug)]
48pub struct UpdateApiKeyByIdParams {
49 pub api_key_id: String,
51 pub update_api_key_by_id_request: models::UpdateApiKeyByIdRequest
52}
53
54
55#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(untagged)]
58pub enum CreateApiKeyError {
59 Status400(),
60 Status401(),
61 Status403(),
62 UnknownValue(serde_json::Value),
63}
64
65#[derive(Debug, Clone, Serialize, Deserialize)]
67#[serde(untagged)]
68pub enum DeleteApiKeyByIdError {
69 Status401(),
70 Status403(),
71 Status404(),
72 UnknownValue(serde_json::Value),
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum GetApiKeyByIdError {
79 Status401(),
80 Status403(),
81 Status404(),
82 UnknownValue(serde_json::Value),
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum ListApiKeysError {
89 Status400(),
90 Status401(),
91 Status403(),
92 UnknownValue(serde_json::Value),
93}
94
95#[derive(Debug, Clone, Serialize, Deserialize)]
97#[serde(untagged)]
98pub enum UpdateApiKeyByIdError {
99 Status400(),
100 Status401(),
101 Status403(),
102 Status404(),
103 UnknownValue(serde_json::Value),
104}
105
106
107pub async fn create_api_key(configuration: &configuration::Configuration, params: CreateApiKeyParams) -> Result<models::CreateApiKey201Response, Error<CreateApiKeyError>> {
109
110 let uri_str = format!("{}/api-keys", configuration.base_path);
111 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
112
113 if let Some(ref user_agent) = configuration.user_agent {
114 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
115 }
116 if let Some(ref token) = configuration.bearer_access_token {
117 req_builder = req_builder.bearer_auth(token.to_owned());
118 };
119 req_builder = req_builder.json(¶ms.create_api_key_request);
120
121 let req = req_builder.build()?;
122 let resp = configuration.client.execute(req).await?;
123
124 let status = resp.status();
125 let content_type = resp
126 .headers()
127 .get("content-type")
128 .and_then(|v| v.to_str().ok())
129 .unwrap_or("application/octet-stream");
130 let content_type = super::ContentType::from(content_type);
131
132 if !status.is_client_error() && !status.is_server_error() {
133 let content = resp.text().await?;
134 match content_type {
135 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
136 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateApiKey201Response`"))),
137 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::CreateApiKey201Response`")))),
138 }
139 } else {
140 let content = resp.text().await?;
141 let entity: Option<CreateApiKeyError> = serde_json::from_str(&content).ok();
142 Err(Error::ResponseError(ResponseContent { status, content, entity }))
143 }
144}
145
146pub async fn delete_api_key_by_id(configuration: &configuration::Configuration, params: DeleteApiKeyByIdParams) -> Result<(), Error<DeleteApiKeyByIdError>> {
148
149 let uri_str = format!("{}/api-keys/{apiKeyId}", configuration.base_path, apiKeyId=crate::apis::urlencode(params.api_key_id));
150 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
151
152 if let Some(ref user_agent) = configuration.user_agent {
153 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
154 }
155 if let Some(ref token) = configuration.bearer_access_token {
156 req_builder = req_builder.bearer_auth(token.to_owned());
157 };
158
159 let req = req_builder.build()?;
160 let resp = configuration.client.execute(req).await?;
161
162 let status = resp.status();
163
164 if !status.is_client_error() && !status.is_server_error() {
165 Ok(())
166 } else {
167 let content = resp.text().await?;
168 let entity: Option<DeleteApiKeyByIdError> = serde_json::from_str(&content).ok();
169 Err(Error::ResponseError(ResponseContent { status, content, entity }))
170 }
171}
172
173pub async fn get_api_key_by_id(configuration: &configuration::Configuration, params: GetApiKeyByIdParams) -> Result<models::ApiKey, Error<GetApiKeyByIdError>> {
175
176 let uri_str = format!("{}/api-keys/{apiKeyId}", configuration.base_path, apiKeyId=crate::apis::urlencode(params.api_key_id));
177 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
178
179 if let Some(ref user_agent) = configuration.user_agent {
180 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
181 }
182 if let Some(ref token) = configuration.bearer_access_token {
183 req_builder = req_builder.bearer_auth(token.to_owned());
184 };
185
186 let req = req_builder.build()?;
187 let resp = configuration.client.execute(req).await?;
188
189 let status = resp.status();
190 let content_type = resp
191 .headers()
192 .get("content-type")
193 .and_then(|v| v.to_str().ok())
194 .unwrap_or("application/octet-stream");
195 let content_type = super::ContentType::from(content_type);
196
197 if !status.is_client_error() && !status.is_server_error() {
198 let content = resp.text().await?;
199 match content_type {
200 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
201 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ApiKey`"))),
202 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::ApiKey`")))),
203 }
204 } else {
205 let content = resp.text().await?;
206 let entity: Option<GetApiKeyByIdError> = serde_json::from_str(&content).ok();
207 Err(Error::ResponseError(ResponseContent { status, content, entity }))
208 }
209}
210
211pub async fn list_api_keys(configuration: &configuration::Configuration, params: ListApiKeysParams) -> Result<models::ListApiKeys200Response, Error<ListApiKeysError>> {
213
214 let uri_str = format!("{}/api-keys", configuration.base_path);
215 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
216
217 if let Some(ref param_value) = params.limit {
218 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
219 }
220 if let Some(ref param_value) = params.cursor {
221 req_builder = req_builder.query(&[("cursor", ¶m_value.to_string())]);
222 }
223 if let Some(ref user_agent) = configuration.user_agent {
224 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
225 }
226 if let Some(ref token) = configuration.bearer_access_token {
227 req_builder = req_builder.bearer_auth(token.to_owned());
228 };
229
230 let req = req_builder.build()?;
231 let resp = configuration.client.execute(req).await?;
232
233 let status = resp.status();
234 let content_type = resp
235 .headers()
236 .get("content-type")
237 .and_then(|v| v.to_str().ok())
238 .unwrap_or("application/octet-stream");
239 let content_type = super::ContentType::from(content_type);
240
241 if !status.is_client_error() && !status.is_server_error() {
242 let content = resp.text().await?;
243 match content_type {
244 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
245 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListApiKeys200Response`"))),
246 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::ListApiKeys200Response`")))),
247 }
248 } else {
249 let content = resp.text().await?;
250 let entity: Option<ListApiKeysError> = serde_json::from_str(&content).ok();
251 Err(Error::ResponseError(ResponseContent { status, content, entity }))
252 }
253}
254
255pub async fn update_api_key_by_id(configuration: &configuration::Configuration, params: UpdateApiKeyByIdParams) -> Result<models::ApiKey, Error<UpdateApiKeyByIdError>> {
257
258 let uri_str = format!("{}/api-keys/{apiKeyId}", configuration.base_path, apiKeyId=crate::apis::urlencode(params.api_key_id));
259 let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
260
261 if let Some(ref user_agent) = configuration.user_agent {
262 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
263 }
264 if let Some(ref token) = configuration.bearer_access_token {
265 req_builder = req_builder.bearer_auth(token.to_owned());
266 };
267 req_builder = req_builder.json(¶ms.update_api_key_by_id_request);
268
269 let req = req_builder.build()?;
270 let resp = configuration.client.execute(req).await?;
271
272 let status = resp.status();
273 let content_type = resp
274 .headers()
275 .get("content-type")
276 .and_then(|v| v.to_str().ok())
277 .unwrap_or("application/octet-stream");
278 let content_type = super::ContentType::from(content_type);
279
280 if !status.is_client_error() && !status.is_server_error() {
281 let content = resp.text().await?;
282 match content_type {
283 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
284 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ApiKey`"))),
285 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::ApiKey`")))),
286 }
287 } else {
288 let content = resp.text().await?;
289 let entity: Option<UpdateApiKeyByIdError> = serde_json::from_str(&content).ok();
290 Err(Error::ResponseError(ResponseContent { status, content, entity }))
291 }
292}
293