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::{configuration, Error},
11    crate::{apis::ResponseContent, models},
12    async_trait::async_trait,
13    reqwest,
14    serde::{Deserialize, Serialize},
15    std::sync::Arc,
16};
17
18#[async_trait]
19pub trait DAppConnectionsApi: Send + Sync {
20    async fn create(
21        &self,
22        params: CreateParams,
23    ) -> Result<models::CreateConnectionResponse, Error<CreateError>>;
24    async fn get(
25        &self,
26        params: GetParams,
27    ) -> Result<models::GetConnectionsResponse, Error<GetError>>;
28    async fn remove(&self, params: RemoveParams) -> Result<(), Error<RemoveError>>;
29    async fn submit(&self, params: SubmitParams) -> Result<(), Error<SubmitError>>;
30}
31
32pub struct DAppConnectionsApiClient {
33    configuration: Arc<configuration::Configuration>,
34}
35
36impl DAppConnectionsApiClient {
37    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
38        Self { configuration }
39    }
40}
41
42/// struct for passing parameters to the method [`create`]
43#[derive(Clone, Debug)]
44#[cfg_attr(feature = "bon", derive(::bon::Builder))]
45pub struct CreateParams {
46    pub create_connection_request: models::CreateConnectionRequest,
47    /// A unique identifier for the request. If the request is sent multiple
48    /// times with the same idempotency key, the server will return the same
49    /// response as the first request. The idempotency key is valid for 24
50    /// hours.
51    pub idempotency_key: Option<String>,
52}
53
54/// struct for passing parameters to the method [`get`]
55#[derive(Clone, Debug)]
56#[cfg_attr(feature = "bon", derive(::bon::Builder))]
57pub struct GetParams {
58    /// List order (ascending or descending)
59    pub order: Option<String>,
60    /// Parsed filter object
61    pub filter: Option<models::GetFilterParameter>,
62    /// Property to sort Web3 connections by.
63    pub sort: Option<String>,
64    /// Amount of results to return in the next page.
65    pub page_size: Option<f64>,
66    /// Cursor to the next page
67    pub next: Option<String>,
68}
69
70/// struct for passing parameters to the method [`remove`]
71#[derive(Clone, Debug)]
72#[cfg_attr(feature = "bon", derive(::bon::Builder))]
73pub struct RemoveParams {
74    /// The ID of the existing Web3 connection to remove.
75    pub id: String,
76}
77
78/// struct for passing parameters to the method [`submit`]
79#[derive(Clone, Debug)]
80#[cfg_attr(feature = "bon", derive(::bon::Builder))]
81pub struct SubmitParams {
82    /// The ID of the initiated Web3 connection to approve.
83    pub id: String,
84    pub respond_to_connection_request: models::RespondToConnectionRequest,
85    /// A unique identifier for the request. If the request is sent multiple
86    /// times with the same idempotency key, the server will return the same
87    /// response as the first request. The idempotency key is valid for 24
88    /// hours.
89    pub idempotency_key: Option<String>,
90}
91
92#[async_trait]
93impl DAppConnectionsApi for DAppConnectionsApiClient {
94    /// Initiate a new dApp connection.  * Note: After this succeeds, make a
95    /// request to `PUT /v1/connections/wc/{id}` (below) to approve or reject
96    /// the new Web3 connection.
97    async fn create(
98        &self,
99        params: CreateParams,
100    ) -> Result<models::CreateConnectionResponse, Error<CreateError>> {
101        let CreateParams {
102            create_connection_request,
103            idempotency_key,
104        } = params;
105
106        let local_var_configuration = &self.configuration;
107
108        let local_var_client = &local_var_configuration.client;
109
110        let local_var_uri_str = format!("{}/connections/wc", local_var_configuration.base_path);
111        let mut local_var_req_builder =
112            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
113
114        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
115            local_var_req_builder = local_var_req_builder
116                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
117        }
118        if let Some(local_var_param_value) = idempotency_key {
119            local_var_req_builder =
120                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
121        }
122        local_var_req_builder = local_var_req_builder.json(&create_connection_request);
123
124        let local_var_req = local_var_req_builder.build()?;
125        let local_var_resp = local_var_client.execute(local_var_req).await?;
126
127        let local_var_status = local_var_resp.status();
128        let local_var_content = local_var_resp.text().await?;
129
130        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
131            serde_json::from_str(&local_var_content).map_err(Error::from)
132        } else {
133            let local_var_entity: Option<CreateError> =
134                serde_json::from_str(&local_var_content).ok();
135            let local_var_error = ResponseContent {
136                status: local_var_status,
137                content: local_var_content,
138                entity: local_var_entity,
139            };
140            Err(Error::ResponseError(local_var_error))
141        }
142    }
143
144    /// List all open dApp connections.
145    async fn get(
146        &self,
147        params: GetParams,
148    ) -> Result<models::GetConnectionsResponse, Error<GetError>> {
149        #[allow(unused_variables)]
150        let GetParams {
151            order,
152            filter,
153            sort,
154            page_size,
155            next,
156        } = 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!("{}/connections", local_var_configuration.base_path);
163        let mut local_var_req_builder =
164            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
165
166        if let Some(ref local_var_str) = order {
167            local_var_req_builder =
168                local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
169        }
170        // if let Some(ref local_var_str) = filter {
171        // local_var_req_builder = local_var_req_builder.query(&[("filter",
172        // &local_var_str.to_string())]);
173        //}
174        if let Some(ref local_var_str) = sort {
175            local_var_req_builder =
176                local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
177        }
178        if let Some(ref local_var_str) = page_size {
179            local_var_req_builder =
180                local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
181        }
182        if let Some(ref local_var_str) = next {
183            local_var_req_builder =
184                local_var_req_builder.query(&[("next", &local_var_str.to_string())]);
185        }
186        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
187            local_var_req_builder = local_var_req_builder
188                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
189        }
190
191        let local_var_req = local_var_req_builder.build()?;
192        let local_var_resp = local_var_client.execute(local_var_req).await?;
193
194        let local_var_status = local_var_resp.status();
195        let local_var_content = local_var_resp.text().await?;
196
197        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
198            serde_json::from_str(&local_var_content).map_err(Error::from)
199        } else {
200            let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
201            let local_var_error = ResponseContent {
202                status: local_var_status,
203                content: local_var_content,
204                entity: local_var_entity,
205            };
206            Err(Error::ResponseError(local_var_error))
207        }
208    }
209
210    /// Remove an existing dApp connection
211    async fn remove(&self, params: RemoveParams) -> Result<(), Error<RemoveError>> {
212        let RemoveParams { id } = params;
213
214        let local_var_configuration = &self.configuration;
215
216        let local_var_client = &local_var_configuration.client;
217
218        let local_var_uri_str = format!(
219            "{}/connections/wc/{id}",
220            local_var_configuration.base_path,
221            id = crate::apis::urlencode(id)
222        );
223        let mut local_var_req_builder =
224            local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
225
226        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
227            local_var_req_builder = local_var_req_builder
228                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
229        }
230
231        let local_var_req = local_var_req_builder.build()?;
232        let local_var_resp = local_var_client.execute(local_var_req).await?;
233
234        let local_var_status = local_var_resp.status();
235        let local_var_content = local_var_resp.text().await?;
236
237        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
238            Ok(())
239        } else {
240            let local_var_entity: Option<RemoveError> =
241                serde_json::from_str(&local_var_content).ok();
242            let local_var_error = ResponseContent {
243                status: local_var_status,
244                content: local_var_content,
245                entity: local_var_entity,
246            };
247            Err(Error::ResponseError(local_var_error))
248        }
249    }
250
251    /// Submit a response to *approve* or *reject* an initiated dApp connection.
252    /// * Note: This call is used to complete your `POST /v1/connections/wc/`
253    /// request.  After this succeeds, your new dApp connection is created and
254    /// functioning.
255    async fn submit(&self, params: SubmitParams) -> Result<(), Error<SubmitError>> {
256        let SubmitParams {
257            id,
258            respond_to_connection_request,
259            idempotency_key,
260        } = params;
261
262        let local_var_configuration = &self.configuration;
263
264        let local_var_client = &local_var_configuration.client;
265
266        let local_var_uri_str = format!(
267            "{}/connections/wc/{id}",
268            local_var_configuration.base_path,
269            id = crate::apis::urlencode(id)
270        );
271        let mut local_var_req_builder =
272            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
273
274        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
275            local_var_req_builder = local_var_req_builder
276                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
277        }
278        if let Some(local_var_param_value) = idempotency_key {
279            local_var_req_builder =
280                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
281        }
282        local_var_req_builder = local_var_req_builder.json(&respond_to_connection_request);
283
284        let local_var_req = local_var_req_builder.build()?;
285        let local_var_resp = local_var_client.execute(local_var_req).await?;
286
287        let local_var_status = local_var_resp.status();
288        let local_var_content = local_var_resp.text().await?;
289
290        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
291            Ok(())
292        } else {
293            let local_var_entity: Option<SubmitError> =
294                serde_json::from_str(&local_var_content).ok();
295            let local_var_error = ResponseContent {
296                status: local_var_status,
297                content: local_var_content,
298                entity: local_var_entity,
299            };
300            Err(Error::ResponseError(local_var_error))
301        }
302    }
303}
304
305/// struct for typed errors of method [`create`]
306#[derive(Debug, Clone, Serialize, Deserialize)]
307#[serde(untagged)]
308pub enum CreateError {
309    Status400(),
310    Status500(),
311    UnknownValue(serde_json::Value),
312}
313
314/// struct for typed errors of method [`get`]
315#[derive(Debug, Clone, Serialize, Deserialize)]
316#[serde(untagged)]
317pub enum GetError {
318    Status400(),
319    Status500(),
320    UnknownValue(serde_json::Value),
321}
322
323/// struct for typed errors of method [`remove`]
324#[derive(Debug, Clone, Serialize, Deserialize)]
325#[serde(untagged)]
326pub enum RemoveError {
327    Status404(),
328    Status500(),
329    UnknownValue(serde_json::Value),
330}
331
332/// struct for typed errors of method [`submit`]
333#[derive(Debug, Clone, Serialize, Deserialize)]
334#[serde(untagged)]
335pub enum SubmitError {
336    Status400(),
337    Status404(),
338    Status500(),
339    UnknownValue(serde_json::Value),
340}