/*
* The Jira Cloud platform REST API
*
* Jira Cloud platform REST API documentation
*
* The version of the OpenAPI document: 1001.0.0-SNAPSHOT
* Contact: ecosystem@atlassian.com
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use serde::{Deserialize, Serialize};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};
/// struct for typed errors of method [`delete_user_property`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteUserPropertyError {
Status400(),
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_user_property`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetUserPropertyError {
Status400(),
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_user_property_keys`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetUserPropertyKeysError {
Status400(),
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`set_user_property`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SetUserPropertyError {
Status400(),
Status401(),
Status403(),
Status404(),
Status405(),
UnknownValue(serde_json::Value),
}
/// Deletes a property from a user. Note: This operation does not access the [user properties](https://confluence.atlassian.com/x/8YxjL) created and maintained in Jira. **[Permissions](#permissions) required:** * *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg), to delete a property from any user. * Access to Jira, to delete a property from the calling user's record.
pub async fn delete_user_property(configuration: &configuration::Configuration, property_key: &str, account_id: Option<&str>, user_key: Option<&str>, username: Option<&str>) -> Result<(), Error<DeleteUserPropertyError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_property_key = property_key;
let p_account_id = account_id;
let p_user_key = user_key;
let p_username = username;
let uri_str = format!("{}/rest/api/2/user/properties/{propertyKey}", configuration.base_path, propertyKey=crate::apis::urlencode(p_property_key));
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref param_value) = p_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_user_key {
req_builder = req_builder.query(&[("userKey", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_username {
req_builder = req_builder.query(&[("username", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<DeleteUserPropertyError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns the value of a user's property. If no property key is provided [Get user property keys](#api-rest-api-2-user-properties-get) is called. Note: This operation does not access the [user properties](https://confluence.atlassian.com/x/8YxjL) created and maintained in Jira. **[Permissions](#permissions) required:** * *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg), to get a property from any user. * Access to Jira, to get a property from the calling user's record.
pub async fn get_user_property(configuration: &configuration::Configuration, property_key: &str, account_id: Option<&str>, user_key: Option<&str>, username: Option<&str>) -> Result<models::EntityProperty, Error<GetUserPropertyError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_property_key = property_key;
let p_account_id = account_id;
let p_user_key = user_key;
let p_username = username;
let uri_str = format!("{}/rest/api/2/user/properties/{propertyKey}", configuration.base_path, propertyKey=crate::apis::urlencode(p_property_key));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_user_key {
req_builder = req_builder.query(&[("userKey", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_username {
req_builder = req_builder.query(&[("username", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<GetUserPropertyError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Returns the keys of all properties for a user. Note: This operation does not access the [user properties](https://confluence.atlassian.com/x/8YxjL) created and maintained in Jira. **[Permissions](#permissions) required:** * *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg), to access the property keys on any user. * Access to Jira, to access the calling user's property keys.
pub async fn get_user_property_keys(configuration: &configuration::Configuration, account_id: Option<&str>, user_key: Option<&str>, username: Option<&str>) -> Result<models::PropertyKeys, Error<GetUserPropertyKeysError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_account_id = account_id;
let p_user_key = user_key;
let p_username = username;
let uri_str = format!("{}/rest/api/2/user/properties", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_user_key {
req_builder = req_builder.query(&[("userKey", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_username {
req_builder = req_builder.query(&[("username", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<GetUserPropertyKeysError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
/// Sets the value of a user's property. Use this resource to store custom data against a user. Note: This operation does not access the [user properties](https://confluence.atlassian.com/x/8YxjL) created and maintained in Jira. **[Permissions](#permissions) required:** * *Administer Jira* [global permission](https://confluence.atlassian.com/x/x4dKLg), to set a property on any user. * Access to Jira, to set a property on the calling user's record.
pub async fn set_user_property(configuration: &configuration::Configuration, property_key: &str, body: Option<serde_json::Value>, account_id: Option<&str>, user_key: Option<&str>, username: Option<&str>) -> Result<serde_json::Value, Error<SetUserPropertyError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_property_key = property_key;
let p_body = body;
let p_account_id = account_id;
let p_user_key = user_key;
let p_username = username;
let uri_str = format!("{}/rest/api/2/user/properties/{propertyKey}", configuration.base_path, propertyKey=crate::apis::urlencode(p_property_key));
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
if let Some(ref param_value) = p_account_id {
req_builder = req_builder.query(&[("accountId", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_user_key {
req_builder = req_builder.query(&[("userKey", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_username {
req_builder = req_builder.query(&[("username", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.oauth_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
if let Some(ref auth_conf) = configuration.basic_auth {
req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
};
req_builder = req_builder.json(&p_body);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
serde_json::from_str(&content).map_err(Error::from)
} else {
let content = resp.text().await?;
let entity: Option<SetUserPropertyError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}