Skip to main content

fireblocks_sdk/apis/
approval_requests_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 ApprovalRequestsApi: Send + Sync {
23    /// POST /tags/approval_requests/{id}/cancel
24    ///
25    /// Cancel an approval request by id. - Can only cancel requests in the
26    /// `PENDING` status. - Returns `202 Accepted` when the cancellation is
27    /// processed.
28    async fn cancel_approval_request(
29        &self,
30        params: CancelApprovalRequestParams,
31    ) -> Result<(), Error<CancelApprovalRequestError>>;
32
33    /// GET /tags/approval_requests/{id}
34    ///
35    /// Get an approval request by id
36    async fn get_approval_request(
37        &self,
38        params: GetApprovalRequestParams,
39    ) -> Result<models::ApprovalRequest, Error<GetApprovalRequestError>>;
40}
41
42pub struct ApprovalRequestsApiClient {
43    configuration: Arc<configuration::Configuration>,
44}
45
46impl ApprovalRequestsApiClient {
47    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
48        Self { configuration }
49    }
50}
51
52/// struct for passing parameters to the method
53/// [`ApprovalRequestsApi::cancel_approval_request`]
54#[derive(Clone, Debug)]
55#[cfg_attr(feature = "bon", derive(::bon::Builder))]
56pub struct CancelApprovalRequestParams {
57    pub id: String,
58    /// A unique identifier for the request. If the request is sent multiple
59    /// times with the same idempotency key, the server will return the same
60    /// response as the first request. The idempotency key is valid for 24
61    /// hours.
62    pub idempotency_key: Option<String>,
63}
64
65/// struct for passing parameters to the method
66/// [`ApprovalRequestsApi::get_approval_request`]
67#[derive(Clone, Debug)]
68#[cfg_attr(feature = "bon", derive(::bon::Builder))]
69pub struct GetApprovalRequestParams {
70    pub id: String,
71}
72
73#[async_trait]
74impl ApprovalRequestsApi for ApprovalRequestsApiClient {
75    /// Cancel an approval request by id. - Can only cancel requests in the
76    /// `PENDING` status. - Returns `202 Accepted` when the cancellation is
77    /// processed.
78    async fn cancel_approval_request(
79        &self,
80        params: CancelApprovalRequestParams,
81    ) -> Result<(), Error<CancelApprovalRequestError>> {
82        let CancelApprovalRequestParams {
83            id,
84            idempotency_key,
85        } = params;
86
87        let local_var_configuration = &self.configuration;
88
89        let local_var_client = &local_var_configuration.client;
90
91        let local_var_uri_str = format!(
92            "{}/tags/approval_requests/{id}/cancel",
93            local_var_configuration.base_path,
94            id = crate::apis::urlencode(id)
95        );
96        let mut local_var_req_builder =
97            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
98
99        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
100            local_var_req_builder = local_var_req_builder
101                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
102        }
103        if let Some(local_var_param_value) = idempotency_key {
104            local_var_req_builder =
105                local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
106        }
107
108        let local_var_req = local_var_req_builder.build()?;
109        let local_var_resp = local_var_client.execute(local_var_req).await?;
110
111        let local_var_status = local_var_resp.status();
112        let local_var_content = local_var_resp.text().await?;
113
114        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
115            Ok(())
116        } else {
117            let local_var_entity: Option<CancelApprovalRequestError> =
118                serde_json::from_str(&local_var_content).ok();
119            let local_var_error = ResponseContent {
120                status: local_var_status,
121                content: local_var_content,
122                entity: local_var_entity,
123            };
124            Err(Error::ResponseError(local_var_error))
125        }
126    }
127
128    /// Get an approval request by id
129    async fn get_approval_request(
130        &self,
131        params: GetApprovalRequestParams,
132    ) -> Result<models::ApprovalRequest, Error<GetApprovalRequestError>> {
133        let GetApprovalRequestParams { id } = params;
134
135        let local_var_configuration = &self.configuration;
136
137        let local_var_client = &local_var_configuration.client;
138
139        let local_var_uri_str = format!(
140            "{}/tags/approval_requests/{id}",
141            local_var_configuration.base_path,
142            id = crate::apis::urlencode(id)
143        );
144        let mut local_var_req_builder =
145            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
146
147        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
148            local_var_req_builder = local_var_req_builder
149                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
150        }
151
152        let local_var_req = local_var_req_builder.build()?;
153        let local_var_resp = local_var_client.execute(local_var_req).await?;
154
155        let local_var_status = local_var_resp.status();
156        let local_var_content_type = local_var_resp
157            .headers()
158            .get("content-type")
159            .and_then(|v| v.to_str().ok())
160            .unwrap_or("application/octet-stream");
161        let local_var_content_type = super::ContentType::from(local_var_content_type);
162        let local_var_content = local_var_resp.text().await?;
163
164        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
165            match local_var_content_type {
166                ContentType::Json => {
167                    crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
168                }
169                ContentType::Text => {
170                    return Err(Error::from(serde_json::Error::custom(
171                        "Received `text/plain` content type response that cannot be converted to \
172                         `models::ApprovalRequest`",
173                    )));
174                }
175                ContentType::Unsupported(local_var_unknown_type) => {
176                    return Err(Error::from(serde_json::Error::custom(format!(
177                        "Received `{local_var_unknown_type}` content type response that cannot be \
178                         converted to `models::ApprovalRequest`"
179                    ))));
180                }
181            }
182        } else {
183            let local_var_entity: Option<GetApprovalRequestError> =
184                serde_json::from_str(&local_var_content).ok();
185            let local_var_error = ResponseContent {
186                status: local_var_status,
187                content: local_var_content,
188                entity: local_var_entity,
189            };
190            Err(Error::ResponseError(local_var_error))
191        }
192    }
193}
194
195/// struct for typed errors of method
196/// [`ApprovalRequestsApi::cancel_approval_request`]
197#[derive(Debug, Clone, Serialize, Deserialize)]
198#[serde(untagged)]
199pub enum CancelApprovalRequestError {
200    Status401(models::ErrorResponse),
201    Status404(),
202    Status409(models::ErrorResponse),
203    UnknownValue(serde_json::Value),
204}
205
206/// struct for typed errors of method
207/// [`ApprovalRequestsApi::get_approval_request`]
208#[derive(Debug, Clone, Serialize, Deserialize)]
209#[serde(untagged)]
210pub enum GetApprovalRequestError {
211    Status401(models::ErrorResponse),
212    Status404(models::ErrorResponse),
213    UnknownValue(serde_json::Value),
214}