hatchet-sdk 0.2.8

This is an unofficial Rust SDK for Hatchet, a distributed, fault-tolerant task queue.
Documentation
/*
 * Hatchet API
 *
 * The Hatchet API
 *
 * The version of the OpenAPI document: 1.0.0
 *
 * Generated by: https://openapi-generator.tech
 */

use super::{ContentType, Error, configuration};
use crate::clients::rest::{apis::ResponseContent, models};
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};

/// struct for typed errors of method [`sns_create`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SnsCreateError {
    Status400(models::V1TaskGet400Response),
    Status401(models::V1TaskGet400Response),
    Status405(models::V1TaskGet400Response),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`sns_delete`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SnsDeleteError {
    Status400(models::V1TaskGet400Response),
    Status401(models::V1TaskGet400Response),
    Status405(models::V1TaskGet400Response),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`sns_list`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SnsListError {
    Status400(models::V1TaskGet400Response),
    Status401(models::V1TaskGet400Response),
    Status405(models::V1TaskGet400Response),
    UnknownValue(serde_json::Value),
}

/// Create SNS integration
pub async fn sns_create(
    configuration: &configuration::Configuration,
    tenant: &str,
    sns_create_request: Option<models::SnsCreateRequest>,
) -> Result<models::SnsList200ResponseRowsInner, Error<SnsCreateError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_tenant = tenant;
    let p_sns_create_request = sns_create_request;

    let uri_str = format!(
        "{}/api/v1/tenants/{tenant}/sns",
        configuration.base_path,
        tenant = crate::clients::rest::apis::urlencode(p_tenant)
    );
    let mut req_builder = configuration
        .client
        .request(reqwest::Method::POST, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };
    req_builder = req_builder.json(&p_sns_create_request);

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => {
                return Err(Error::from(serde_json::Error::custom(
                    "Received `text/plain` content type response that cannot be converted to `models::SnsList200ResponseRowsInner`",
                )));
            }
            ContentType::Unsupported(unknown_type) => {
                return Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `models::SnsList200ResponseRowsInner`"
                ))));
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<SnsCreateError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// Delete SNS integration
pub async fn sns_delete(
    configuration: &configuration::Configuration,
    sns: &str,
) -> Result<(), Error<SnsDeleteError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_sns = sns;

    let uri_str = format!(
        "{}/api/v1/sns/{sns}",
        configuration.base_path,
        sns = crate::clients::rest::apis::urlencode(p_sns)
    );
    let mut req_builder = configuration
        .client
        .request(reqwest::Method::DELETE, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();

    if !status.is_client_error() && !status.is_server_error() {
        Ok(())
    } else {
        let content = resp.text().await?;
        let entity: Option<SnsDeleteError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}

/// List SNS integrations
pub async fn sns_list(
    configuration: &configuration::Configuration,
    tenant: &str,
) -> Result<models::SnsList200Response, Error<SnsListError>> {
    // add a prefix to parameters to efficiently prevent name collisions
    let p_tenant = tenant;

    let uri_str = format!(
        "{}/api/v1/tenants/{tenant}/sns",
        configuration.base_path,
        tenant = crate::clients::rest::apis::urlencode(p_tenant)
    );
    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);

    if let Some(ref user_agent) = configuration.user_agent {
        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
    }
    if let Some(ref token) = configuration.bearer_access_token {
        req_builder = req_builder.bearer_auth(token.to_owned());
    };

    let req = req_builder.build()?;
    let resp = configuration.client.execute(req).await?;

    let status = resp.status();
    let content_type = resp
        .headers()
        .get("content-type")
        .and_then(|v| v.to_str().ok())
        .unwrap_or("application/octet-stream");
    let content_type = super::ContentType::from(content_type);

    if !status.is_client_error() && !status.is_server_error() {
        let content = resp.text().await?;
        match content_type {
            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
            ContentType::Text => {
                return Err(Error::from(serde_json::Error::custom(
                    "Received `text/plain` content type response that cannot be converted to `models::SnsList200Response`",
                )));
            }
            ContentType::Unsupported(unknown_type) => {
                return Err(Error::from(serde_json::Error::custom(format!(
                    "Received `{unknown_type}` content type response that cannot be converted to `models::SnsList200Response`"
                ))));
            }
        }
    } else {
        let content = resp.text().await?;
        let entity: Option<SnsListError> = serde_json::from_str(&content).ok();
        Err(Error::ResponseError(ResponseContent {
            status,
            content,
            entity,
        }))
    }
}