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 [`open_interactive_dialog`]
#[derive(Clone, Debug, Default)]
pub struct OpenInteractiveDialogParams {
    /// Metadata for the dialog to be opened
    pub open_interactive_dialog_request: crate::openapi::models::OpenInteractiveDialogRequest,
}

/// struct for passing parameters to the method [`submit_interactive_dialog`]
#[derive(Clone, Debug, Default)]
pub struct SubmitInteractiveDialogParams {
    /// Dialog submission data
    pub submit_interactive_dialog_request: crate::openapi::models::SubmitInteractiveDialogRequest,
}

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

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

/// Open an interactive dialog using a trigger ID provided by a slash command, or some other action payload.
/// See <https://docs.mattermost.com/developer/interactive-dialogs.html> for more information on interactive dialogs.
/// __Minimum server version: 5.6__
pub async fn open_interactive_dialog(
    configuration: &configuration::Configuration,
    params: OpenInteractiveDialogParams,
) -> Result<crate::openapi::models::StatusOk, Error<OpenInteractiveDialogError>> {
    let local_var_configuration = configuration;

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

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/api/v4/actions/dialogs/open",
        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(&open_interactive_dialog_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<OpenInteractiveDialogError> =
            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))
    }
}

/// Endpoint used by the Mattermost clients to submit a dialog.
/// See <https://docs.mattermost.com/developer/interactive-dialogs.html> for more information on interactive dialogs.
/// __Minimum server version: 5.6__
pub async fn submit_interactive_dialog(
    configuration: &configuration::Configuration,
    params: SubmitInteractiveDialogParams,
) -> Result<crate::openapi::models::StatusOk, Error<SubmitInteractiveDialogError>> {
    let local_var_configuration = configuration;

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

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/api/v4/actions/dialogs/submit",
        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(&submit_interactive_dialog_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<SubmitInteractiveDialogError> =
            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))
    }
}