fireblocks-sdk 2026.3.28

Rust implementation of the Fireblocks SDK
Documentation
// Fireblocks API
//
// Fireblocks provides a suite of applications to manage digital asset operations and a complete development platform to build your business on the blockchain.  - Visit our website for more information: [Fireblocks Website](https://fireblocks.com) - Visit our developer docs: [Fireblocks DevPortal](https://developers.fireblocks.com)
//
// The version of the OpenAPI document: 1.8.0
// Contact: developers@fireblocks.com
// Generated by: https://openapi-generator.tech

use {
    super::{Error, configuration},
    crate::{
        apis::{ContentType, ResponseContent},
        models,
    },
    async_trait::async_trait,
    reqwest,
    serde::{Deserialize, Serialize, de::Error as _},
    std::sync::Arc,
};

#[async_trait]
pub trait ApprovalRequestsApi: Send + Sync {
    /// POST /tags/approval_requests/{id}/cancel
    ///
    /// Cancel an approval request by id. - Can only cancel requests in the
    /// `PENDING` status. - Returns `202 Accepted` when the cancellation is
    /// processed.
    async fn cancel_approval_request(
        &self,
        params: CancelApprovalRequestParams,
    ) -> Result<(), Error<CancelApprovalRequestError>>;

    /// GET /tags/approval_requests/{id}
    ///
    /// Get an approval request by id
    async fn get_approval_request(
        &self,
        params: GetApprovalRequestParams,
    ) -> Result<models::ApprovalRequest, Error<GetApprovalRequestError>>;
}

pub struct ApprovalRequestsApiClient {
    configuration: Arc<configuration::Configuration>,
}

impl ApprovalRequestsApiClient {
    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
        Self { configuration }
    }
}

/// struct for passing parameters to the method
/// [`ApprovalRequestsApi::cancel_approval_request`]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct CancelApprovalRequestParams {
    pub id: String,
    /// A unique identifier for the request. If the request is sent multiple
    /// times with the same idempotency key, the server will return the same
    /// response as the first request. The idempotency key is valid for 24
    /// hours.
    pub idempotency_key: Option<String>,
}

/// struct for passing parameters to the method
/// [`ApprovalRequestsApi::get_approval_request`]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct GetApprovalRequestParams {
    pub id: String,
}

#[async_trait]
impl ApprovalRequestsApi for ApprovalRequestsApiClient {
    /// Cancel an approval request by id. - Can only cancel requests in the
    /// `PENDING` status. - Returns `202 Accepted` when the cancellation is
    /// processed.
    async fn cancel_approval_request(
        &self,
        params: CancelApprovalRequestParams,
    ) -> Result<(), Error<CancelApprovalRequestError>> {
        let CancelApprovalRequestParams {
            id,
            idempotency_key,
        } = params;

        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/tags/approval_requests/{id}/cancel",
            local_var_configuration.base_path,
            id = crate::apis::urlencode(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(local_var_param_value) = idempotency_key {
            local_var_req_builder =
                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
        }

        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<CancelApprovalRequestError> =
                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 an approval request by id
    async fn get_approval_request(
        &self,
        params: GetApprovalRequestParams,
    ) -> Result<models::ApprovalRequest, Error<GetApprovalRequestError>> {
        let GetApprovalRequestParams { id } = params;

        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/tags/approval_requests/{id}",
            local_var_configuration.base_path,
            id = crate::apis::urlencode(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());
        }

        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_type = local_var_resp
            .headers()
            .get("content-type")
            .and_then(|v| v.to_str().ok())
            .unwrap_or("application/octet-stream");
        let local_var_content_type = super::ContentType::from(local_var_content_type);
        let local_var_content = local_var_resp.text().await?;

        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
            match local_var_content_type {
                ContentType::Json => {
                    crate::deserialize_wrapper(&local_var_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::ApprovalRequest`",
                    )));
                }
                ContentType::Unsupported(local_var_unknown_type) => {
                    return Err(Error::from(serde_json::Error::custom(format!(
                        "Received `{local_var_unknown_type}` content type response that cannot be \
                         converted to `models::ApprovalRequest`"
                    ))));
                }
            }
        } else {
            let local_var_entity: Option<GetApprovalRequestError> =
                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))
        }
    }
}

/// struct for typed errors of method
/// [`ApprovalRequestsApi::cancel_approval_request`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CancelApprovalRequestError {
    Status401(models::ErrorResponse),
    Status404(),
    Status409(models::ErrorResponse),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method
/// [`ApprovalRequestsApi::get_approval_request`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetApprovalRequestError {
    Status401(models::ErrorResponse),
    Status404(models::ErrorResponse),
    UnknownValue(serde_json::Value),
}