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_ancillary_permissions`]
#[derive(Clone, Debug, Default)]
pub struct GetAncillaryPermissionsParams {
    /// The subsection permissions to return the ancillary permissions for. These values are comma seperated. Ex. subsection_permissions=sysconsole_read_reporting_site_statistics,sysconsole_write_reporting_site_statistics,sysconsole_write_user_management_channels
    pub subsection_permissions: Option<String>,
}

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

/// Returns all the ancillary permissions for the corresponding system console subsection permissions appended to the requested permission subsections.  __Minimum server version__: 5.35
pub async fn get_ancillary_permissions(
    configuration: &configuration::Configuration,
    params: GetAncillaryPermissionsParams,
) -> Result<Vec<String>, Error<GetAncillaryPermissionsError>> {
    let local_var_configuration = configuration;

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

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/api/v4/permissions/ancillary",
        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_str) = subsection_permissions {
        local_var_req_builder =
            local_var_req_builder.query(&[("subsection_permissions", &local_var_str.to_string())]);
    }
    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<GetAncillaryPermissionsError> =
            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))
    }
}