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 [`remove_timeline_event`]
#[derive(Clone, Debug, Default)]
pub struct RemoveTimelineEventParams {
    /// ID of the playbook run whose timeline event will be modified.
    pub id: String,
    /// ID of the timeline event to be deleted
    pub event_id: String,
}

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

pub async fn remove_timeline_event(
    configuration: &configuration::Configuration,
    params: RemoveTimelineEventParams,
) -> Result<(), Error<RemoveTimelineEventError>> {
    let local_var_configuration = configuration;

    // unbox the parameters
    let id = params.id;
    let event_id = params.event_id;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!(
        "{}/plugins/playbooks/api/v0/runs/{id}/timeline/{event_id}/",
        local_var_configuration.base_path,
        id = super::urlencode(id),
        event_id = super::urlencode(event_id)
    );
    let mut local_var_req_builder =
        local_var_client.request(reqwest::Method::DELETE, 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() {
        Ok(())
    } else {
        let local_var_entity: Option<RemoveTimelineEventError> =
            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))
    }
}