1use {
10 super::{configuration, Error},
11 crate::{
12 apis::{ContentType, ResponseContent},
13 models,
14 },
15 async_trait::async_trait,
16 reqwest,
17 serde::{de::Error as _, Deserialize, Serialize},
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 => serde_json::from_str(&local_var_content).map_err(Error::from),
160 ContentType::Text => {
161 return Err(Error::from(serde_json::Error::custom(
162 "Received `text/plain` content type response that cannot be converted to \
163 `models::CreateConnectionResponse`",
164 )))
165 }
166 ContentType::Unsupported(local_var_unknown_type) => {
167 return Err(Error::from(serde_json::Error::custom(format!(
168 "Received `{local_var_unknown_type}` content type response that cannot be \
169 converted to `models::CreateConnectionResponse`"
170 ))))
171 }
172 }
173 } else {
174 let local_var_entity: Option<CreateError> =
175 serde_json::from_str(&local_var_content).ok();
176 let local_var_error = ResponseContent {
177 status: local_var_status,
178 content: local_var_content,
179 entity: local_var_entity,
180 };
181 Err(Error::ResponseError(local_var_error))
182 }
183 }
184
185 async fn get(
188 &self,
189 params: GetParams,
190 ) -> Result<models::GetConnectionsResponse, Error<GetError>> {
191 let GetParams {
192 order,
193 filter,
194 sort,
195 page_size,
196 next,
197 } = params;
198
199 let local_var_configuration = &self.configuration;
200
201 let local_var_client = &local_var_configuration.client;
202
203 let local_var_uri_str = format!("{}/connections", local_var_configuration.base_path);
204 let mut local_var_req_builder =
205 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
206
207 if let Some(ref local_var_str) = order {
208 local_var_req_builder =
209 local_var_req_builder.query(&[("order", &local_var_str.to_string())]);
210 }
211 if let Some(ref _local_var_str) = filter {
212 eprintln!("warning filter for dapp not available...skipping");
213 }
216 if let Some(ref local_var_str) = sort {
217 local_var_req_builder =
218 local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
219 }
220 if let Some(ref local_var_str) = page_size {
221 local_var_req_builder =
222 local_var_req_builder.query(&[("pageSize", &local_var_str.to_string())]);
223 }
224 if let Some(ref local_var_str) = next {
225 local_var_req_builder =
226 local_var_req_builder.query(&[("next", &local_var_str.to_string())]);
227 }
228 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
229 local_var_req_builder = local_var_req_builder
230 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
231 }
232
233 let local_var_req = local_var_req_builder.build()?;
234 let local_var_resp = local_var_client.execute(local_var_req).await?;
235
236 let local_var_status = local_var_resp.status();
237 let local_var_content_type = local_var_resp
238 .headers()
239 .get("content-type")
240 .and_then(|v| v.to_str().ok())
241 .unwrap_or("application/octet-stream");
242 let local_var_content_type = super::ContentType::from(local_var_content_type);
243 let local_var_content = local_var_resp.text().await?;
244
245 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
246 match local_var_content_type {
247 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
248 ContentType::Text => {
249 return Err(Error::from(serde_json::Error::custom(
250 "Received `text/plain` content type response that cannot be converted to \
251 `models::GetConnectionsResponse`",
252 )))
253 }
254 ContentType::Unsupported(local_var_unknown_type) => {
255 return Err(Error::from(serde_json::Error::custom(format!(
256 "Received `{local_var_unknown_type}` content type response that cannot be \
257 converted to `models::GetConnectionsResponse`"
258 ))))
259 }
260 }
261 } else {
262 let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
263 let local_var_error = ResponseContent {
264 status: local_var_status,
265 content: local_var_content,
266 entity: local_var_entity,
267 };
268 Err(Error::ResponseError(local_var_error))
269 }
270 }
271
272 async fn remove(&self, params: RemoveParams) -> Result<(), Error<RemoveError>> {
275 let RemoveParams { id } = params;
276
277 let local_var_configuration = &self.configuration;
278
279 let local_var_client = &local_var_configuration.client;
280
281 let local_var_uri_str = format!(
282 "{}/connections/wc/{id}",
283 local_var_configuration.base_path,
284 id = crate::apis::urlencode(id)
285 );
286 let mut local_var_req_builder =
287 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
288
289 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
290 local_var_req_builder = local_var_req_builder
291 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
292 }
293
294 let local_var_req = local_var_req_builder.build()?;
295 let local_var_resp = local_var_client.execute(local_var_req).await?;
296
297 let local_var_status = local_var_resp.status();
298 let local_var_content = local_var_resp.text().await?;
299
300 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
301 Ok(())
302 } else {
303 let local_var_entity: Option<RemoveError> =
304 serde_json::from_str(&local_var_content).ok();
305 let local_var_error = ResponseContent {
306 status: local_var_status,
307 content: local_var_content,
308 entity: local_var_entity,
309 };
310 Err(Error::ResponseError(local_var_error))
311 }
312 }
313
314 async fn submit(&self, params: SubmitParams) -> Result<(), Error<SubmitError>> {
319 let SubmitParams {
320 id,
321 respond_to_connection_request,
322 idempotency_key,
323 } = params;
324
325 let local_var_configuration = &self.configuration;
326
327 let local_var_client = &local_var_configuration.client;
328
329 let local_var_uri_str = format!(
330 "{}/connections/wc/{id}",
331 local_var_configuration.base_path,
332 id = crate::apis::urlencode(id)
333 );
334 let mut local_var_req_builder =
335 local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
336
337 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
338 local_var_req_builder = local_var_req_builder
339 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
340 }
341 if let Some(local_var_param_value) = idempotency_key {
342 local_var_req_builder =
343 local_var_req_builder.header("Idempotency-Key", local_var_param_value.to_string());
344 }
345 local_var_req_builder = local_var_req_builder.json(&respond_to_connection_request);
346
347 let local_var_req = local_var_req_builder.build()?;
348 let local_var_resp = local_var_client.execute(local_var_req).await?;
349
350 let local_var_status = local_var_resp.status();
351 let local_var_content = local_var_resp.text().await?;
352
353 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
354 Ok(())
355 } else {
356 let local_var_entity: Option<SubmitError> =
357 serde_json::from_str(&local_var_content).ok();
358 let local_var_error = ResponseContent {
359 status: local_var_status,
360 content: local_var_content,
361 entity: local_var_entity,
362 };
363 Err(Error::ResponseError(local_var_error))
364 }
365 }
366}
367
368#[derive(Debug, Clone, Serialize, Deserialize)]
370#[serde(untagged)]
371pub enum CreateError {
372 Status400(),
373 Status500(),
374 UnknownValue(serde_json::Value),
375}
376
377#[derive(Debug, Clone, Serialize, Deserialize)]
379#[serde(untagged)]
380pub enum GetError {
381 Status400(),
382 Status500(),
383 UnknownValue(serde_json::Value),
384}
385
386#[derive(Debug, Clone, Serialize, Deserialize)]
388#[serde(untagged)]
389pub enum RemoveError {
390 Status404(),
391 Status500(),
392 UnknownValue(serde_json::Value),
393}
394
395#[derive(Debug, Clone, Serialize, Deserialize)]
397#[serde(untagged)]
398pub enum SubmitError {
399 Status400(),
400 Status404(),
401 Status500(),
402 UnknownValue(serde_json::Value),
403}