jira2/apis/
myself_api.rs

1/*
2 * The Jira Cloud platform REST API
3 *
4 * Jira Cloud platform REST API documentation
5 *
6 * The version of the OpenAPI document: 1001.0.0-SNAPSHOT
7 * Contact: ecosystem@atlassian.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17/// struct for passing parameters to the method [`get_current_user`]
18#[derive(Clone, Debug, Default)]
19pub struct GetCurrentUserParams {
20    /// Use [expand](#expansion) to include additional information about user in the response. This parameter accepts a comma-separated list. Expand options include:   *  `groups` Returns all groups, including nested groups, the user belongs to.  *  `applicationRoles` Returns the application roles the user is assigned to.
21    pub expand: Option<String>
22}
23
24/// struct for passing parameters to the method [`get_preference`]
25#[derive(Clone, Debug, Default)]
26pub struct GetPreferenceParams {
27    /// The key of the preference.
28    pub key: String
29}
30
31/// struct for passing parameters to the method [`remove_preference`]
32#[derive(Clone, Debug, Default)]
33pub struct RemovePreferenceParams {
34    /// The key of the preference.
35    pub key: String
36}
37
38/// struct for passing parameters to the method [`set_locale`]
39#[derive(Clone, Debug, Default)]
40pub struct SetLocaleParams {
41    /// The locale defined in a LocaleBean.
42    pub locale: crate::models::Locale
43}
44
45/// struct for passing parameters to the method [`set_preference`]
46#[derive(Clone, Debug, Default)]
47pub struct SetPreferenceParams {
48    /// The key of the preference. The maximum length is 255 characters.
49    pub key: String,
50    /// The value of the preference as a plain text string. The maximum length is 255 characters.
51    pub body: String
52}
53
54
55/// struct for typed errors of method [`delete_locale`]
56#[derive(Debug, Clone, Serialize, Deserialize)]
57#[serde(untagged)]
58pub enum DeleteLocaleError {
59    Status401(),
60    UnknownValue(serde_json::Value),
61}
62
63/// struct for typed errors of method [`get_current_user`]
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum GetCurrentUserError {
67    Status401(),
68    UnknownValue(serde_json::Value),
69}
70
71/// struct for typed errors of method [`get_locale`]
72#[derive(Debug, Clone, Serialize, Deserialize)]
73#[serde(untagged)]
74pub enum GetLocaleError {
75    Status401(),
76    UnknownValue(serde_json::Value),
77}
78
79/// struct for typed errors of method [`get_preference`]
80#[derive(Debug, Clone, Serialize, Deserialize)]
81#[serde(untagged)]
82pub enum GetPreferenceError {
83    Status401(),
84    Status404(),
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`remove_preference`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum RemovePreferenceError {
92    Status401(),
93    Status404(),
94    UnknownValue(serde_json::Value),
95}
96
97/// struct for typed errors of method [`set_locale`]
98#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(untagged)]
100pub enum SetLocaleError {
101    Status400(),
102    Status401(),
103    UnknownValue(serde_json::Value),
104}
105
106/// struct for typed errors of method [`set_preference`]
107#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum SetPreferenceError {
110    Status401(),
111    Status404(),
112    UnknownValue(serde_json::Value),
113}
114
115
116/// Deprecated, use [ Update a user profile](https://developer.atlassian.com/cloud/admin/user-management/rest/#api-users-account-id-manage-profile-patch) from the user management REST API instead.  Deletes the locale of the user, which restores the default setting.  **[Permissions](#permissions) required:** Permission to access Jira.
117pub async fn delete_locale(configuration: &configuration::Configuration) -> Result<serde_json::Value, Error<DeleteLocaleError>> {
118    let local_var_configuration = configuration;
119
120    // unbox the parameters
121
122
123    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
150/// Returns details for the current user.  **[Permissions](#permissions) required:** Permission to access Jira.
151pub async fn get_current_user(configuration: &configuration::Configuration, params: GetCurrentUserParams) -> Result<crate::models::User, Error<GetCurrentUserError>> {
152    let local_var_configuration = configuration;
153
154    // unbox the parameters
155    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
191/// Returns the locale for the user.  If the user has no language preference set (which is the default setting) or this resource is accessed anonymous, the browser locale detected by Jira is returned. Jira detects the browser locale using the *Accept-Language* header in the request. However, if this doesn't match a locale available Jira, the site default locale is returned.  This operation can be accessed anonymously.  **[Permissions](#permissions) required:** None.
192pub async fn get_locale(configuration: &configuration::Configuration) -> Result<crate::models::Locale, Error<GetLocaleError>> {
193    let local_var_configuration = configuration;
194
195    // unbox the parameters
196
197
198    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
228/// Returns the value of a preference of the current user.  Note that these keys are deprecated:   *  *jira.user.locale* The locale of the user. By default this is not set and the user takes the locale of the instance.  *  *jira.user.timezone* The time zone of the user. By default this is not set and the user takes the timezone of the instance.  Use [ Update a user profile](https://developer.atlassian.com/cloud/admin/user-management/rest/#api-users-account-id-manage-profile-patch) from the user management REST API to manage timezone and locale instead.  **[Permissions](#permissions) required:** Permission to access Jira.
229pub async fn get_preference(configuration: &configuration::Configuration, params: GetPreferenceParams) -> Result<String, Error<GetPreferenceError>> {
230    let local_var_configuration = configuration;
231
232    // unbox the parameters
233    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
267/// Deletes a preference of the user, which restores the default value of system defined settings.  Note that these keys are deprecated:   *  *jira.user.locale* The locale of the user. By default, not set. The user takes the instance locale.  *  *jira.user.timezone* The time zone of the user. By default, not set. The user takes the instance timezone.  Use [ Update a user profile](https://developer.atlassian.com/cloud/admin/user-management/rest/#api-users-account-id-manage-profile-patch) from the user management REST API to manage timezone and locale instead.  **[Permissions](#permissions) required:** Permission to access Jira.
268pub async fn remove_preference(configuration: &configuration::Configuration, params: RemovePreferenceParams) -> Result<(), Error<RemovePreferenceError>> {
269    let local_var_configuration = configuration;
270
271    // unbox the parameters
272    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
306/// Deprecated, use [ Update a user profile](https://developer.atlassian.com/cloud/admin/user-management/rest/#api-users-account-id-manage-profile-patch) from the user management REST API instead.  Sets the locale of the user. The locale must be one supported by the instance of Jira.  **[Permissions](#permissions) required:** Permission to access Jira.
307pub async fn set_locale(configuration: &configuration::Configuration, params: SetLocaleParams) -> Result<serde_json::Value, Error<SetLocaleError>> {
308    let local_var_configuration = configuration;
309
310    // unbox the parameters
311    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
342/// Creates a preference for the user or updates a preference's value by sending a plain text string. For example, `false`. An arbitrary preference can be created with the value containing up to 255 characters. In addition, the following keys define system preferences that can be set or created:   *  *user.notifications.mimetype* The mime type used in notifications sent to the user. Defaults to `html`.  *  *user.notify.own.changes* Whether the user gets notified of their own changes. Defaults to `false`.  *  *user.default.share.private* Whether new [ filters](https://confluence.atlassian.com/x/eQiiLQ) are set to private. Defaults to `true`.  *  *user.keyboard.shortcuts.disabled* Whether keyboard shortcuts are disabled. Defaults to `false`.  *  *user.autowatch.disabled* Whether the user automatically watches issues they create or add a comment to. By default, not set: the user takes the instance autowatch setting.  Note that these keys are deprecated:   *  *jira.user.locale* The locale of the user. By default, not set. The user takes the instance locale.  *  *jira.user.timezone* The time zone of the user. By default, not set. The user takes the instance timezone.  Use [ Update a user profile](https://developer.atlassian.com/cloud/admin/user-management/rest/#api-users-account-id-manage-profile-patch) from the user management REST API to manage timezone and locale instead.  **[Permissions](#permissions) required:** Permission to access Jira.
343pub async fn set_preference(configuration: &configuration::Configuration, params: SetPreferenceParams) -> Result<serde_json::Value, Error<SetPreferenceError>> {
344    let local_var_configuration = configuration;
345
346    // unbox the parameters
347    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