fireblocks_sdk/apis/
keys_beta_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 KeysBetaApi: Send + Sync {
23 async fn get_mpc_keys_list(
29 &self,
30 ) -> Result<models::GetMpcKeysResponse, Error<GetMpcKeysListError>>;
31
32 async fn get_mpc_keys_list_by_user(
38 &self,
39 params: GetMpcKeysListByUserParams,
40 ) -> Result<models::GetMpcKeysResponse, Error<GetMpcKeysListByUserError>>;
41}
42
43pub struct KeysBetaApiClient {
44 configuration: Arc<configuration::Configuration>,
45}
46
47impl KeysBetaApiClient {
48 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
49 Self { configuration }
50 }
51}
52
53#[derive(Clone, Debug)]
56#[cfg_attr(feature = "bon", derive(::bon::Builder))]
57pub struct GetMpcKeysListByUserParams {
58 pub user_id: String,
60}
61
62#[async_trait]
63impl KeysBetaApi for KeysBetaApiClient {
64 async fn get_mpc_keys_list(
68 &self,
69 ) -> Result<models::GetMpcKeysResponse, Error<GetMpcKeysListError>> {
70 let local_var_configuration = &self.configuration;
71
72 let local_var_client = &local_var_configuration.client;
73
74 let local_var_uri_str = format!("{}/keys/mpc/list", local_var_configuration.base_path);
75 let mut local_var_req_builder =
76 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
77
78 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
79 local_var_req_builder = local_var_req_builder
80 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
81 }
82
83 let local_var_req = local_var_req_builder.build()?;
84 let local_var_resp = local_var_client.execute(local_var_req).await?;
85
86 let local_var_status = local_var_resp.status();
87 let local_var_content_type = local_var_resp
88 .headers()
89 .get("content-type")
90 .and_then(|v| v.to_str().ok())
91 .unwrap_or("application/octet-stream");
92 let local_var_content_type = super::ContentType::from(local_var_content_type);
93 let local_var_content = local_var_resp.text().await?;
94
95 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
96 match local_var_content_type {
97 ContentType::Json => {
98 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
99 }
100 ContentType::Text => {
101 return Err(Error::from(serde_json::Error::custom(
102 "Received `text/plain` content type response that cannot be converted to \
103 `models::GetMpcKeysResponse`",
104 )));
105 }
106 ContentType::Unsupported(local_var_unknown_type) => {
107 return Err(Error::from(serde_json::Error::custom(format!(
108 "Received `{local_var_unknown_type}` content type response that cannot be \
109 converted to `models::GetMpcKeysResponse`"
110 ))));
111 }
112 }
113 } else {
114 let local_var_entity: Option<GetMpcKeysListError> =
115 serde_json::from_str(&local_var_content).ok();
116 let local_var_error = ResponseContent {
117 status: local_var_status,
118 content: local_var_content,
119 entity: local_var_entity,
120 };
121 Err(Error::ResponseError(local_var_error))
122 }
123 }
124
125 async fn get_mpc_keys_list_by_user(
129 &self,
130 params: GetMpcKeysListByUserParams,
131 ) -> Result<models::GetMpcKeysResponse, Error<GetMpcKeysListByUserError>> {
132 let GetMpcKeysListByUserParams { user_id } = params;
133
134 let local_var_configuration = &self.configuration;
135
136 let local_var_client = &local_var_configuration.client;
137
138 let local_var_uri_str = format!(
139 "{}/keys/mpc/list/{userId}",
140 local_var_configuration.base_path,
141 userId = crate::apis::urlencode(user_id)
142 );
143 let mut local_var_req_builder =
144 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
145
146 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
147 local_var_req_builder = local_var_req_builder
148 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
149 }
150
151 let local_var_req = local_var_req_builder.build()?;
152 let local_var_resp = local_var_client.execute(local_var_req).await?;
153
154 let local_var_status = local_var_resp.status();
155 let local_var_content_type = local_var_resp
156 .headers()
157 .get("content-type")
158 .and_then(|v| v.to_str().ok())
159 .unwrap_or("application/octet-stream");
160 let local_var_content_type = super::ContentType::from(local_var_content_type);
161 let local_var_content = local_var_resp.text().await?;
162
163 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
164 match local_var_content_type {
165 ContentType::Json => {
166 crate::deserialize_wrapper(&local_var_content).map_err(Error::from)
167 }
168 ContentType::Text => {
169 return Err(Error::from(serde_json::Error::custom(
170 "Received `text/plain` content type response that cannot be converted to \
171 `models::GetMpcKeysResponse`",
172 )));
173 }
174 ContentType::Unsupported(local_var_unknown_type) => {
175 return Err(Error::from(serde_json::Error::custom(format!(
176 "Received `{local_var_unknown_type}` content type response that cannot be \
177 converted to `models::GetMpcKeysResponse`"
178 ))));
179 }
180 }
181 } else {
182 let local_var_entity: Option<GetMpcKeysListByUserError> =
183 serde_json::from_str(&local_var_content).ok();
184 let local_var_error = ResponseContent {
185 status: local_var_status,
186 content: local_var_content,
187 entity: local_var_entity,
188 };
189 Err(Error::ResponseError(local_var_error))
190 }
191 }
192}
193
194#[derive(Debug, Clone, Serialize, Deserialize)]
196#[serde(untagged)]
197pub enum GetMpcKeysListError {
198 DefaultResponse(models::ErrorSchema),
199 UnknownValue(serde_json::Value),
200}
201
202#[derive(Debug, Clone, Serialize, Deserialize)]
204#[serde(untagged)]
205pub enum GetMpcKeysListByUserError {
206 DefaultResponse(models::ErrorSchema),
207 UnknownValue(serde_json::Value),
208}