fireblocks_sdk/apis/
webhooks_api.rs1use {
10 super::{Error, configuration},
11 crate::{
12 apis::{ContentType, ResponseContent},
13 models,
14 },
15 async_trait::async_trait,
16 reqwest,
17 serde::{Deserialize, Serialize, de::Error as _},
18 std::sync::Arc,
19};
20
21#[async_trait]
22pub trait WebhooksApi: Send + Sync {
23 async fn resend_transaction_webhooks(
27 &self,
28 params: ResendTransactionWebhooksParams,
29 ) -> Result<models::ResendWebhooksByTransactionIdResponse, Error<ResendTransactionWebhooksError>>;
30
31 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#[derive(Clone, Debug)]
53#[cfg_attr(feature = "bon", derive(::bon::Builder))]
54pub struct ResendTransactionWebhooksParams {
55 pub tx_id: String,
57 pub resend_transaction_webhooks_request: models::ResendTransactionWebhooksRequest,
58 pub idempotency_key: Option<String>,
63}
64
65#[derive(Clone, Debug)]
67#[cfg_attr(feature = "bon", derive(::bon::Builder))]
68pub struct ResendWebhooksParams {
69 pub idempotency_key: Option<String>,
74}
75
76#[async_trait]
77impl WebhooksApi for WebhooksApiClient {
78 async fn resend_transaction_webhooks(
80 &self,
81 params: ResendTransactionWebhooksParams,
82 ) -> Result<models::ResendWebhooksByTransactionIdResponse, Error<ResendTransactionWebhooksError>>
83 {
84 let ResendTransactionWebhooksParams {
85 tx_id,
86 resend_transaction_webhooks_request,
87 idempotency_key,
88 } = params;
89
90 let local_var_configuration = &self.configuration;
91
92 let local_var_client = &local_var_configuration.client;
93
94 let local_var_uri_str = format!(
95 "{}/webhooks/resend/{txId}",
96 local_var_configuration.base_path,
97 txId = crate::apis::urlencode(tx_id)
98 );
99 let mut local_var_req_builder =
100 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
101
102 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
103 local_var_req_builder = local_var_req_builder
104 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
105 }
106 if let Some(local_var_param_value) = idempotency_key {
107 local_var_req_builder =
108 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
109 }
110 local_var_req_builder = local_var_req_builder.json(&resend_transaction_webhooks_request);
111
112 let local_var_req = local_var_req_builder.build()?;
113 let local_var_resp = local_var_client.execute(local_var_req).await?;
114
115 let local_var_status = local_var_resp.status();
116 let local_var_content_type = local_var_resp
117 .headers()
118 .get("content-type")
119 .and_then(|v| v.to_str().ok())
120 .unwrap_or("application/octet-stream");
121 let local_var_content_type = super::ContentType::from(local_var_content_type);
122 let local_var_content = local_var_resp.text().await?;
123
124 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
125 match local_var_content_type {
126 ContentType::Json => {
127 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
128 }
129 ContentType::Text => {
130 return Err(Error::from(serde_json::Error::custom(
131 "Received `text/plain` content type response that cannot be converted to \
132 `models::ResendWebhooksByTransactionIdResponse`",
133 )));
134 }
135 ContentType::Unsupported(local_var_unknown_type) => {
136 return Err(Error::from(serde_json::Error::custom(format!(
137 "Received `{local_var_unknown_type}` content type response that cannot be \
138 converted to `models::ResendWebhooksByTransactionIdResponse`"
139 ))));
140 }
141 }
142 } else {
143 let local_var_entity: Option<ResendTransactionWebhooksError> =
144 serde_json::from_str(&local_var_content).ok();
145 let local_var_error = ResponseContent {
146 status: local_var_status,
147 content: local_var_content,
148 entity: local_var_entity,
149 };
150 Err(Error::ResponseError(local_var_error))
151 }
152 }
153
154 async fn resend_webhooks(
156 &self,
157 params: ResendWebhooksParams,
158 ) -> Result<models::ResendWebhooksResponse, Error<ResendWebhooksError>> {
159 let ResendWebhooksParams { idempotency_key } = params;
160
161 let local_var_configuration = &self.configuration;
162
163 let local_var_client = &local_var_configuration.client;
164
165 let local_var_uri_str = format!("{}/webhooks/resend", local_var_configuration.base_path);
166 let mut local_var_req_builder =
167 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
168
169 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
170 local_var_req_builder = local_var_req_builder
171 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
172 }
173 if let Some(local_var_param_value) = idempotency_key {
174 local_var_req_builder =
175 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
176 }
177
178 let local_var_req = local_var_req_builder.build()?;
179 let local_var_resp = local_var_client.execute(local_var_req).await?;
180
181 let local_var_status = local_var_resp.status();
182 let local_var_content_type = local_var_resp
183 .headers()
184 .get("content-type")
185 .and_then(|v| v.to_str().ok())
186 .unwrap_or("application/octet-stream");
187 let local_var_content_type = super::ContentType::from(local_var_content_type);
188 let local_var_content = local_var_resp.text().await?;
189
190 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
191 match local_var_content_type {
192 ContentType::Json => {
193 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
194 }
195 ContentType::Text => {
196 return Err(Error::from(serde_json::Error::custom(
197 "Received `text/plain` content type response that cannot be converted to \
198 `models::ResendWebhooksResponse`",
199 )));
200 }
201 ContentType::Unsupported(local_var_unknown_type) => {
202 return Err(Error::from(serde_json::Error::custom(format!(
203 "Received `{local_var_unknown_type}` content type response that cannot be \
204 converted to `models::ResendWebhooksResponse`"
205 ))));
206 }
207 }
208 } else {
209 let local_var_entity: Option<ResendWebhooksError> =
210 serde_json::from_str(&local_var_content).ok();
211 let local_var_error = ResponseContent {
212 status: local_var_status,
213 content: local_var_content,
214 entity: local_var_entity,
215 };
216 Err(Error::ResponseError(local_var_error))
217 }
218 }
219}
220
221#[derive(Debug, Clone, Serialize, Deserialize)]
224#[serde(untagged)]
225pub enum ResendTransactionWebhooksError {
226 DefaultResponse(models::ErrorSchema),
227 UnknownValue(serde_json::Value),
228}
229
230#[derive(Debug, Clone, Serialize, Deserialize)]
232#[serde(untagged)]
233pub enum ResendWebhooksError {
234 DefaultResponse(models::ErrorSchema),
235 UnknownValue(serde_json::Value),
236}