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_all_shared_channels`]
#[derive(Clone, Debug, Default)]
pub struct GetAllSharedChannelsParams {
    /// Team Id
    pub team_id: String,
    /// The page to select.
    pub page: Option<i32>,
    /// The number of sharedchannels per page.
    pub per_page: Option<i32>,
}

/// struct for passing parameters to the method [`get_remote_cluster_info`]
#[derive(Clone, Debug, Default)]
pub struct GetRemoteClusterInfoParams {
    /// Remote Cluster GUID
    pub remote_id: String,
}

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

/// Get all shared channels for a team.  __Minimum server version__: 5.50  ##### Permissions Must be authenticated.
pub async fn get_all_shared_channels(
    configuration: &configuration::Configuration,
    params: GetAllSharedChannelsParams,
) -> Result<Vec<crate::openapi::models::SharedChannel>, Error<GetAllSharedChannelsError>> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let team_id = params.team_id;
    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/sharedchannels/{team_id}",
        local_var_configuration.base_path,
        team_id = super::urlencode(team_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_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<GetAllSharedChannelsError> =
            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 remote cluster info based on remoteId.  __Minimum server version__: 5.50  ##### Permissions Must be authenticated and user must belong to at least one channel shared with the remote cluster.
pub async fn get_remote_cluster_info(
    configuration: &configuration::Configuration,
    params: GetRemoteClusterInfoParams,
) -> Result<crate::openapi::models::RemoteClusterInfo, Error<GetRemoteClusterInfoError>> {
    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/sharedchannels/remote_info/{remote_id}",
        local_var_configuration.base_path,
        remote_id = super::urlencode(remote_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<GetRemoteClusterInfoError> =
            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))
    }
}