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(
32 &self,
33 params: ResendTransactionWebhooksParams,
34 ) -> Result<models::ResendWebhooksByTransactionIdResponse, Error<ResendTransactionWebhooksError>>;
35
36 async fn resend_webhooks(
44 &self,
45 params: ResendWebhooksParams,
46 ) -> Result<models::ResendWebhooksResponse, Error<ResendWebhooksError>>;
47}
48
49pub struct WebhooksApiClient {
50 configuration: Arc<configuration::Configuration>,
51}
52
53impl WebhooksApiClient {
54 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
55 Self { configuration }
56 }
57}
58
59#[derive(Clone, Debug)]
62#[cfg_attr(feature = "bon", derive(::bon::Builder))]
63pub struct ResendTransactionWebhooksParams {
64 pub tx_id: String,
66 pub resend_transaction_webhooks_request: models::ResendTransactionWebhooksRequest,
67 pub idempotency_key: Option<String>,
72}
73
74#[derive(Clone, Debug)]
76#[cfg_attr(feature = "bon", derive(::bon::Builder))]
77pub struct ResendWebhooksParams {
78 pub idempotency_key: Option<String>,
83}
84
85#[async_trait]
86impl WebhooksApi for WebhooksApiClient {
87 async fn resend_transaction_webhooks(
94 &self,
95 params: ResendTransactionWebhooksParams,
96 ) -> Result<models::ResendWebhooksByTransactionIdResponse, Error<ResendTransactionWebhooksError>>
97 {
98 let ResendTransactionWebhooksParams {
99 tx_id,
100 resend_transaction_webhooks_request,
101 idempotency_key,
102 } = params;
103
104 let local_var_configuration = &self.configuration;
105
106 let local_var_client = &local_var_configuration.client;
107
108 let local_var_uri_str = format!(
109 "{}/webhooks/resend/{txId}",
110 local_var_configuration.base_path,
111 txId = crate::apis::urlencode(tx_id)
112 );
113 let mut local_var_req_builder =
114 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
115
116 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
117 local_var_req_builder = local_var_req_builder
118 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
119 }
120 if let Some(local_var_param_value) = idempotency_key {
121 local_var_req_builder =
122 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
123 }
124 local_var_req_builder = local_var_req_builder.json(&resend_transaction_webhooks_request);
125
126 let local_var_req = local_var_req_builder.build()?;
127 let local_var_resp = local_var_client.execute(local_var_req).await?;
128
129 let local_var_status = local_var_resp.status();
130 let local_var_content_type = local_var_resp
131 .headers()
132 .get("content-type")
133 .and_then(|v| v.to_str().ok())
134 .unwrap_or("application/octet-stream");
135 let local_var_content_type = super::ContentType::from(local_var_content_type);
136 let local_var_content = local_var_resp.text().await?;
137
138 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
139 match local_var_content_type {
140 ContentType::Json => {
141 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
142 }
143 ContentType::Text => {
144 return Err(Error::from(serde_json::Error::custom(
145 "Received `text/plain` content type response that cannot be converted to \
146 `models::ResendWebhooksByTransactionIdResponse`",
147 )));
148 }
149 ContentType::Unsupported(local_var_unknown_type) => {
150 return Err(Error::from(serde_json::Error::custom(format!(
151 "Received `{local_var_unknown_type}` content type response that cannot be \
152 converted to `models::ResendWebhooksByTransactionIdResponse`"
153 ))));
154 }
155 }
156 } else {
157 let local_var_entity: Option<ResendTransactionWebhooksError> =
158 serde_json::from_str(&local_var_content).ok();
159 let local_var_error = ResponseContent {
160 status: local_var_status,
161 content: local_var_content,
162 entity: local_var_entity,
163 };
164 Err(Error::ResponseError(local_var_error))
165 }
166 }
167
168 async fn resend_webhooks(
174 &self,
175 params: ResendWebhooksParams,
176 ) -> Result<models::ResendWebhooksResponse, Error<ResendWebhooksError>> {
177 let ResendWebhooksParams { idempotency_key } = params;
178
179 let local_var_configuration = &self.configuration;
180
181 let local_var_client = &local_var_configuration.client;
182
183 let local_var_uri_str = format!("{}/webhooks/resend", local_var_configuration.base_path);
184 let mut local_var_req_builder =
185 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
186
187 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
188 local_var_req_builder = local_var_req_builder
189 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
190 }
191 if let Some(local_var_param_value) = idempotency_key {
192 local_var_req_builder =
193 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
194 }
195
196 let local_var_req = local_var_req_builder.build()?;
197 let local_var_resp = local_var_client.execute(local_var_req).await?;
198
199 let local_var_status = local_var_resp.status();
200 let local_var_content_type = local_var_resp
201 .headers()
202 .get("content-type")
203 .and_then(|v| v.to_str().ok())
204 .unwrap_or("application/octet-stream");
205 let local_var_content_type = super::ContentType::from(local_var_content_type);
206 let local_var_content = local_var_resp.text().await?;
207
208 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
209 match local_var_content_type {
210 ContentType::Json => {
211 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
212 }
213 ContentType::Text => {
214 return Err(Error::from(serde_json::Error::custom(
215 "Received `text/plain` content type response that cannot be converted to \
216 `models::ResendWebhooksResponse`",
217 )));
218 }
219 ContentType::Unsupported(local_var_unknown_type) => {
220 return Err(Error::from(serde_json::Error::custom(format!(
221 "Received `{local_var_unknown_type}` content type response that cannot be \
222 converted to `models::ResendWebhooksResponse`"
223 ))));
224 }
225 }
226 } else {
227 let local_var_entity: Option<ResendWebhooksError> =
228 serde_json::from_str(&local_var_content).ok();
229 let local_var_error = ResponseContent {
230 status: local_var_status,
231 content: local_var_content,
232 entity: local_var_entity,
233 };
234 Err(Error::ResponseError(local_var_error))
235 }
236 }
237}
238
239#[derive(Debug, Clone, Serialize, Deserialize)]
242#[serde(untagged)]
243pub enum ResendTransactionWebhooksError {
244 DefaultResponse(models::ErrorSchema),
245 UnknownValue(serde_json::Value),
246}
247
248#[derive(Debug, Clone, Serialize, Deserialize)]
250#[serde(untagged)]
251pub enum ResendWebhooksError {
252 DefaultResponse(models::ErrorSchema),
253 UnknownValue(serde_json::Value),
254}