mattermost-client 0.2.0

A sane Rust interface to the Mattermost API
Documentation
/*
 * Mattermost API Reference
 *
 * There is also a work-in-progress [Postman API reference](https://documenter.getpostman.com/view/4508214/RW8FERUn).
 *
 * The version of the OpenAPI document: 4.0.0
 * Contact: feedback@mattermost.com
 * Generated by: https://openapi-generator.tech
 */

use reqwest;

use super::ResponseContent;
use super::{Error, configuration};

/// struct for passing parameters to the method [`get_role`]
#[derive(Clone, Debug, Default)]
pub struct GetRoleParams {
    /// Role GUID
    pub role_id: String,
}

/// struct for passing parameters to the method [`get_role_by_name`]
#[derive(Clone, Debug, Default)]
pub struct GetRoleByNameParams {
    /// Role Name
    pub role_name: String,
}

/// struct for passing parameters to the method [`get_roles_by_names`]
#[derive(Clone, Debug, Default)]
pub struct GetRolesByNamesParams {
    /// List of role names
    pub request_body: Vec<String>,
}

/// struct for passing parameters to the method [`patch_role`]
#[derive(Clone, Debug, Default)]
pub struct PatchRoleParams {
    /// Role GUID
    pub role_id: String,
    /// Role object to be updated
    pub patch_role_request: crate::openapi::models::PatchRoleRequest,
}

/// struct for typed errors of method [`get_all_roles`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetAllRolesError {
    Status400(crate::openapi::models::AppError),
    Status401(crate::openapi::models::AppError),
    Status403(crate::openapi::models::AppError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_role`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetRoleError {
    Status401(crate::openapi::models::AppError),
    Status404(crate::openapi::models::AppError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_role_by_name`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetRoleByNameError {
    Status401(crate::openapi::models::AppError),
    Status404(crate::openapi::models::AppError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`get_roles_by_names`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetRolesByNamesError {
    Status400(crate::openapi::models::AppError),
    Status401(crate::openapi::models::AppError),
    Status404(crate::openapi::models::AppError),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`patch_role`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum PatchRoleError {
    Status400(crate::openapi::models::AppError),
    Status401(crate::openapi::models::AppError),
    Status403(crate::openapi::models::AppError),
    Status404(crate::openapi::models::AppError),
    UnknownValue(serde_json::Value),
}

/// ##### Permissions  `manage_system` permission is required.  __Minimum server version__: 5.33
pub async fn get_all_roles(
    configuration: &configuration::Configuration,
) -> Result<Vec<crate::openapi::models::Role>, Error<GetAllRolesError>> {
    let local_var_configuration = configuration;

    // unbox the parameters

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/api/v4/roles", local_var_configuration.base_path);
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = local_var_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) = local_var_configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.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<GetAllRolesError> =
            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))
    }
}

/// Get a role from the provided role id.  ##### Permissions Requires an active session but no other permissions.  __Minimum server version__: 4.9
pub async fn get_role(
    configuration: &configuration::Configuration,
    params: GetRoleParams,
) -> Result<crate::openapi::models::Role, Error<GetRoleError>> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let role_id = params.role_id;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/api/v4/roles/{role_id}",
        local_var_configuration.base_path,
        role_id = super::urlencode(role_id)
    );
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = local_var_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) = local_var_configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.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<GetRoleError> = 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))
    }
}

/// Get a role from the provided role name.  ##### Permissions Requires an active session but no other permissions.  __Minimum server version__: 4.9
pub async fn get_role_by_name(
    configuration: &configuration::Configuration,
    params: GetRoleByNameParams,
) -> Result<crate::openapi::models::Role, Error<GetRoleByNameError>> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let role_name = params.role_name;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/api/v4/roles/name/{role_name}",
        local_var_configuration.base_path,
        role_name = super::urlencode(role_name)
    );
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = local_var_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) = local_var_configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.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<GetRoleByNameError> =
            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))
    }
}

/// Get a list of roles from their names.  ##### Permissions Requires an active session but no other permissions.  __Minimum server version__: 4.9
pub async fn get_roles_by_names(
    configuration: &configuration::Configuration,
    params: GetRolesByNamesParams,
) -> Result<Vec<crate::openapi::models::Role>, Error<GetRolesByNamesError>> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let request_body = params.request_body;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/api/v4/roles/names", local_var_configuration.base_path);
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = local_var_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) = local_var_configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.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<GetRolesByNamesError> =
            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))
    }
}

/// Partially update a role by providing only the fields you want to update. Omitted fields will not be updated. The fields that can be updated are defined in the request body, all other provided fields will be ignored.  ##### Permissions `manage_system` permission is required.  __Minimum server version__: 4.9
pub async fn patch_role(
    configuration: &configuration::Configuration,
    params: PatchRoleParams,
) -> Result<crate::openapi::models::Role, Error<PatchRoleError>> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let role_id = params.role_id;
    let patch_role_request = params.patch_role_request;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/api/v4/roles/{role_id}/patch",
        local_var_configuration.base_path,
        role_id = super::urlencode(role_id)
    );
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = local_var_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) = local_var_configuration.bearer_access_token {
        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
    };
    local_var_req_builder = local_var_req_builder.json(&patch_role_request);

    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<PatchRoleError> =
            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))
    }
}