use super::{configuration, Error};
use crate::gen::apis::ResponseContent;
use crate::gen::models;
#[derive(Clone, Debug)]
pub struct AddUserToGroupParams {
pub groupname: String,
pub request_body: ::std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Clone, Debug)]
pub struct BulkGetGroupsParams {
pub start_at: Option<i64>,
pub max_results: Option<i32>,
pub group_id: Option<Vec<String>>,
pub group_name: Option<Vec<String>>,
}
#[derive(Clone, Debug)]
pub struct CreateGroupParams {
pub request_body: ::std::collections::HashMap<String, serde_json::Value>,
}
#[derive(Clone, Debug)]
pub struct FindGroupsParams {
pub account_id: Option<String>,
pub query: Option<String>,
pub exclude: Option<Vec<String>>,
pub max_results: Option<i32>,
pub user_name: Option<String>,
}
#[derive(Clone, Debug)]
pub struct GetGroupParams {
pub groupname: String,
pub expand: Option<String>,
}
#[derive(Clone, Debug)]
pub struct GetUsersFromGroupParams {
pub groupname: String,
pub include_inactive_users: Option<bool>,
pub start_at: Option<i64>,
pub max_results: Option<i32>,
}
#[derive(Clone, Debug)]
pub struct RemoveGroupParams {
pub groupname: String,
pub swap_group: Option<String>,
}
#[derive(Clone, Debug)]
pub struct RemoveUserFromGroupParams {
pub groupname: String,
pub account_id: String,
pub username: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AddUserToGroupError {
Status400(),
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum BulkGetGroupsError {
Status400(),
Status401(),
Status403(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateGroupError {
Status400(),
Status401(),
Status403(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum FindGroupsError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetGroupError {
Status400(),
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetUsersFromGroupError {
Status400(),
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RemoveGroupError {
Status400(),
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RemoveUserFromGroupError {
Status400(),
Status401(),
Status403(),
Status404(),
UnknownValue(serde_json::Value),
}
pub async fn add_user_to_group(
configuration: &configuration::Configuration,
params: AddUserToGroupParams,
) -> Result<models::Group, Error<AddUserToGroupError>> {
let groupname = params.groupname;
let request_body = params.request_body;
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/rest/api/3/group/user", configuration.base_path);
let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
local_var_req_builder = local_var_req_builder.query(&[("groupname", &groupname.to_string())]);
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = configuration.oauth_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
if let Some(ref local_var_auth_conf) = configuration.basic_auth {
local_var_req_builder = local_var_req_builder.basic_auth(
local_var_auth_conf.0.to_owned(),
local_var_auth_conf.1.to_owned(),
);
};
local_var_req_builder = local_var_req_builder.json(&request_body);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<AddUserToGroupError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn bulk_get_groups(
configuration: &configuration::Configuration,
params: BulkGetGroupsParams,
) -> Result<models::PageBeanGroupDetails, Error<BulkGetGroupsError>> {
let start_at = params.start_at;
let max_results = params.max_results;
let group_id = params.group_id;
let group_name = params.group_name;
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/rest/api/3/group/bulk", configuration.base_path);
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_str) = start_at {
local_var_req_builder =
local_var_req_builder.query(&[("startAt", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = max_results {
local_var_req_builder =
local_var_req_builder.query(&[("maxResults", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = group_id {
local_var_req_builder = local_var_req_builder.query(&[(
"groupId",
&local_var_str
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]);
}
if let Some(ref local_var_str) = group_name {
local_var_req_builder = local_var_req_builder.query(&[(
"groupName",
&local_var_str
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]);
}
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = configuration.oauth_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
if let Some(ref local_var_auth_conf) = configuration.basic_auth {
local_var_req_builder = local_var_req_builder.basic_auth(
local_var_auth_conf.0.to_owned(),
local_var_auth_conf.1.to_owned(),
);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<BulkGetGroupsError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn create_group(
configuration: &configuration::Configuration,
params: CreateGroupParams,
) -> Result<models::Group, Error<CreateGroupError>> {
let request_body = params.request_body;
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/rest/api/3/group", configuration.base_path);
let mut local_var_req_builder = local_var_client.post(local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = configuration.oauth_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
if let Some(ref local_var_auth_conf) = configuration.basic_auth {
local_var_req_builder = local_var_req_builder.basic_auth(
local_var_auth_conf.0.to_owned(),
local_var_auth_conf.1.to_owned(),
);
};
local_var_req_builder = local_var_req_builder.json(&request_body);
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<CreateGroupError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn find_groups(
configuration: &configuration::Configuration,
params: FindGroupsParams,
) -> Result<models::FoundGroups, Error<FindGroupsError>> {
let account_id = params.account_id;
let query = params.query;
let exclude = params.exclude;
let max_results = params.max_results;
let user_name = params.user_name;
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/rest/api/3/groups/picker", configuration.base_path);
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_str) = account_id {
local_var_req_builder =
local_var_req_builder.query(&[("accountId", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = query {
local_var_req_builder =
local_var_req_builder.query(&[("query", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = exclude {
local_var_req_builder = local_var_req_builder.query(&[(
"exclude",
&local_var_str
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]);
}
if let Some(ref local_var_str) = max_results {
local_var_req_builder =
local_var_req_builder.query(&[("maxResults", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = user_name {
local_var_req_builder =
local_var_req_builder.query(&[("userName", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = configuration.oauth_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
if let Some(ref local_var_auth_conf) = configuration.basic_auth {
local_var_req_builder = local_var_req_builder.basic_auth(
local_var_auth_conf.0.to_owned(),
local_var_auth_conf.1.to_owned(),
);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<FindGroupsError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_group(
configuration: &configuration::Configuration,
params: GetGroupParams,
) -> Result<models::Group, Error<GetGroupError>> {
let groupname = params.groupname;
let expand = params.expand;
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/rest/api/3/group", configuration.base_path);
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
local_var_req_builder = local_var_req_builder.query(&[("groupname", &groupname.to_string())]);
if let Some(ref local_var_str) = expand {
local_var_req_builder =
local_var_req_builder.query(&[("expand", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = configuration.oauth_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
if let Some(ref local_var_auth_conf) = configuration.basic_auth {
local_var_req_builder = local_var_req_builder.basic_auth(
local_var_auth_conf.0.to_owned(),
local_var_auth_conf.1.to_owned(),
);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetGroupError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn get_users_from_group(
configuration: &configuration::Configuration,
params: GetUsersFromGroupParams,
) -> Result<models::PageBeanUserDetails, Error<GetUsersFromGroupError>> {
let groupname = params.groupname;
let include_inactive_users = params.include_inactive_users;
let start_at = params.start_at;
let max_results = params.max_results;
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/rest/api/3/group/member", configuration.base_path);
let mut local_var_req_builder = local_var_client.get(local_var_uri_str.as_str());
local_var_req_builder = local_var_req_builder.query(&[("groupname", &groupname.to_string())]);
if let Some(ref local_var_str) = include_inactive_users {
local_var_req_builder =
local_var_req_builder.query(&[("includeInactiveUsers", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = start_at {
local_var_req_builder =
local_var_req_builder.query(&[("startAt", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = max_results {
local_var_req_builder =
local_var_req_builder.query(&[("maxResults", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = configuration.oauth_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
if let Some(ref local_var_auth_conf) = configuration.basic_auth {
local_var_req_builder = local_var_req_builder.basic_auth(
local_var_auth_conf.0.to_owned(),
local_var_auth_conf.1.to_owned(),
);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetUsersFromGroupError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn remove_group(
configuration: &configuration::Configuration,
params: RemoveGroupParams,
) -> Result<(), Error<RemoveGroupError>> {
let groupname = params.groupname;
let swap_group = params.swap_group;
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/rest/api/3/group", configuration.base_path);
let mut local_var_req_builder = local_var_client.delete(local_var_uri_str.as_str());
local_var_req_builder = local_var_req_builder.query(&[("groupname", &groupname.to_string())]);
if let Some(ref local_var_str) = swap_group {
local_var_req_builder =
local_var_req_builder.query(&[("swapGroup", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = configuration.oauth_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
if let Some(ref local_var_auth_conf) = configuration.basic_auth {
local_var_req_builder = local_var_req_builder.basic_auth(
local_var_auth_conf.0.to_owned(),
local_var_auth_conf.1.to_owned(),
);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
Ok(())
} else {
let local_var_entity: Option<RemoveGroupError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}
pub async fn remove_user_from_group(
configuration: &configuration::Configuration,
params: RemoveUserFromGroupParams,
) -> Result<(), Error<RemoveUserFromGroupError>> {
let groupname = params.groupname;
let account_id = params.account_id;
let username = params.username;
let local_var_client = &configuration.client;
let local_var_uri_str = format!("{}/rest/api/3/group/user", configuration.base_path);
let mut local_var_req_builder = local_var_client.delete(local_var_uri_str.as_str());
local_var_req_builder = local_var_req_builder.query(&[("groupname", &groupname.to_string())]);
if let Some(ref local_var_str) = username {
local_var_req_builder =
local_var_req_builder.query(&[("username", &local_var_str.to_string())]);
}
local_var_req_builder = local_var_req_builder.query(&[("accountId", &account_id.to_string())]);
if let Some(ref local_var_user_agent) = configuration.user_agent {
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = configuration.oauth_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
if let Some(ref local_var_auth_conf) = configuration.basic_auth {
local_var_req_builder = local_var_req_builder.basic_auth(
local_var_auth_conf.0.to_owned(),
local_var_auth_conf.1.to_owned(),
);
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
Ok(())
} else {
let local_var_entity: Option<RemoveUserFromGroupError> =
serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}