zsgf_client/apis/
access_token_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 AccessTokenDeleteError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum AccessTokenPostError {
29 UnknownValue(serde_json::Value),
30}
31
32#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum AccessTokenPutError {
36 UnknownValue(serde_json::Value),
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum AccessTokensError {
43 UnknownValue(serde_json::Value),
44}
45
46
47pub async fn access_token_delete(configuration: &configuration::Configuration, id: i64, app_key: &str) -> Result<models::BooleanApiResponse, Error<AccessTokenDeleteError>> {
49 let p_id = id;
51 let p_app_key = app_key;
52
53 let uri_str = format!("{}/AccessToken/{appKey}/{id}", configuration.base_path, id=p_id, appKey=crate::apis::urlencode(p_app_key));
54 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
55
56 if let Some(ref user_agent) = configuration.user_agent {
57 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
58 }
59 if let Some(ref token) = configuration.bearer_access_token {
60 req_builder = req_builder.bearer_auth(token.to_owned());
61 };
62
63 let req = req_builder.build()?;
64 let resp = configuration.client.execute(req).await?;
65
66 let status = resp.status();
67 let content_type = resp
68 .headers()
69 .get("content-type")
70 .and_then(|v| v.to_str().ok())
71 .unwrap_or("application/octet-stream");
72 let content_type = super::ContentType::from(content_type);
73
74 if !status.is_client_error() && !status.is_server_error() {
75 let content = resp.text().await?;
76 match content_type {
77 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
78 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BooleanApiResponse`"))),
79 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::BooleanApiResponse`")))),
80 }
81 } else {
82 let content = resp.text().await?;
83 let entity: Option<AccessTokenDeleteError> = serde_json::from_str(&content).ok();
84 Err(Error::ResponseError(ResponseContent { status, content, entity }))
85 }
86}
87
88pub async fn access_token_post(configuration: &configuration::Configuration, app_key: &str, access_token_post_request: Option<models::AccessTokenPostRequest>) -> Result<models::TokenModelApiResponse, Error<AccessTokenPostError>> {
90 let p_app_key = app_key;
92 let p_access_token_post_request = access_token_post_request;
93
94 let uri_str = format!("{}/AccessToken/{appKey}", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
95 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
96
97 if let Some(ref user_agent) = configuration.user_agent {
98 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
99 }
100 if let Some(ref token) = configuration.bearer_access_token {
101 req_builder = req_builder.bearer_auth(token.to_owned());
102 };
103 req_builder = req_builder.json(&p_access_token_post_request);
104
105 let req = req_builder.build()?;
106 let resp = configuration.client.execute(req).await?;
107
108 let status = resp.status();
109 let content_type = resp
110 .headers()
111 .get("content-type")
112 .and_then(|v| v.to_str().ok())
113 .unwrap_or("application/octet-stream");
114 let content_type = super::ContentType::from(content_type);
115
116 if !status.is_client_error() && !status.is_server_error() {
117 let content = resp.text().await?;
118 match content_type {
119 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
120 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::TokenModelApiResponse`"))),
121 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::TokenModelApiResponse`")))),
122 }
123 } else {
124 let content = resp.text().await?;
125 let entity: Option<AccessTokenPostError> = serde_json::from_str(&content).ok();
126 Err(Error::ResponseError(ResponseContent { status, content, entity }))
127 }
128}
129
130pub async fn access_token_put(configuration: &configuration::Configuration, id: i64, app_key: &str, access_token_put_request: Option<models::AccessTokenPutRequest>) -> Result<models::BooleanApiResponse, Error<AccessTokenPutError>> {
132 let p_id = id;
134 let p_app_key = app_key;
135 let p_access_token_put_request = access_token_put_request;
136
137 let uri_str = format!("{}/AccessToken/{appKey}/{id}", configuration.base_path, id=p_id, appKey=crate::apis::urlencode(p_app_key));
138 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &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.bearer_access_token {
144 req_builder = req_builder.bearer_auth(token.to_owned());
145 };
146 req_builder = req_builder.json(&p_access_token_put_request);
147
148 let req = req_builder.build()?;
149 let resp = configuration.client.execute(req).await?;
150
151 let status = resp.status();
152 let content_type = resp
153 .headers()
154 .get("content-type")
155 .and_then(|v| v.to_str().ok())
156 .unwrap_or("application/octet-stream");
157 let content_type = super::ContentType::from(content_type);
158
159 if !status.is_client_error() && !status.is_server_error() {
160 let content = resp.text().await?;
161 match content_type {
162 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
163 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BooleanApiResponse`"))),
164 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::BooleanApiResponse`")))),
165 }
166 } else {
167 let content = resp.text().await?;
168 let entity: Option<AccessTokenPutError> = serde_json::from_str(&content).ok();
169 Err(Error::ResponseError(ResponseContent { status, content, entity }))
170 }
171}
172
173pub async fn access_tokens(configuration: &configuration::Configuration, app_key: &str, user_id: Option<i64>, skip: Option<i32>, take: Option<i32>) -> Result<models::AccessTokenListResultApiResponse, Error<AccessTokensError>> {
175 let p_app_key = app_key;
177 let p_user_id = user_id;
178 let p_skip = skip;
179 let p_take = take;
180
181 let uri_str = format!("{}/AccessToken/{appKey}", configuration.base_path, appKey=crate::apis::urlencode(p_app_key));
182 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
183
184 if let Some(ref param_value) = p_user_id {
185 req_builder = req_builder.query(&[("userId", ¶m_value.to_string())]);
186 }
187 if let Some(ref param_value) = p_skip {
188 req_builder = req_builder.query(&[("skip", ¶m_value.to_string())]);
189 }
190 if let Some(ref param_value) = p_take {
191 req_builder = req_builder.query(&[("take", ¶m_value.to_string())]);
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 token) = configuration.bearer_access_token {
197 req_builder = req_builder.bearer_auth(token.to_owned());
198 };
199
200 let req = req_builder.build()?;
201 let resp = configuration.client.execute(req).await?;
202
203 let status = resp.status();
204 let content_type = resp
205 .headers()
206 .get("content-type")
207 .and_then(|v| v.to_str().ok())
208 .unwrap_or("application/octet-stream");
209 let content_type = super::ContentType::from(content_type);
210
211 if !status.is_client_error() && !status.is_server_error() {
212 let content = resp.text().await?;
213 match content_type {
214 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
215 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AccessTokenListResultApiResponse`"))),
216 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::AccessTokenListResultApiResponse`")))),
217 }
218 } else {
219 let content = resp.text().await?;
220 let entity: Option<AccessTokensError> = serde_json::from_str(&content).ok();
221 Err(Error::ResponseError(ResponseContent { status, content, entity }))
222 }
223}
224