fireblocks_sdk/apis/
webhooks_api.rs1use {
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 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)]
52#[cfg_attr(feature = "bon", derive(::bon::Builder))]
53pub struct ResendTransactionWebhooksParams {
54 pub tx_id: String,
56 pub resend_transaction_webhooks_request: models::ResendTransactionWebhooksRequest,
57 pub idempotency_key: Option<String>,
62}
63
64#[derive(Clone, Debug)]
66#[cfg_attr(feature = "bon", derive(::bon::Builder))]
67pub struct ResendWebhooksParams {
68 pub idempotency_key: Option<String>,
73}
74
75#[async_trait]
76impl WebhooksApi for WebhooksApiClient {
77 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 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#[derive(Debug, Clone, Serialize, Deserialize)]
218#[serde(untagged)]
219pub enum ResendTransactionWebhooksError {
220 DefaultResponse(models::ErrorSchema),
221 UnknownValue(serde_json::Value),
222}
223
224#[derive(Debug, Clone, Serialize, Deserialize)]
226#[serde(untagged)]
227pub enum ResendWebhooksError {
228 DefaultResponse(models::ErrorSchema),
229 UnknownValue(serde_json::Value),
230}