1
2
3use reqwest;
4
5use crate::{apis::ResponseContent, models};
6use super::{Error, configuration};
7
8#[derive(Clone, Debug)]
10pub struct ApiControllerAddTokenParams {
11 pub body: models::Token
13}
14
15#[derive(Clone, Debug)]
17pub struct ApiControllerDeleteTokenParams {
18 pub body: models::Token
20}
21
22#[derive(Clone, Debug)]
24pub struct ApiControllerGetCaptchaStatusParams {
25 pub id: String
27}
28
29#[derive(Clone, Debug)]
31pub struct ApiControllerGetOAuthTokenParams {
32 pub grant_type: String,
34 pub client_id: String,
36 pub client_secret: String,
38 pub code: String
40}
41
42#[derive(Clone, Debug)]
44pub struct ApiControllerGetTokenParams {
45 pub id: String
47}
48
49#[derive(Clone, Debug)]
51pub struct ApiControllerGetTokensParams {
52 pub owner: String,
54 pub page_size: String,
56 pub p: String
58}
59
60#[derive(Clone, Debug)]
62pub struct ApiControllerRefreshTokenParams {
63 pub grant_type: String,
65 pub refresh_token: String,
67 pub scope: String,
69 pub client_id: String,
71 pub client_secret: Option<String>
73}
74
75#[derive(Clone, Debug)]
77pub struct ApiControllerUpdateTokenParams {
78 pub id: String,
80 pub body: models::Token
82}
83
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum ApiControllerAddTokenError {
89 UnknownValue(serde_json::Value),
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
94#[serde(untagged)]
95pub enum ApiControllerDeleteTokenError {
96 UnknownValue(serde_json::Value),
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum ApiControllerGetCaptchaStatusError {
103 UnknownValue(serde_json::Value),
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum ApiControllerGetOAuthTokenError {
110 Status400(models::TokenError),
111 Status401(models::TokenError),
112 UnknownValue(serde_json::Value),
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize)]
117#[serde(untagged)]
118pub enum ApiControllerGetTokenError {
119 UnknownValue(serde_json::Value),
120}
121
122#[derive(Debug, Clone, Serialize, Deserialize)]
124#[serde(untagged)]
125pub enum ApiControllerGetTokensError {
126 UnknownValue(serde_json::Value),
127}
128
129#[derive(Debug, Clone, Serialize, Deserialize)]
131#[serde(untagged)]
132pub enum ApiControllerRefreshTokenError {
133 Status400(models::TokenError),
134 Status401(models::TokenError),
135 UnknownValue(serde_json::Value),
136}
137
138#[derive(Debug, Clone, Serialize, Deserialize)]
140#[serde(untagged)]
141pub enum ApiControllerUpdateTokenError {
142 UnknownValue(serde_json::Value),
143}
144
145
146pub async fn add_token(configuration: &configuration::Configuration, params: ApiControllerAddTokenParams) -> Result<models::ControllersResponse, Error<ApiControllerAddTokenError>> {
148 let local_var_configuration = configuration;
149
150 let body = params.body;
152
153
154 let local_var_client = &local_var_configuration.client;
155
156 let local_var_uri_str = format!("{}/api/add-token", local_var_configuration.base_path);
157 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
158
159 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
160 local_var_req_builder = 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(&body);
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<ApiControllerAddTokenError> = serde_json::from_str(&local_var_content).ok();
174 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
175 Err(Error::ResponseError(local_var_error))
176 }
177}
178
179pub async fn delete_token(configuration: &configuration::Configuration, params: ApiControllerDeleteTokenParams) -> Result<models::ControllersResponse, Error<ApiControllerDeleteTokenError>> {
181 let local_var_configuration = configuration;
182
183 let body = params.body;
185
186
187 let local_var_client = &local_var_configuration.client;
188
189 let local_var_uri_str = format!("{}/api/delete-token", local_var_configuration.base_path);
190 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
191
192 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
193 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
194 }
195 local_var_req_builder = local_var_req_builder.json(&body);
196
197 let local_var_req = local_var_req_builder.build()?;
198 let local_var_resp = local_var_client.execute(local_var_req).await?;
199
200 let local_var_status = local_var_resp.status();
201 let local_var_content = local_var_resp.text().await?;
202
203 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
204 serde_json::from_str(&local_var_content).map_err(Error::from)
205 } else {
206 let local_var_entity: Option<ApiControllerDeleteTokenError> = serde_json::from_str(&local_var_content).ok();
207 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
208 Err(Error::ResponseError(local_var_error))
209 }
210}
211
212pub async fn get_captcha_status(configuration: &configuration::Configuration, params: ApiControllerGetCaptchaStatusParams) -> Result<models::ControllersResponse, Error<ApiControllerGetCaptchaStatusError>> {
214 let local_var_configuration = configuration;
215
216 let id = params.id;
218
219
220 let local_var_client = &local_var_configuration.client;
221
222 let local_var_uri_str = format!("{}/api/get-captcha-status", local_var_configuration.base_path);
223 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
224
225 local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]);
226 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
227 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
228 }
229
230 let local_var_req = local_var_req_builder.build()?;
231 let local_var_resp = local_var_client.execute(local_var_req).await?;
232
233 let local_var_status = local_var_resp.status();
234 let local_var_content = local_var_resp.text().await?;
235
236 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
237 serde_json::from_str(&local_var_content).map_err(Error::from)
238 } else {
239 let local_var_entity: Option<ApiControllerGetCaptchaStatusError> = serde_json::from_str(&local_var_content).ok();
240 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
241 Err(Error::ResponseError(local_var_error))
242 }
243}
244
245pub async fn get_o_auth_token(configuration: &configuration::Configuration, params: ApiControllerGetOAuthTokenParams) -> Result<models::TokenWrapper, Error<ApiControllerGetOAuthTokenError>> {
247 let local_var_configuration = configuration;
248
249 let grant_type = params.grant_type;
251 let client_id = params.client_id;
252 let client_secret = params.client_secret;
253 let code = params.code;
254
255
256 let local_var_client = &local_var_configuration.client;
257
258 let local_var_uri_str = format!("{}/api/login/oauth/access_token", local_var_configuration.base_path);
259 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
260
261 local_var_req_builder = local_var_req_builder.query(&[("grant_type", &grant_type.to_string())]);
262 local_var_req_builder = local_var_req_builder.query(&[("client_id", &client_id.to_string())]);
263 local_var_req_builder = local_var_req_builder.query(&[("client_secret", &client_secret.to_string())]);
264 local_var_req_builder = local_var_req_builder.query(&[("code", &code.to_string())]);
265 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
266 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
267 }
268
269 let local_var_req = local_var_req_builder.build()?;
270 let local_var_resp = local_var_client.execute(local_var_req).await?;
271
272 let local_var_status = local_var_resp.status();
273 let local_var_content = local_var_resp.text().await?;
274
275 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
276 serde_json::from_str(&local_var_content).map_err(Error::from)
277 } else {
278 let local_var_entity: Option<ApiControllerGetOAuthTokenError> = serde_json::from_str(&local_var_content).ok();
279 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
280 Err(Error::ResponseError(local_var_error))
281 }
282}
283
284pub async fn get_token(configuration: &configuration::Configuration, params: ApiControllerGetTokenParams) -> Result<models::Token, Error<ApiControllerGetTokenError>> {
286 let local_var_configuration = configuration;
287
288 let id = params.id;
290
291
292 let local_var_client = &local_var_configuration.client;
293
294 let local_var_uri_str = format!("{}/api/get-token", local_var_configuration.base_path);
295 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
296
297 local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]);
298 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
299 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
300 }
301
302 let local_var_req = local_var_req_builder.build()?;
303 let local_var_resp = local_var_client.execute(local_var_req).await?;
304
305 let local_var_status = local_var_resp.status();
306 let local_var_content = local_var_resp.text().await?;
307
308 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
309 serde_json::from_str(&local_var_content).map_err(Error::from)
310 } else {
311 let local_var_entity: Option<ApiControllerGetTokenError> = serde_json::from_str(&local_var_content).ok();
312 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
313 Err(Error::ResponseError(local_var_error))
314 }
315}
316
317pub async fn get_tokens(configuration: &configuration::Configuration, params: ApiControllerGetTokensParams) -> Result<Vec<models::Token>, Error<ApiControllerGetTokensError>> {
319 let local_var_configuration = configuration;
320
321 let owner = params.owner;
323 let page_size = params.page_size;
324 let p = params.p;
325
326
327 let local_var_client = &local_var_configuration.client;
328
329 let local_var_uri_str = format!("{}/api/get-tokens", local_var_configuration.base_path);
330 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
331
332 local_var_req_builder = local_var_req_builder.query(&[("owner", &owner.to_string())]);
333 local_var_req_builder = local_var_req_builder.query(&[("pageSize", &page_size.to_string())]);
334 local_var_req_builder = local_var_req_builder.query(&[("p", &p.to_string())]);
335 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
336 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
337 }
338
339 let local_var_req = local_var_req_builder.build()?;
340 let local_var_resp = local_var_client.execute(local_var_req).await?;
341
342 let local_var_status = local_var_resp.status();
343 let local_var_content = local_var_resp.text().await?;
344
345 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
346 serde_json::from_str(&local_var_content).map_err(Error::from)
347 } else {
348 let local_var_entity: Option<ApiControllerGetTokensError> = serde_json::from_str(&local_var_content).ok();
349 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
350 Err(Error::ResponseError(local_var_error))
351 }
352}
353
354pub async fn refresh_token(configuration: &configuration::Configuration, params: ApiControllerRefreshTokenParams) -> Result<models::TokenWrapper, Error<ApiControllerRefreshTokenError>> {
356 let local_var_configuration = configuration;
357
358 let grant_type = params.grant_type;
360 let refresh_token = params.refresh_token;
361 let scope = params.scope;
362 let client_id = params.client_id;
363 let client_secret = params.client_secret;
364
365
366 let local_var_client = &local_var_configuration.client;
367
368 let local_var_uri_str = format!("{}/api/login/oauth/refresh_token", local_var_configuration.base_path);
369 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
370
371 local_var_req_builder = local_var_req_builder.query(&[("grant_type", &grant_type.to_string())]);
372 local_var_req_builder = local_var_req_builder.query(&[("refresh_token", &refresh_token.to_string())]);
373 local_var_req_builder = local_var_req_builder.query(&[("scope", &scope.to_string())]);
374 local_var_req_builder = local_var_req_builder.query(&[("client_id", &client_id.to_string())]);
375 if let Some(ref local_var_str) = client_secret {
376 local_var_req_builder = local_var_req_builder.query(&[("client_secret", &local_var_str.to_string())]);
377 }
378 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
379 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
380 }
381
382 let local_var_req = local_var_req_builder.build()?;
383 let local_var_resp = local_var_client.execute(local_var_req).await?;
384
385 let local_var_status = local_var_resp.status();
386 let local_var_content = local_var_resp.text().await?;
387
388 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
389 serde_json::from_str(&local_var_content).map_err(Error::from)
390 } else {
391 let local_var_entity: Option<ApiControllerRefreshTokenError> = serde_json::from_str(&local_var_content).ok();
392 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
393 Err(Error::ResponseError(local_var_error))
394 }
395}
396
397pub async fn update_token(configuration: &configuration::Configuration, params: ApiControllerUpdateTokenParams) -> Result<models::ControllersResponse, Error<ApiControllerUpdateTokenError>> {
399 let local_var_configuration = configuration;
400
401 let id = params.id;
403 let body = params.body;
404
405
406 let local_var_client = &local_var_configuration.client;
407
408 let local_var_uri_str = format!("{}/api/update-token", local_var_configuration.base_path);
409 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
410
411 local_var_req_builder = local_var_req_builder.query(&[("id", &id.to_string())]);
412 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
413 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
414 }
415 local_var_req_builder = local_var_req_builder.json(&body);
416
417 let local_var_req = local_var_req_builder.build()?;
418 let local_var_resp = local_var_client.execute(local_var_req).await?;
419
420 let local_var_status = local_var_resp.status();
421 let local_var_content = local_var_resp.text().await?;
422
423 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
424 serde_json::from_str(&local_var_content).map_err(Error::from)
425 } else {
426 let local_var_entity: Option<ApiControllerUpdateTokenError> = serde_json::from_str(&local_var_content).ok();
427 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
428 Err(Error::ResponseError(local_var_error))
429 }
430}
431