jira_api_v2/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;
13use serde::{Deserialize, Serialize};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`delete_locale`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteLocaleError {
22    Status401(),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`get_current_user`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum GetCurrentUserError {
30    Status401(),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`get_locale`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetLocaleError {
38    Status401(),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`get_preference`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum GetPreferenceError {
46    Status401(),
47    Status404(),
48    UnknownValue(serde_json::Value),
49}
50
51/// struct for typed errors of method [`remove_preference`]
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum RemovePreferenceError {
55    Status401(),
56    Status404(),
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`set_locale`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum SetLocaleError {
64    Status400(),
65    Status401(),
66    UnknownValue(serde_json::Value),
67}
68
69/// struct for typed errors of method [`set_preference`]
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum SetPreferenceError {
73    Status401(),
74    Status404(),
75    UnknownValue(serde_json::Value),
76}
77
78
79/// 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.
80pub async fn delete_locale(configuration: &configuration::Configuration, ) -> Result<serde_json::Value, Error<DeleteLocaleError>> {
81
82    let uri_str = format!("{}/rest/api/2/mypreferences/locale", configuration.base_path);
83    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
84
85    if let Some(ref user_agent) = configuration.user_agent {
86        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
87    }
88    if let Some(ref auth_conf) = configuration.basic_auth {
89        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
90    };
91
92    let req = req_builder.build()?;
93    let resp = configuration.client.execute(req).await?;
94
95    let status = resp.status();
96
97    if !status.is_client_error() && !status.is_server_error() {
98        let content = resp.text().await?;
99        serde_json::from_str(&content).map_err(Error::from)
100    } else {
101        let content = resp.text().await?;
102        let entity: Option<DeleteLocaleError> = serde_json::from_str(&content).ok();
103        Err(Error::ResponseError(ResponseContent { status, content, entity }))
104    }
105}
106
107/// Returns details for the current user.  **[Permissions](#permissions) required:** Permission to access Jira.
108pub async fn get_current_user(configuration: &configuration::Configuration, expand: Option<&str>) -> Result<models::User, Error<GetCurrentUserError>> {
109    // add a prefix to parameters to efficiently prevent name collisions
110    let p_expand = expand;
111
112    let uri_str = format!("{}/rest/api/2/myself", configuration.base_path);
113    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
114
115    if let Some(ref param_value) = p_expand {
116        req_builder = req_builder.query(&[("expand", &param_value.to_string())]);
117    }
118    if let Some(ref user_agent) = configuration.user_agent {
119        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
120    }
121    if let Some(ref token) = configuration.oauth_access_token {
122        req_builder = req_builder.bearer_auth(token.to_owned());
123    };
124    if let Some(ref auth_conf) = configuration.basic_auth {
125        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
126    };
127
128    let req = req_builder.build()?;
129    let resp = configuration.client.execute(req).await?;
130
131    let status = resp.status();
132
133    if !status.is_client_error() && !status.is_server_error() {
134        let content = resp.text().await?;
135        serde_json::from_str(&content).map_err(Error::from)
136    } else {
137        let content = resp.text().await?;
138        let entity: Option<GetCurrentUserError> = serde_json::from_str(&content).ok();
139        Err(Error::ResponseError(ResponseContent { status, content, entity }))
140    }
141}
142
143/// 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.
144pub async fn get_locale(configuration: &configuration::Configuration, ) -> Result<models::Locale, Error<GetLocaleError>> {
145
146    let uri_str = format!("{}/rest/api/2/mypreferences/locale", configuration.base_path);
147    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
148
149    if let Some(ref user_agent) = configuration.user_agent {
150        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
151    }
152    if let Some(ref token) = configuration.oauth_access_token {
153        req_builder = req_builder.bearer_auth(token.to_owned());
154    };
155    if let Some(ref auth_conf) = configuration.basic_auth {
156        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.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        let content = resp.text().await?;
166        serde_json::from_str(&content).map_err(Error::from)
167    } else {
168        let content = resp.text().await?;
169        let entity: Option<GetLocaleError> = serde_json::from_str(&content).ok();
170        Err(Error::ResponseError(ResponseContent { status, content, entity }))
171    }
172}
173
174/// 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.
175pub async fn get_preference(configuration: &configuration::Configuration, key: &str) -> Result<String, Error<GetPreferenceError>> {
176    // add a prefix to parameters to efficiently prevent name collisions
177    let p_key = key;
178
179    let uri_str = format!("{}/rest/api/2/mypreferences", configuration.base_path);
180    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
181
182    req_builder = req_builder.query(&[("key", &p_key.to_string())]);
183    if let Some(ref user_agent) = configuration.user_agent {
184        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
185    }
186    if let Some(ref token) = configuration.oauth_access_token {
187        req_builder = req_builder.bearer_auth(token.to_owned());
188    };
189    if let Some(ref auth_conf) = configuration.basic_auth {
190        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
191    };
192
193    let req = req_builder.build()?;
194    let resp = configuration.client.execute(req).await?;
195
196    let status = resp.status();
197
198    if !status.is_client_error() && !status.is_server_error() {
199        let content = resp.text().await?;
200        serde_json::from_str(&content).map_err(Error::from)
201    } else {
202        let content = resp.text().await?;
203        let entity: Option<GetPreferenceError> = serde_json::from_str(&content).ok();
204        Err(Error::ResponseError(ResponseContent { status, content, entity }))
205    }
206}
207
208/// 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.
209pub async fn remove_preference(configuration: &configuration::Configuration, key: &str) -> Result<(), Error<RemovePreferenceError>> {
210    // add a prefix to parameters to efficiently prevent name collisions
211    let p_key = key;
212
213    let uri_str = format!("{}/rest/api/2/mypreferences", configuration.base_path);
214    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
215
216    req_builder = req_builder.query(&[("key", &p_key.to_string())]);
217    if let Some(ref user_agent) = configuration.user_agent {
218        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
219    }
220    if let Some(ref token) = configuration.oauth_access_token {
221        req_builder = req_builder.bearer_auth(token.to_owned());
222    };
223    if let Some(ref auth_conf) = configuration.basic_auth {
224        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
225    };
226
227    let req = req_builder.build()?;
228    let resp = configuration.client.execute(req).await?;
229
230    let status = resp.status();
231
232    if !status.is_client_error() && !status.is_server_error() {
233        Ok(())
234    } else {
235        let content = resp.text().await?;
236        let entity: Option<RemovePreferenceError> = serde_json::from_str(&content).ok();
237        Err(Error::ResponseError(ResponseContent { status, content, entity }))
238    }
239}
240
241/// 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.
242pub async fn set_locale(configuration: &configuration::Configuration, locale: models::Locale) -> Result<serde_json::Value, Error<SetLocaleError>> {
243    // add a prefix to parameters to efficiently prevent name collisions
244    let p_locale = locale;
245
246    let uri_str = format!("{}/rest/api/2/mypreferences/locale", configuration.base_path);
247    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
248
249    if let Some(ref user_agent) = configuration.user_agent {
250        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
251    }
252    if let Some(ref auth_conf) = configuration.basic_auth {
253        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
254    };
255    req_builder = req_builder.json(&p_locale);
256
257    let req = req_builder.build()?;
258    let resp = configuration.client.execute(req).await?;
259
260    let status = resp.status();
261
262    if !status.is_client_error() && !status.is_server_error() {
263        let content = resp.text().await?;
264        serde_json::from_str(&content).map_err(Error::from)
265    } else {
266        let content = resp.text().await?;
267        let entity: Option<SetLocaleError> = serde_json::from_str(&content).ok();
268        Err(Error::ResponseError(ResponseContent { status, content, entity }))
269    }
270}
271
272/// 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.
273pub async fn set_preference(configuration: &configuration::Configuration, key: &str, body: &str) -> Result<serde_json::Value, Error<SetPreferenceError>> {
274    // add a prefix to parameters to efficiently prevent name collisions
275    let p_key = key;
276    let p_body = body;
277
278    let uri_str = format!("{}/rest/api/2/mypreferences", configuration.base_path);
279    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
280
281    req_builder = req_builder.query(&[("key", &p_key.to_string())]);
282    if let Some(ref user_agent) = configuration.user_agent {
283        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
284    }
285    if let Some(ref token) = configuration.oauth_access_token {
286        req_builder = req_builder.bearer_auth(token.to_owned());
287    };
288    if let Some(ref auth_conf) = configuration.basic_auth {
289        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
290    };
291    req_builder = req_builder.json(&p_body);
292
293    let req = req_builder.build()?;
294    let resp = configuration.client.execute(req).await?;
295
296    let status = resp.status();
297
298    if !status.is_client_error() && !status.is_server_error() {
299        let content = resp.text().await?;
300        serde_json::from_str(&content).map_err(Error::from)
301    } else {
302        let content = resp.text().await?;
303        let entity: Option<SetPreferenceError> = serde_json::from_str(&content).ok();
304        Err(Error::ResponseError(ResponseContent { status, content, entity }))
305    }
306}
307