1use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17#[derive(Clone, Debug, Default)]
19pub struct GetCurrentUserParams {
20 pub expand: Option<String>
22}
23
24#[derive(Clone, Debug, Default)]
26pub struct GetPreferenceParams {
27 pub key: String
29}
30
31#[derive(Clone, Debug, Default)]
33pub struct RemovePreferenceParams {
34 pub key: String
36}
37
38#[derive(Clone, Debug, Default)]
40pub struct SetLocaleParams {
41 pub locale: crate::models::Locale
43}
44
45#[derive(Clone, Debug, Default)]
47pub struct SetPreferenceParams {
48 pub key: String,
50 pub body: String
52}
53
54
55#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(untagged)]
58pub enum DeleteLocaleError {
59 Status401(),
60 UnknownValue(serde_json::Value),
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum GetCurrentUserError {
67 Status401(),
68 UnknownValue(serde_json::Value),
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(untagged)]
74pub enum GetLocaleError {
75 Status401(),
76 UnknownValue(serde_json::Value),
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize)]
81#[serde(untagged)]
82pub enum GetPreferenceError {
83 Status401(),
84 Status404(),
85 UnknownValue(serde_json::Value),
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum RemovePreferenceError {
92 Status401(),
93 Status404(),
94 UnknownValue(serde_json::Value),
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(untagged)]
100pub enum SetLocaleError {
101 Status400(),
102 Status401(),
103 UnknownValue(serde_json::Value),
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum SetPreferenceError {
110 Status401(),
111 Status404(),
112 UnknownValue(serde_json::Value),
113}
114
115
116pub async fn delete_locale(configuration: &configuration::Configuration) -> Result<serde_json::Value, Error<DeleteLocaleError>> {
118 let local_var_configuration = configuration;
119
120 let local_var_client = &local_var_configuration.client;
124
125 let local_var_uri_str = format!("{}/rest/api/2/mypreferences/locale", local_var_configuration.base_path);
126 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
127
128 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
129 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
130 }
131 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
132 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
133 };
134
135 let local_var_req = local_var_req_builder.build()?;
136 let local_var_resp = local_var_client.execute(local_var_req).await?;
137
138 let local_var_status = local_var_resp.status();
139 let local_var_content = local_var_resp.text().await?;
140
141 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
142 serde_json::from_str(&local_var_content).map_err(Error::from)
143 } else {
144 let local_var_entity: Option<DeleteLocaleError> = serde_json::from_str(&local_var_content).ok();
145 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
146 Err(Error::ResponseError(local_var_error))
147 }
148}
149
150pub async fn get_current_user(configuration: &configuration::Configuration, params: GetCurrentUserParams) -> Result<crate::models::User, Error<GetCurrentUserError>> {
152 let local_var_configuration = configuration;
153
154 let expand = params.expand;
156
157
158 let local_var_client = &local_var_configuration.client;
159
160 let local_var_uri_str = format!("{}/rest/api/2/myself", local_var_configuration.base_path);
161 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
162
163 if let Some(ref local_var_str) = expand {
164 local_var_req_builder = local_var_req_builder.query(&[("expand", &local_var_str.to_string())]);
165 }
166 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
167 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
168 }
169 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
170 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
171 };
172 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
173 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
174 };
175
176 let local_var_req = local_var_req_builder.build()?;
177 let local_var_resp = local_var_client.execute(local_var_req).await?;
178
179 let local_var_status = local_var_resp.status();
180 let local_var_content = local_var_resp.text().await?;
181
182 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
183 serde_json::from_str(&local_var_content).map_err(Error::from)
184 } else {
185 let local_var_entity: Option<GetCurrentUserError> = serde_json::from_str(&local_var_content).ok();
186 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
187 Err(Error::ResponseError(local_var_error))
188 }
189}
190
191pub async fn get_locale(configuration: &configuration::Configuration) -> Result<crate::models::Locale, Error<GetLocaleError>> {
193 let local_var_configuration = configuration;
194
195 let local_var_client = &local_var_configuration.client;
199
200 let local_var_uri_str = format!("{}/rest/api/2/mypreferences/locale", local_var_configuration.base_path);
201 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
202
203 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
204 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
205 }
206 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
207 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
208 };
209 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
210 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
211 };
212
213 let local_var_req = local_var_req_builder.build()?;
214 let local_var_resp = local_var_client.execute(local_var_req).await?;
215
216 let local_var_status = local_var_resp.status();
217 let local_var_content = local_var_resp.text().await?;
218
219 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
220 serde_json::from_str(&local_var_content).map_err(Error::from)
221 } else {
222 let local_var_entity: Option<GetLocaleError> = serde_json::from_str(&local_var_content).ok();
223 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
224 Err(Error::ResponseError(local_var_error))
225 }
226}
227
228pub async fn get_preference(configuration: &configuration::Configuration, params: GetPreferenceParams) -> Result<String, Error<GetPreferenceError>> {
230 let local_var_configuration = configuration;
231
232 let key = params.key;
234
235
236 let local_var_client = &local_var_configuration.client;
237
238 let local_var_uri_str = format!("{}/rest/api/2/mypreferences", local_var_configuration.base_path);
239 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
240
241 local_var_req_builder = local_var_req_builder.query(&[("key", &key.to_string())]);
242 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
243 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
244 }
245 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
246 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
247 };
248 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
249 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
250 };
251
252 let local_var_req = local_var_req_builder.build()?;
253 let local_var_resp = local_var_client.execute(local_var_req).await?;
254
255 let local_var_status = local_var_resp.status();
256 let local_var_content = local_var_resp.text().await?;
257
258 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
259 serde_json::from_str(&local_var_content).map_err(Error::from)
260 } else {
261 let local_var_entity: Option<GetPreferenceError> = serde_json::from_str(&local_var_content).ok();
262 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
263 Err(Error::ResponseError(local_var_error))
264 }
265}
266
267pub async fn remove_preference(configuration: &configuration::Configuration, params: RemovePreferenceParams) -> Result<(), Error<RemovePreferenceError>> {
269 let local_var_configuration = configuration;
270
271 let key = params.key;
273
274
275 let local_var_client = &local_var_configuration.client;
276
277 let local_var_uri_str = format!("{}/rest/api/2/mypreferences", local_var_configuration.base_path);
278 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
279
280 local_var_req_builder = local_var_req_builder.query(&[("key", &key.to_string())]);
281 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
282 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
283 }
284 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
285 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
286 };
287 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
288 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
289 };
290
291 let local_var_req = local_var_req_builder.build()?;
292 let local_var_resp = local_var_client.execute(local_var_req).await?;
293
294 let local_var_status = local_var_resp.status();
295 let local_var_content = local_var_resp.text().await?;
296
297 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
298 Ok(())
299 } else {
300 let local_var_entity: Option<RemovePreferenceError> = serde_json::from_str(&local_var_content).ok();
301 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
302 Err(Error::ResponseError(local_var_error))
303 }
304}
305
306pub async fn set_locale(configuration: &configuration::Configuration, params: SetLocaleParams) -> Result<serde_json::Value, Error<SetLocaleError>> {
308 let local_var_configuration = configuration;
309
310 let locale = params.locale;
312
313
314 let local_var_client = &local_var_configuration.client;
315
316 let local_var_uri_str = format!("{}/rest/api/2/mypreferences/locale", local_var_configuration.base_path);
317 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
318
319 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
320 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
321 }
322 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
323 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
324 };
325 local_var_req_builder = local_var_req_builder.json(&locale);
326
327 let local_var_req = local_var_req_builder.build()?;
328 let local_var_resp = local_var_client.execute(local_var_req).await?;
329
330 let local_var_status = local_var_resp.status();
331 let local_var_content = local_var_resp.text().await?;
332
333 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
334 serde_json::from_str(&local_var_content).map_err(Error::from)
335 } else {
336 let local_var_entity: Option<SetLocaleError> = serde_json::from_str(&local_var_content).ok();
337 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
338 Err(Error::ResponseError(local_var_error))
339 }
340}
341
342pub async fn set_preference(configuration: &configuration::Configuration, params: SetPreferenceParams) -> Result<serde_json::Value, Error<SetPreferenceError>> {
344 let local_var_configuration = configuration;
345
346 let key = params.key;
348 let body = params.body;
349
350
351 let local_var_client = &local_var_configuration.client;
352
353 let local_var_uri_str = format!("{}/rest/api/2/mypreferences", local_var_configuration.base_path);
354 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
355
356 local_var_req_builder = local_var_req_builder.query(&[("key", &key.to_string())]);
357 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
358 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
359 }
360 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
361 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
362 };
363 if let Some(ref local_var_auth_conf) = local_var_configuration.basic_auth {
364 local_var_req_builder = local_var_req_builder.basic_auth(local_var_auth_conf.0.to_owned(), local_var_auth_conf.1.to_owned());
365 };
366 local_var_req_builder = local_var_req_builder.json(&body);
367
368 let local_var_req = local_var_req_builder.build()?;
369 let local_var_resp = local_var_client.execute(local_var_req).await?;
370
371 let local_var_status = local_var_resp.status();
372 let local_var_content = local_var_resp.text().await?;
373
374 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
375 serde_json::from_str(&local_var_content).map_err(Error::from)
376 } else {
377 let local_var_entity: Option<SetPreferenceError> = serde_json::from_str(&local_var_content).ok();
378 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
379 Err(Error::ResponseError(local_var_error))
380 }
381}
382