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 WebhooksApi: Send + Sync {
    /// POST /webhooks/resend/{txId}
    ///
    /// **Deprecation notice:** Webhooks v1 will be deprecated in March 2026.
    /// Please use the Developer Center in the Fireblocks Console to upgrade to
    /// Webhooks v2, which offers improved reliability, performance, and
    /// observability.  Resends webhook notifications for a transaction by its
    /// unique identifier.  **Endpoint Permissions:** Admin, Non-Signing Admin,
    /// Signer, Approver, Editor.
    async fn resend_transaction_webhooks(
        &self,
        params: ResendTransactionWebhooksParams,
    ) -> Result<models::ResendWebhooksByTransactionIdResponse, Error<ResendTransactionWebhooksError>>;

    /// POST /webhooks/resend
    ///
    /// **Deprecation notice:** Webhooks v1 will be deprecated in March 2026.
    /// Please use the Developer Center in the Fireblocks Console to upgrade to
    /// Webhooks v2, which offers improved reliability, performance, and
    /// observability.  Resends all failed webhook notifications.  </br>Endpoint
    /// Permission: Admin, Non-Signing Admin, Signer, Approver, Editor.
    async fn resend_webhooks(
        &self,
        params: ResendWebhooksParams,
    ) -> Result<models::ResendWebhooksResponse, Error<ResendWebhooksError>>;
}

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

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

/// struct for passing parameters to the method
/// [`WebhooksApi::resend_transaction_webhooks`]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct ResendTransactionWebhooksParams {
    /// The ID of the transaction for webhooks
    pub tx_id: String,
    pub resend_transaction_webhooks_request: models::ResendTransactionWebhooksRequest,
    /// 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 [`WebhooksApi::resend_webhooks`]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct ResendWebhooksParams {
    /// 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>,
}

#[async_trait]
impl WebhooksApi for WebhooksApiClient {
    /// **Deprecation notice:** Webhooks v1 will be deprecated in March 2026.
    /// Please use the Developer Center in the Fireblocks Console to upgrade to
    /// Webhooks v2, which offers improved reliability, performance, and
    /// observability.  Resends webhook notifications for a transaction by its
    /// unique identifier.  **Endpoint Permissions:** Admin, Non-Signing Admin,
    /// Signer, Approver, Editor.
    async fn resend_transaction_webhooks(
        &self,
        params: ResendTransactionWebhooksParams,
    ) -> Result<models::ResendWebhooksByTransactionIdResponse, Error<ResendTransactionWebhooksError>>
    {
        let ResendTransactionWebhooksParams {
            tx_id,
            resend_transaction_webhooks_request,
            idempotency_key,
        } = params;

        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!(
            "{}/webhooks/resend/{txId}",
            local_var_configuration.base_path,
            txId = crate::apis::urlencode(tx_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());
        }
        local_var_req_builder = local_var_req_builder.json(&resend_transaction_webhooks_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_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::ResendWebhooksByTransactionIdResponse`",
                    )));
                }
                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::ResendWebhooksByTransactionIdResponse`"
                    ))));
                }
            }
        } else {
            let local_var_entity: Option<ResendTransactionWebhooksError> =
                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))
        }
    }

    /// **Deprecation notice:** Webhooks v1 will be deprecated in March 2026.
    /// Please use the Developer Center in the Fireblocks Console to upgrade to
    /// Webhooks v2, which offers improved reliability, performance, and
    /// observability.  Resends all failed webhook notifications.  </br>Endpoint
    /// Permission: Admin, Non-Signing Admin, Signer, Approver, Editor.
    async fn resend_webhooks(
        &self,
        params: ResendWebhooksParams,
    ) -> Result<models::ResendWebhooksResponse, Error<ResendWebhooksError>> {
        let ResendWebhooksParams { idempotency_key } = params;

        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!("{}/webhooks/resend", 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(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_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::ResendWebhooksResponse`",
                    )));
                }
                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::ResendWebhooksResponse`"
                    ))));
                }
            }
        } else {
            let local_var_entity: Option<ResendWebhooksError> =
                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
/// [`WebhooksApi::resend_transaction_webhooks`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ResendTransactionWebhooksError {
    DefaultResponse(models::ErrorSchema),
    UnknownValue(serde_json::Value),
}

/// struct for typed errors of method [`WebhooksApi::resend_webhooks`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ResendWebhooksError {
    DefaultResponse(models::ErrorSchema),
    UnknownValue(serde_json::Value),
}