fireblocks_sdk/apis/
webhooks_api.rs

1// Fireblocks API
2//
3// 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)
4//
5// The version of the OpenAPI document: 1.8.0
6// Contact: developers@fireblocks.com
7// Generated by: https://openapi-generator.tech
8
9use {
10    super::{configuration, Error},
11    crate::{
12        apis::{ContentType, ResponseContent},
13        models,
14    },
15    async_trait::async_trait,
16    reqwest,
17    serde::{de::Error as _, Deserialize, Serialize},
18    std::sync::Arc,
19};
20
21#[async_trait]
22pub trait WebhooksApi: Send + Sync {
23    /// POST /webhooks/resend/{txId}
24    ///
25    /// Resends webhook notifications for a transaction by its unique identifier. Learn more about Fireblocks Webhooks in the following [guide](https://developers.fireblocks.com/docs/configure-webhooks). </br>Endpoint Permission: Admin, Non-Signing Admin, Signer, Approver, Editor.
26    async fn resend_transaction_webhooks(
27        &self,
28        params: ResendTransactionWebhooksParams,
29    ) -> Result<models::ResendWebhooksByTransactionIdResponse, Error<ResendTransactionWebhooksError>>;
30
31    /// POST /webhooks/resend
32    ///
33    /// Resends all failed webhook notifications. Learn more about Fireblocks Webhooks in the following [guide](https://developers.fireblocks.com/docs/configure-webhooks). </br>Endpoint Permission: Admin, Non-Signing Admin, Signer, Approver, Editor.
34    async fn resend_webhooks(
35        &self,
36        params: ResendWebhooksParams,
37    ) -> Result<models::ResendWebhooksResponse, Error<ResendWebhooksError>>;
38}
39
40pub struct WebhooksApiClient {
41    configuration: Arc<configuration::Configuration>,
42}
43
44impl WebhooksApiClient {
45    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
46        Self { configuration }
47    }
48}
49
50/// struct for passing parameters to the method [`resend_transaction_webhooks`]
51#[derive(Clone, Debug)]
52#[cfg_attr(feature = "bon", derive(::bon::Builder))]
53pub struct ResendTransactionWebhooksParams {
54    /// The ID of the transaction for webhooks
55    pub tx_id: String,
56    pub resend_transaction_webhooks_request: models::ResendTransactionWebhooksRequest,
57    /// A unique identifier for the request. If the request is sent multiple
58    /// times with the same idempotency key, the server will return the same
59    /// response as the first request. The idempotency key is valid for 24
60    /// hours.
61    pub idempotency_key: Option<String>,
62}
63
64/// struct for passing parameters to the method [`resend_webhooks`]
65#[derive(Clone, Debug)]
66#[cfg_attr(feature = "bon", derive(::bon::Builder))]
67pub struct ResendWebhooksParams {
68    /// A unique identifier for the request. If the request is sent multiple
69    /// times with the same idempotency key, the server will return the same
70    /// response as the first request. The idempotency key is valid for 24
71    /// hours.
72    pub idempotency_key: Option<String>,
73}
74
75#[async_trait]
76impl WebhooksApi for WebhooksApiClient {
77    /// Resends webhook notifications for a transaction by its unique identifier. Learn more about Fireblocks Webhooks in the following [guide](https://developers.fireblocks.com/docs/configure-webhooks). </br>Endpoint Permission: Admin, Non-Signing Admin, Signer, Approver, Editor.
78    async fn resend_transaction_webhooks(
79        &self,
80        params: ResendTransactionWebhooksParams,
81    ) -> Result<models::ResendWebhooksByTransactionIdResponse, Error<ResendTransactionWebhooksError>>
82    {
83        let ResendTransactionWebhooksParams {
84            tx_id,
85            resend_transaction_webhooks_request,
86            idempotency_key,
87        } = params;
88
89        let local_var_configuration = &self.configuration;
90
91        let local_var_client = &local_var_configuration.client;
92
93        let local_var_uri_str = format!(
94            "{}/webhooks/resend/{txId}",
95            local_var_configuration.base_path,
96            txId = crate::apis::urlencode(tx_id)
97        );
98        let mut local_var_req_builder =
99            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
100
101        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
102            local_var_req_builder = local_var_req_builder
103                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
104        }
105        if let Some(local_var_param_value) = idempotency_key {
106            local_var_req_builder =
107                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
108        }
109        local_var_req_builder = local_var_req_builder.json(&resend_transaction_webhooks_request);
110
111        let local_var_req = local_var_req_builder.build()?;
112        let local_var_resp = local_var_client.execute(local_var_req).await?;
113
114        let local_var_status = local_var_resp.status();
115        let local_var_content_type = local_var_resp
116            .headers()
117            .get("content-type")
118            .and_then(|v| v.to_str().ok())
119            .unwrap_or("application/octet-stream");
120        let local_var_content_type = super::ContentType::from(local_var_content_type);
121        let local_var_content = local_var_resp.text().await?;
122
123        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
124            match local_var_content_type {
125                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
126                ContentType::Text => {
127                    return Err(Error::from(serde_json::Error::custom(
128                        "Received `text/plain` content type response that cannot be converted to \
129                         `models::ResendWebhooksByTransactionIdResponse`",
130                    )))
131                }
132                ContentType::Unsupported(local_var_unknown_type) => {
133                    return Err(Error::from(serde_json::Error::custom(format!(
134                        "Received `{local_var_unknown_type}` content type response that cannot be \
135                         converted to `models::ResendWebhooksByTransactionIdResponse`"
136                    ))))
137                }
138            }
139        } else {
140            let local_var_entity: Option<ResendTransactionWebhooksError> =
141                serde_json::from_str(&local_var_content).ok();
142            let local_var_error = ResponseContent {
143                status: local_var_status,
144                content: local_var_content,
145                entity: local_var_entity,
146            };
147            Err(Error::ResponseError(local_var_error))
148        }
149    }
150
151    /// Resends all failed webhook notifications. Learn more about Fireblocks Webhooks in the following [guide](https://developers.fireblocks.com/docs/configure-webhooks). </br>Endpoint Permission: Admin, Non-Signing Admin, Signer, Approver, Editor.
152    async fn resend_webhooks(
153        &self,
154        params: ResendWebhooksParams,
155    ) -> Result<models::ResendWebhooksResponse, Error<ResendWebhooksError>> {
156        let ResendWebhooksParams { idempotency_key } = params;
157
158        let local_var_configuration = &self.configuration;
159
160        let local_var_client = &local_var_configuration.client;
161
162        let local_var_uri_str = format!("{}/webhooks/resend", local_var_configuration.base_path);
163        let mut local_var_req_builder =
164            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
165
166        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
167            local_var_req_builder = local_var_req_builder
168                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
169        }
170        if let Some(local_var_param_value) = idempotency_key {
171            local_var_req_builder =
172                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
173        }
174
175        let local_var_req = local_var_req_builder.build()?;
176        let local_var_resp = local_var_client.execute(local_var_req).await?;
177
178        let local_var_status = local_var_resp.status();
179        let local_var_content_type = local_var_resp
180            .headers()
181            .get("content-type")
182            .and_then(|v| v.to_str().ok())
183            .unwrap_or("application/octet-stream");
184        let local_var_content_type = super::ContentType::from(local_var_content_type);
185        let local_var_content = local_var_resp.text().await?;
186
187        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
188            match local_var_content_type {
189                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
190                ContentType::Text => {
191                    return Err(Error::from(serde_json::Error::custom(
192                        "Received `text/plain` content type response that cannot be converted to \
193                         `models::ResendWebhooksResponse`",
194                    )))
195                }
196                ContentType::Unsupported(local_var_unknown_type) => {
197                    return Err(Error::from(serde_json::Error::custom(format!(
198                        "Received `{local_var_unknown_type}` content type response that cannot be \
199                         converted to `models::ResendWebhooksResponse`"
200                    ))))
201                }
202            }
203        } else {
204            let local_var_entity: Option<ResendWebhooksError> =
205                serde_json::from_str(&local_var_content).ok();
206            let local_var_error = ResponseContent {
207                status: local_var_status,
208                content: local_var_content,
209                entity: local_var_entity,
210            };
211            Err(Error::ResponseError(local_var_error))
212        }
213    }
214}
215
216/// struct for typed errors of method [`resend_transaction_webhooks`]
217#[derive(Debug, Clone, Serialize, Deserialize)]
218#[serde(untagged)]
219pub enum ResendTransactionWebhooksError {
220    DefaultResponse(models::ErrorSchema),
221    UnknownValue(serde_json::Value),
222}
223
224/// struct for typed errors of method [`resend_webhooks`]
225#[derive(Debug, Clone, Serialize, Deserialize)]
226#[serde(untagged)]
227pub enum ResendWebhooksError {
228    DefaultResponse(models::ErrorSchema),
229    UnknownValue(serde_json::Value),
230}