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_ldap_groups`]
#[derive(Clone, Debug, Default)]
pub struct GetLdapGroupsParams {
    /// Search term
    pub q: Option<String>,
    /// The page to select.
    pub page: Option<i32>,
    /// The number of users per page. There is a maximum limit of 200 users per page.
    pub per_page: Option<i32>,
}

/// struct for passing parameters to the method [`link_ldap_group`]
#[derive(Clone, Debug, Default)]
pub struct LinkLdapGroupParams {
    /// Group GUID
    pub remote_id: String,
}

/// struct for typed errors of method [`get_ldap_groups`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetLdapGroupsError {
    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 [`link_ldap_group`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum LinkLdapGroupError {
    Status400(crate::openapi::models::AppError),
    Status401(crate::openapi::models::AppError),
    Status403(crate::openapi::models::AppError),
    UnknownValue(serde_json::Value),
}

/// ##### Permissions Must have `manage_system` permission. __Minimum server version__: 5.11
pub async fn get_ldap_groups(
    configuration: &configuration::Configuration,
    params: GetLdapGroupsParams,
) -> Result<Vec<crate::openapi::models::LdapGroupsPaged>, Error<GetLdapGroupsError>> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let q = params.q;
    let page = params.page;
    let per_page = params.per_page;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/api/v4/ldap/groups", 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) = q {
        local_var_req_builder = local_var_req_builder.query(&[("q", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = page {
        local_var_req_builder =
            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = per_page {
        local_var_req_builder =
            local_var_req_builder.query(&[("per_page", &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<GetLdapGroupsError> =
            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))
    }
}

/// ##### Permissions Must have `manage_system` permission. __Minimum server version__: 5.11
pub async fn link_ldap_group(
    configuration: &configuration::Configuration,
    params: LinkLdapGroupParams,
) -> Result<crate::openapi::models::StatusOk, Error<LinkLdapGroupError>> {
    let local_var_configuration = configuration;

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

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/api/v4/ldap/groups/{remote_id}/link",
        local_var_configuration.base_path,
        remote_id = super::urlencode(remote_id)
    );
    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());
    };

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