1use {
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 async fn create(
27 &self,
28 params: CreateParams,
29 ) -> Result<models::CreateConnectionResponse, Error<CreateError>>;
30
31 async fn get(
36 &self,
37 params: GetParams,
38 ) -> Result<models::GetConnectionsResponse, Error<GetError>>;
39
40 async fn remove(&self, params: RemoveParams) -> Result<(), Error<RemoveError>>;
45
46 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#[derive(Clone, Debug)]
67#[cfg_attr(feature = "bon", derive(::bon::Builder))]
68pub struct CreateParams {
69 pub create_connection_request: models::CreateConnectionRequest,
70 pub idempotency_key: Option<String>,
75}
76
77#[derive(Clone, Debug)]
79#[cfg_attr(feature = "bon", derive(::bon::Builder))]
80pub struct GetParams {
81 pub order: Option<String>,
83 pub filter: Option<models::GetFilterParameter>,
85 pub sort: Option<String>,
87 pub page_size: Option<f64>,
89 pub next: Option<String>,
91}
92
93#[derive(Clone, Debug)]
95#[cfg_attr(feature = "bon", derive(::bon::Builder))]
96pub struct RemoveParams {
97 pub id: String,
99}
100
101#[derive(Clone, Debug)]
103#[cfg_attr(feature = "bon", derive(::bon::Builder))]
104pub struct SubmitParams {
105 pub id: String,
107 pub respond_to_connection_request: models::RespondToConnectionRequest,
108 pub idempotency_key: Option<String>,
113}
114
115#[async_trait]
116impl DAppConnectionsApi for DAppConnectionsApiClient {
117 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 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", ¶m_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", ¶m_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", ¶m_value.to_string())]);
224 }
225 if let Some(ref param_value) = next {
226 local_var_req_builder =
227 local_var_req_builder.query(&[("next", ¶m_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 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 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#[derive(Debug, Clone, Serialize, Deserialize)]
373#[serde(untagged)]
374pub enum CreateError {
375 Status400(),
376 Status500(),
377 UnknownValue(serde_json::Value),
378}
379
380#[derive(Debug, Clone, Serialize, Deserialize)]
382#[serde(untagged)]
383pub enum GetError {
384 Status400(),
385 Status500(),
386 UnknownValue(serde_json::Value),
387}
388
389#[derive(Debug, Clone, Serialize, Deserialize)]
391#[serde(untagged)]
392pub enum RemoveError {
393 Status404(),
394 Status500(),
395 UnknownValue(serde_json::Value),
396}
397
398#[derive(Debug, Clone, Serialize, Deserialize)]
400#[serde(untagged)]
401pub enum SubmitError {
402 Status400(),
403 Status404(),
404 Status500(),
405 UnknownValue(serde_json::Value),
406}