fireblocks_sdk/apis/
d_app_connections_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::{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 DAppConnectionsApi: Send + Sync {
23    /// POST /connections/wc
24    ///
25    /// Initiate a new Web3 connection.  * Note: After this succeeds, make a request to `PUT /v1/connections/wc/{id}` (below) to approve or reject the new Web3 connection. Learn more about Fireblocks Wallet Link in the following [guide](https://developers.fireblocks.com/docs/web3-wallet-link). </br>Endpoint Permission: Admin, Non-Signing Admin.
26    async fn create(
27        &self,
28        params: CreateParams,
29    ) -> Result<models::CreateConnectionResponse, Error<CreateError>>;
30
31    /// GET /connections
32    ///
33    /// List all open Web3 connections. </br>Endpoint Permission: Admin,
34    /// Non-Signing Admin.
35    async fn get(
36        &self,
37        params: GetParams,
38    ) -> Result<models::GetConnectionsResponse, Error<GetError>>;
39
40    /// DELETE /connections/wc/{id}
41    ///
42    /// Remove an existing Web3 connection.  </br>Endpoint Permission: Admin,
43    /// Non-Signing Admin.
44    async fn remove(&self, params: RemoveParams) -> Result<(), Error<RemoveError>>;
45
46    /// PUT /connections/wc/{id}
47    ///
48    /// Submit a response to *approve* or *reject* an initiated Web3 connection.
49    /// * Note: This call is used to complete your `POST /v1/connections/wc/`
50    /// request. After this succeeds, your new Web3 connection is created and
51    /// functioning.  </br>Endpoint Permission: Admin, Non-Signing Admin.
52    async fn submit(&self, params: SubmitParams) -> Result<(), Error<SubmitError>>;
53}
54
55pub struct DAppConnectionsApiClient {
56    configuration: Arc<configuration::Configuration>,
57}
58
59impl DAppConnectionsApiClient {
60    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
61        Self { configuration }
62    }
63}
64
65/// struct for passing parameters to the method [`DAppConnectionsApi::create`]
66#[derive(Clone, Debug)]
67#[cfg_attr(feature = "bon", derive(::bon::Builder))]
68pub struct CreateParams {
69    pub create_connection_request: models::CreateConnectionRequest,
70    /// A unique identifier for the request. If the request is sent multiple
71    /// times with the same idempotency key, the server will return the same
72    /// response as the first request. The idempotency key is valid for 24
73    /// hours.
74    pub idempotency_key: Option<String>,
75}
76
77/// struct for passing parameters to the method [`DAppConnectionsApi::get`]
78#[derive(Clone, Debug)]
79#[cfg_attr(feature = "bon", derive(::bon::Builder))]
80pub struct GetParams {
81    /// List order (ascending or descending)
82    pub order: Option<String>,
83    /// Parsed filter object
84    pub filter: Option<models::GetFilterParameter>,
85    /// Property to sort Web3 connections by.
86    pub sort: Option<String>,
87    /// Amount of results to return in the next page.
88    pub page_size: Option<f64>,
89    /// Cursor to the next page
90    pub next: Option<String>,
91}
92
93/// struct for passing parameters to the method [`DAppConnectionsApi::remove`]
94#[derive(Clone, Debug)]
95#[cfg_attr(feature = "bon", derive(::bon::Builder))]
96pub struct RemoveParams {
97    /// The ID of the existing Web3 connection to remove.
98    pub id: String,
99}
100
101/// struct for passing parameters to the method [`DAppConnectionsApi::submit`]
102#[derive(Clone, Debug)]
103#[cfg_attr(feature = "bon", derive(::bon::Builder))]
104pub struct SubmitParams {
105    /// The ID of the initiated Web3 connection to approve.
106    pub id: String,
107    pub respond_to_connection_request: models::RespondToConnectionRequest,
108    /// A unique identifier for the request. If the request is sent multiple
109    /// times with the same idempotency key, the server will return the same
110    /// response as the first request. The idempotency key is valid for 24
111    /// hours.
112    pub idempotency_key: Option<String>,
113}
114
115#[async_trait]
116impl DAppConnectionsApi for DAppConnectionsApiClient {
117    /// Initiate a new Web3 connection.  * Note: After this succeeds, make a request to `PUT /v1/connections/wc/{id}` (below) to approve or reject the new Web3 connection. Learn more about Fireblocks Wallet Link in the following [guide](https://developers.fireblocks.com/docs/web3-wallet-link). </br>Endpoint Permission: Admin, Non-Signing Admin.
118    async fn create(
119        &self,
120        params: CreateParams,
121    ) -> Result<models::CreateConnectionResponse, Error<CreateError>> {
122        let CreateParams {
123            create_connection_request,
124            idempotency_key,
125        } = params;
126
127        let local_var_configuration = &self.configuration;
128
129        let local_var_client = &local_var_configuration.client;
130
131        let local_var_uri_str = format!("{}/connections/wc", local_var_configuration.base_path);
132        let mut local_var_req_builder =
133            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
134
135        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
136            local_var_req_builder = local_var_req_builder
137                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
138        }
139        if let Some(local_var_param_value) = idempotency_key {
140            local_var_req_builder =
141                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
142        }
143        local_var_req_builder = local_var_req_builder.json(&create_connection_request);
144
145        let local_var_req = local_var_req_builder.build()?;
146        let local_var_resp = local_var_client.execute(local_var_req).await?;
147
148        let local_var_status = local_var_resp.status();
149        let local_var_content_type = local_var_resp
150            .headers()
151            .get("content-type")
152            .and_then(|v| v.to_str().ok())
153            .unwrap_or("application/octet-stream");
154        let local_var_content_type = super::ContentType::from(local_var_content_type);
155        let local_var_content = local_var_resp.text().await?;
156
157        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
158            match local_var_content_type {
159                ContentType::Json => {
160                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
161                }
162                ContentType::Text => {
163                    return Err(Error::from(serde_json::Error::custom(
164                        "Received `text/plain` content type response that cannot be converted to \
165                         `models::CreateConnectionResponse`",
166                    )));
167                }
168                ContentType::Unsupported(local_var_unknown_type) => {
169                    return Err(Error::from(serde_json::Error::custom(format!(
170                        "Received `{local_var_unknown_type}` content type response that cannot be \
171                         converted to `models::CreateConnectionResponse`"
172                    ))));
173                }
174            }
175        } else {
176            let local_var_entity: Option<CreateError> =
177                serde_json::from_str(&local_var_content).ok();
178            let local_var_error = ResponseContent {
179                status: local_var_status,
180                content: local_var_content,
181                entity: local_var_entity,
182            };
183            Err(Error::ResponseError(local_var_error))
184        }
185    }
186
187    /// List all open Web3 connections. </br>Endpoint Permission: Admin,
188    /// Non-Signing Admin.
189    async fn get(
190        &self,
191        params: GetParams,
192    ) -> Result<models::GetConnectionsResponse, Error<GetError>> {
193        let GetParams {
194            order,
195            filter,
196            sort,
197            page_size,
198            next,
199        } = params;
200
201        let local_var_configuration = &self.configuration;
202
203        let local_var_client = &local_var_configuration.client;
204
205        let local_var_uri_str = format!("{}/connections", local_var_configuration.base_path);
206        let mut local_var_req_builder =
207            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
208
209        if let Some(ref param_value) = order {
210            local_var_req_builder =
211                local_var_req_builder.query(&[("order", &param_value.to_string())]);
212        }
213        if let Some(ref param_value) = filter {
214            local_var_req_builder =
215                local_var_req_builder.query(&[("filter", &serde_json::to_value(param_value)?)]);
216        }
217        if let Some(ref param_value) = sort {
218            local_var_req_builder =
219                local_var_req_builder.query(&[("sort", &param_value.to_string())]);
220        }
221        if let Some(ref param_value) = page_size {
222            local_var_req_builder =
223                local_var_req_builder.query(&[("pageSize", &param_value.to_string())]);
224        }
225        if let Some(ref param_value) = next {
226            local_var_req_builder =
227                local_var_req_builder.query(&[("next", &param_value.to_string())]);
228        }
229        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
230            local_var_req_builder = local_var_req_builder
231                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
232        }
233
234        let local_var_req = local_var_req_builder.build()?;
235        let local_var_resp = local_var_client.execute(local_var_req).await?;
236
237        let local_var_status = local_var_resp.status();
238        let local_var_content_type = local_var_resp
239            .headers()
240            .get("content-type")
241            .and_then(|v| v.to_str().ok())
242            .unwrap_or("application/octet-stream");
243        let local_var_content_type = super::ContentType::from(local_var_content_type);
244        let local_var_content = local_var_resp.text().await?;
245
246        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
247            match local_var_content_type {
248                ContentType::Json => {
249                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
250                }
251                ContentType::Text => {
252                    return Err(Error::from(serde_json::Error::custom(
253                        "Received `text/plain` content type response that cannot be converted to \
254                         `models::GetConnectionsResponse`",
255                    )));
256                }
257                ContentType::Unsupported(local_var_unknown_type) => {
258                    return Err(Error::from(serde_json::Error::custom(format!(
259                        "Received `{local_var_unknown_type}` content type response that cannot be \
260                         converted to `models::GetConnectionsResponse`"
261                    ))));
262                }
263            }
264        } else {
265            let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
266            let local_var_error = ResponseContent {
267                status: local_var_status,
268                content: local_var_content,
269                entity: local_var_entity,
270            };
271            Err(Error::ResponseError(local_var_error))
272        }
273    }
274
275    /// Remove an existing Web3 connection.  </br>Endpoint Permission: Admin,
276    /// Non-Signing Admin.
277    async fn remove(&self, params: RemoveParams) -> Result<(), Error<RemoveError>> {
278        let RemoveParams { id } = params;
279
280        let local_var_configuration = &self.configuration;
281
282        let local_var_client = &local_var_configuration.client;
283
284        let local_var_uri_str = format!(
285            "{}/connections/wc/{id}",
286            local_var_configuration.base_path,
287            id = crate::apis::urlencode(id)
288        );
289        let mut local_var_req_builder =
290            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
291
292        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
293            local_var_req_builder = local_var_req_builder
294                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
295        }
296
297        let local_var_req = local_var_req_builder.build()?;
298        let local_var_resp = local_var_client.execute(local_var_req).await?;
299
300        let local_var_status = local_var_resp.status();
301        let local_var_content = local_var_resp.text().await?;
302
303        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
304            Ok(())
305        } else {
306            let local_var_entity: Option<RemoveError> =
307                serde_json::from_str(&local_var_content).ok();
308            let local_var_error = ResponseContent {
309                status: local_var_status,
310                content: local_var_content,
311                entity: local_var_entity,
312            };
313            Err(Error::ResponseError(local_var_error))
314        }
315    }
316
317    /// Submit a response to *approve* or *reject* an initiated Web3 connection.
318    /// * Note: This call is used to complete your `POST /v1/connections/wc/`
319    /// request. After this succeeds, your new Web3 connection is created and
320    /// functioning.  </br>Endpoint Permission: Admin, Non-Signing Admin.
321    async fn submit(&self, params: SubmitParams) -> Result<(), Error<SubmitError>> {
322        let SubmitParams {
323            id,
324            respond_to_connection_request,
325            idempotency_key,
326        } = params;
327
328        let local_var_configuration = &self.configuration;
329
330        let local_var_client = &local_var_configuration.client;
331
332        let local_var_uri_str = format!(
333            "{}/connections/wc/{id}",
334            local_var_configuration.base_path,
335            id = crate::apis::urlencode(id)
336        );
337        let mut local_var_req_builder =
338            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
339
340        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
341            local_var_req_builder = local_var_req_builder
342                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
343        }
344        if let Some(local_var_param_value) = idempotency_key {
345            local_var_req_builder =
346                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
347        }
348        local_var_req_builder = local_var_req_builder.json(&respond_to_connection_request);
349
350        let local_var_req = local_var_req_builder.build()?;
351        let local_var_resp = local_var_client.execute(local_var_req).await?;
352
353        let local_var_status = local_var_resp.status();
354        let local_var_content = local_var_resp.text().await?;
355
356        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
357            Ok(())
358        } else {
359            let local_var_entity: Option<SubmitError> =
360                serde_json::from_str(&local_var_content).ok();
361            let local_var_error = ResponseContent {
362                status: local_var_status,
363                content: local_var_content,
364                entity: local_var_entity,
365            };
366            Err(Error::ResponseError(local_var_error))
367        }
368    }
369}
370
371/// struct for typed errors of method [`DAppConnectionsApi::create`]
372#[derive(Debug, Clone, Serialize, Deserialize)]
373#[serde(untagged)]
374pub enum CreateError {
375    Status400(),
376    Status500(),
377    UnknownValue(serde_json::Value),
378}
379
380/// struct for typed errors of method [`DAppConnectionsApi::get`]
381#[derive(Debug, Clone, Serialize, Deserialize)]
382#[serde(untagged)]
383pub enum GetError {
384    Status400(),
385    Status500(),
386    UnknownValue(serde_json::Value),
387}
388
389/// struct for typed errors of method [`DAppConnectionsApi::remove`]
390#[derive(Debug, Clone, Serialize, Deserialize)]
391#[serde(untagged)]
392pub enum RemoveError {
393    Status404(),
394    Status500(),
395    UnknownValue(serde_json::Value),
396}
397
398/// struct for typed errors of method [`DAppConnectionsApi::submit`]
399#[derive(Debug, Clone, Serialize, Deserialize)]
400#[serde(untagged)]
401pub enum SubmitError {
402    Status400(),
403    Status404(),
404    Status500(),
405    UnknownValue(serde_json::Value),
406}