1use std::sync::Arc;
12
13use async_trait::async_trait;
14use reqwest;
15use serde::{de::Error as _, Deserialize, Serialize};
16
17use super::{configuration, Error};
18use crate::{
19 apis::{ContentType, ResponseContent},
20 models,
21};
22
23#[async_trait]
24pub trait BlocksApi: Send + Sync {
25 async fn block_controller_create<'block_controller_create_request>(
27 &self,
28 block_controller_create_request: models::BlockControllerCreateRequest,
29 ) -> Result<models::BlockControllerFindAll200ResponseInner, Error<BlockControllerCreateError>>;
30
31 async fn block_controller_find_all<
33 'limit,
34 'created_at_gt,
35 'created_at_lt,
36 'created_at_ge,
37 'created_at_le,
38 'updated_at_gt,
39 'updated_at_lt,
40 'updated_at_ge,
41 'updated_at_le,
42 >(
43 &self,
44 limit: Option<f64>,
45 created_at_gt: Option<String>,
46 created_at_lt: Option<String>,
47 created_at_ge: Option<String>,
48 created_at_le: Option<String>,
49 updated_at_gt: Option<String>,
50 updated_at_lt: Option<String>,
51 updated_at_ge: Option<String>,
52 updated_at_le: Option<String>,
53 ) -> Result<
54 Vec<models::BlockControllerFindAll200ResponseInner>,
55 Error<BlockControllerFindAllError>,
56 >;
57
58 async fn block_controller_find_one<'id>(
60 &self,
61 id: &'id str,
62 ) -> Result<models::BlockControllerFindAll200ResponseInner, Error<BlockControllerFindOneError>>;
63
64 async fn block_controller_remove<'id>(
66 &self,
67 id: &'id str,
68 ) -> Result<models::BlockControllerFindAll200ResponseInner, Error<BlockControllerRemoveError>>;
69
70 async fn block_controller_update<'id, 'block_controller_update_request>(
72 &self,
73 id: &'id str,
74 block_controller_update_request: models::BlockControllerUpdateRequest,
75 ) -> Result<models::BlockControllerFindAll200ResponseInner, Error<BlockControllerUpdateError>>;
76}
77
78pub struct BlocksApiClient {
79 configuration: Arc<configuration::Configuration>,
80}
81
82impl BlocksApiClient {
83 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
84 Self { configuration }
85 }
86}
87
88#[async_trait]
89impl BlocksApi for BlocksApiClient {
90 async fn block_controller_create<'block_controller_create_request>(
91 &self,
92 block_controller_create_request: models::BlockControllerCreateRequest,
93 ) -> Result<models::BlockControllerFindAll200ResponseInner, Error<BlockControllerCreateError>>
94 {
95 let local_var_configuration = &self.configuration;
96
97 let local_var_client = &local_var_configuration.client;
98
99 let local_var_uri_str = format!("{}/block", local_var_configuration.base_path);
100 let mut local_var_req_builder =
101 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
102
103 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
104 local_var_req_builder = local_var_req_builder
105 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
106 }
107 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
108 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
109 };
110 local_var_req_builder = local_var_req_builder.json(&block_controller_create_request);
111
112 let local_var_req = local_var_req_builder.build()?;
113 let local_var_resp = local_var_client.execute(local_var_req).await?;
114
115 let local_var_status = local_var_resp.status();
116 let local_var_content_type = local_var_resp
117 .headers()
118 .get("content-type")
119 .and_then(|v| v.to_str().ok())
120 .unwrap_or("application/octet-stream");
121 let local_var_content_type = super::ContentType::from(local_var_content_type);
122 let local_var_content = local_var_resp.text().await?;
123
124 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
125 match local_var_content_type {
126 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
127 ContentType::Text => {
128 return Err(Error::from(serde_json::Error::custom(
129 "Received `text/plain` content type response that cannot be converted to \
130 `models::BlockControllerFindAll200ResponseInner`",
131 )))
132 }
133 ContentType::Unsupported(local_var_unknown_type) => {
134 return Err(Error::from(serde_json::Error::custom(format!(
135 "Received `{local_var_unknown_type}` content type response that cannot be \
136 converted to `models::BlockControllerFindAll200ResponseInner`"
137 ))))
138 }
139 }
140 } else {
141 let local_var_entity: Option<BlockControllerCreateError> =
142 serde_json::from_str(&local_var_content).ok();
143 let local_var_error = ResponseContent {
144 status: local_var_status,
145 content: local_var_content,
146 entity: local_var_entity,
147 };
148 Err(Error::ResponseError(local_var_error))
149 }
150 }
151
152 async fn block_controller_find_all<
153 'limit,
154 'created_at_gt,
155 'created_at_lt,
156 'created_at_ge,
157 'created_at_le,
158 'updated_at_gt,
159 'updated_at_lt,
160 'updated_at_ge,
161 'updated_at_le,
162 >(
163 &self,
164 limit: Option<f64>,
165 created_at_gt: Option<String>,
166 created_at_lt: Option<String>,
167 created_at_ge: Option<String>,
168 created_at_le: Option<String>,
169 updated_at_gt: Option<String>,
170 updated_at_lt: Option<String>,
171 updated_at_ge: Option<String>,
172 updated_at_le: Option<String>,
173 ) -> Result<
174 Vec<models::BlockControllerFindAll200ResponseInner>,
175 Error<BlockControllerFindAllError>,
176 > {
177 let local_var_configuration = &self.configuration;
178
179 let local_var_client = &local_var_configuration.client;
180
181 let local_var_uri_str = format!("{}/block", local_var_configuration.base_path);
182 let mut local_var_req_builder =
183 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
184
185 if let Some(ref local_var_str) = limit {
186 local_var_req_builder =
187 local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
188 }
189 if let Some(ref local_var_str) = created_at_gt {
190 local_var_req_builder =
191 local_var_req_builder.query(&[("createdAtGt", &local_var_str.to_string())]);
192 }
193 if let Some(ref local_var_str) = created_at_lt {
194 local_var_req_builder =
195 local_var_req_builder.query(&[("createdAtLt", &local_var_str.to_string())]);
196 }
197 if let Some(ref local_var_str) = created_at_ge {
198 local_var_req_builder =
199 local_var_req_builder.query(&[("createdAtGe", &local_var_str.to_string())]);
200 }
201 if let Some(ref local_var_str) = created_at_le {
202 local_var_req_builder =
203 local_var_req_builder.query(&[("createdAtLe", &local_var_str.to_string())]);
204 }
205 if let Some(ref local_var_str) = updated_at_gt {
206 local_var_req_builder =
207 local_var_req_builder.query(&[("updatedAtGt", &local_var_str.to_string())]);
208 }
209 if let Some(ref local_var_str) = updated_at_lt {
210 local_var_req_builder =
211 local_var_req_builder.query(&[("updatedAtLt", &local_var_str.to_string())]);
212 }
213 if let Some(ref local_var_str) = updated_at_ge {
214 local_var_req_builder =
215 local_var_req_builder.query(&[("updatedAtGe", &local_var_str.to_string())]);
216 }
217 if let Some(ref local_var_str) = updated_at_le {
218 local_var_req_builder =
219 local_var_req_builder.query(&[("updatedAtLe", &local_var_str.to_string())]);
220 }
221 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
222 local_var_req_builder = local_var_req_builder
223 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
224 }
225 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
226 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
227 };
228
229 let local_var_req = local_var_req_builder.build()?;
230 let local_var_resp = local_var_client.execute(local_var_req).await?;
231
232 let local_var_status = local_var_resp.status();
233 let local_var_content_type = local_var_resp
234 .headers()
235 .get("content-type")
236 .and_then(|v| v.to_str().ok())
237 .unwrap_or("application/octet-stream");
238 let local_var_content_type = super::ContentType::from(local_var_content_type);
239 let local_var_content = local_var_resp.text().await?;
240
241 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
242 match local_var_content_type {
243 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
244 ContentType::Text => {
245 return Err(Error::from(serde_json::Error::custom(
246 "Received `text/plain` content type response that cannot be converted to \
247 `Vec<models::BlockControllerFindAll200ResponseInner>`",
248 )))
249 }
250 ContentType::Unsupported(local_var_unknown_type) => {
251 return Err(Error::from(serde_json::Error::custom(format!(
252 "Received `{local_var_unknown_type}` content type response that cannot be \
253 converted to `Vec<models::BlockControllerFindAll200ResponseInner>`"
254 ))))
255 }
256 }
257 } else {
258 let local_var_entity: Option<BlockControllerFindAllError> =
259 serde_json::from_str(&local_var_content).ok();
260 let local_var_error = ResponseContent {
261 status: local_var_status,
262 content: local_var_content,
263 entity: local_var_entity,
264 };
265 Err(Error::ResponseError(local_var_error))
266 }
267 }
268
269 async fn block_controller_find_one<'id>(
270 &self,
271 id: &'id str,
272 ) -> Result<models::BlockControllerFindAll200ResponseInner, Error<BlockControllerFindOneError>>
273 {
274 let local_var_configuration = &self.configuration;
275
276 let local_var_client = &local_var_configuration.client;
277
278 let local_var_uri_str = format!(
279 "{}/block/{id}",
280 local_var_configuration.base_path,
281 id = crate::apis::urlencode(id)
282 );
283 let mut local_var_req_builder =
284 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
285
286 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
287 local_var_req_builder = local_var_req_builder
288 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
289 }
290 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
291 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
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_type = local_var_resp
299 .headers()
300 .get("content-type")
301 .and_then(|v| v.to_str().ok())
302 .unwrap_or("application/octet-stream");
303 let local_var_content_type = super::ContentType::from(local_var_content_type);
304 let local_var_content = local_var_resp.text().await?;
305
306 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
307 match local_var_content_type {
308 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
309 ContentType::Text => {
310 return Err(Error::from(serde_json::Error::custom(
311 "Received `text/plain` content type response that cannot be converted to \
312 `models::BlockControllerFindAll200ResponseInner`",
313 )))
314 }
315 ContentType::Unsupported(local_var_unknown_type) => {
316 return Err(Error::from(serde_json::Error::custom(format!(
317 "Received `{local_var_unknown_type}` content type response that cannot be \
318 converted to `models::BlockControllerFindAll200ResponseInner`"
319 ))))
320 }
321 }
322 } else {
323 let local_var_entity: Option<BlockControllerFindOneError> =
324 serde_json::from_str(&local_var_content).ok();
325 let local_var_error = ResponseContent {
326 status: local_var_status,
327 content: local_var_content,
328 entity: local_var_entity,
329 };
330 Err(Error::ResponseError(local_var_error))
331 }
332 }
333
334 async fn block_controller_remove<'id>(
335 &self,
336 id: &'id str,
337 ) -> Result<models::BlockControllerFindAll200ResponseInner, Error<BlockControllerRemoveError>>
338 {
339 let local_var_configuration = &self.configuration;
340
341 let local_var_client = &local_var_configuration.client;
342
343 let local_var_uri_str = format!(
344 "{}/block/{id}",
345 local_var_configuration.base_path,
346 id = crate::apis::urlencode(id)
347 );
348 let mut local_var_req_builder =
349 local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
350
351 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
352 local_var_req_builder = local_var_req_builder
353 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
354 }
355 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
356 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
357 };
358
359 let local_var_req = local_var_req_builder.build()?;
360 let local_var_resp = local_var_client.execute(local_var_req).await?;
361
362 let local_var_status = local_var_resp.status();
363 let local_var_content_type = local_var_resp
364 .headers()
365 .get("content-type")
366 .and_then(|v| v.to_str().ok())
367 .unwrap_or("application/octet-stream");
368 let local_var_content_type = super::ContentType::from(local_var_content_type);
369 let local_var_content = local_var_resp.text().await?;
370
371 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
372 match local_var_content_type {
373 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
374 ContentType::Text => {
375 return Err(Error::from(serde_json::Error::custom(
376 "Received `text/plain` content type response that cannot be converted to \
377 `models::BlockControllerFindAll200ResponseInner`",
378 )))
379 }
380 ContentType::Unsupported(local_var_unknown_type) => {
381 return Err(Error::from(serde_json::Error::custom(format!(
382 "Received `{local_var_unknown_type}` content type response that cannot be \
383 converted to `models::BlockControllerFindAll200ResponseInner`"
384 ))))
385 }
386 }
387 } else {
388 let local_var_entity: Option<BlockControllerRemoveError> =
389 serde_json::from_str(&local_var_content).ok();
390 let local_var_error = ResponseContent {
391 status: local_var_status,
392 content: local_var_content,
393 entity: local_var_entity,
394 };
395 Err(Error::ResponseError(local_var_error))
396 }
397 }
398
399 async fn block_controller_update<'id, 'block_controller_update_request>(
400 &self,
401 id: &'id str,
402 block_controller_update_request: models::BlockControllerUpdateRequest,
403 ) -> Result<models::BlockControllerFindAll200ResponseInner, Error<BlockControllerUpdateError>>
404 {
405 let local_var_configuration = &self.configuration;
406
407 let local_var_client = &local_var_configuration.client;
408
409 let local_var_uri_str = format!(
410 "{}/block/{id}",
411 local_var_configuration.base_path,
412 id = crate::apis::urlencode(id)
413 );
414 let mut local_var_req_builder =
415 local_var_client.request(reqwest::Method::PATCH, local_var_uri_str.as_str());
416
417 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
418 local_var_req_builder = local_var_req_builder
419 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
420 }
421 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
422 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
423 };
424 local_var_req_builder = local_var_req_builder.json(&block_controller_update_request);
425
426 let local_var_req = local_var_req_builder.build()?;
427 let local_var_resp = local_var_client.execute(local_var_req).await?;
428
429 let local_var_status = local_var_resp.status();
430 let local_var_content_type = local_var_resp
431 .headers()
432 .get("content-type")
433 .and_then(|v| v.to_str().ok())
434 .unwrap_or("application/octet-stream");
435 let local_var_content_type = super::ContentType::from(local_var_content_type);
436 let local_var_content = local_var_resp.text().await?;
437
438 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
439 match local_var_content_type {
440 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
441 ContentType::Text => {
442 return Err(Error::from(serde_json::Error::custom(
443 "Received `text/plain` content type response that cannot be converted to \
444 `models::BlockControllerFindAll200ResponseInner`",
445 )))
446 }
447 ContentType::Unsupported(local_var_unknown_type) => {
448 return Err(Error::from(serde_json::Error::custom(format!(
449 "Received `{local_var_unknown_type}` content type response that cannot be \
450 converted to `models::BlockControllerFindAll200ResponseInner`"
451 ))))
452 }
453 }
454 } else {
455 let local_var_entity: Option<BlockControllerUpdateError> =
456 serde_json::from_str(&local_var_content).ok();
457 let local_var_error = ResponseContent {
458 status: local_var_status,
459 content: local_var_content,
460 entity: local_var_entity,
461 };
462 Err(Error::ResponseError(local_var_error))
463 }
464 }
465}
466
467#[derive(Debug, Clone, Serialize, Deserialize)]
469#[serde(untagged)]
470pub enum BlockControllerCreateError {
471 UnknownValue(serde_json::Value),
472}
473
474#[derive(Debug, Clone, Serialize, Deserialize)]
476#[serde(untagged)]
477pub enum BlockControllerFindAllError {
478 UnknownValue(serde_json::Value),
479}
480
481#[derive(Debug, Clone, Serialize, Deserialize)]
483#[serde(untagged)]
484pub enum BlockControllerFindOneError {
485 UnknownValue(serde_json::Value),
486}
487
488#[derive(Debug, Clone, Serialize, Deserialize)]
490#[serde(untagged)]
491pub enum BlockControllerRemoveError {
492 UnknownValue(serde_json::Value),
493}
494
495#[derive(Debug, Clone, Serialize, Deserialize)]
497#[serde(untagged)]
498pub enum BlockControllerUpdateError {
499 UnknownValue(serde_json::Value),
500}