bitwarden_api_api/apis/
devices_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21    apis::{ContentType, ResponseContent},
22    models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait DevicesApi: Send + Sync {
29    /// DELETE /devices/{id}
30    async fn deactivate<'a>(&self, id: &'a str) -> Result<(), Error<DeactivateError>>;
31
32    /// GET /devices/{id}
33    async fn get<'a>(&self, id: &'a str) -> Result<models::DeviceResponseModel, Error<GetError>>;
34
35    /// GET /devices
36    async fn get_all(
37        &self,
38    ) -> Result<models::DeviceAuthRequestResponseModelListResponseModel, Error<GetAllError>>;
39
40    /// GET /devices/identifier/{identifier}
41    async fn get_by_identifier<'a>(
42        &self,
43        identifier: &'a str,
44    ) -> Result<models::DeviceResponseModel, Error<GetByIdentifierError>>;
45
46    /// GET /devices/knowndevice
47    async fn get_by_identifier_query<'a>(
48        &self,
49        x_request_email: &'a str,
50        x_device_identifier: &'a str,
51    ) -> Result<bool, Error<GetByIdentifierQueryError>>;
52
53    /// POST /devices
54    async fn post<'a>(
55        &self,
56        device_request_model: Option<models::DeviceRequestModel>,
57    ) -> Result<models::DeviceResponseModel, Error<PostError>>;
58
59    /// POST /devices/lost-trust
60    async fn post_lost_trust(&self) -> Result<(), Error<PostLostTrustError>>;
61
62    /// POST /devices/untrust
63    async fn post_untrust<'a>(
64        &self,
65        untrust_devices_request_model: Option<models::UntrustDevicesRequestModel>,
66    ) -> Result<(), Error<PostUntrustError>>;
67
68    /// POST /devices/update-trust
69    async fn post_update_trust<'a>(
70        &self,
71        update_devices_trust_request_model: Option<models::UpdateDevicesTrustRequestModel>,
72    ) -> Result<(), Error<PostUpdateTrustError>>;
73
74    /// PUT /devices/{id}
75    async fn put<'a>(
76        &self,
77        id: &'a str,
78        device_request_model: Option<models::DeviceRequestModel>,
79    ) -> Result<models::DeviceResponseModel, Error<PutError>>;
80
81    /// PUT /devices/identifier/{identifier}/clear-token
82    async fn put_clear_token<'a>(
83        &self,
84        identifier: &'a str,
85    ) -> Result<(), Error<PutClearTokenError>>;
86
87    /// PUT /devices/{identifier}/keys
88    async fn put_keys<'a>(
89        &self,
90        identifier: &'a str,
91        device_keys_request_model: Option<models::DeviceKeysRequestModel>,
92    ) -> Result<models::DeviceResponseModel, Error<PutKeysError>>;
93
94    /// PUT /devices/identifier/{identifier}/token
95    async fn put_token<'a>(
96        &self,
97        identifier: &'a str,
98        device_token_request_model: Option<models::DeviceTokenRequestModel>,
99    ) -> Result<(), Error<PutTokenError>>;
100
101    /// PUT /devices/identifier/{identifier}/web-push-auth
102    async fn put_web_push_auth<'a>(
103        &self,
104        identifier: &'a str,
105        web_push_auth_request_model: Option<models::WebPushAuthRequestModel>,
106    ) -> Result<(), Error<PutWebPushAuthError>>;
107}
108
109pub struct DevicesApiClient {
110    configuration: Arc<configuration::Configuration>,
111}
112
113impl DevicesApiClient {
114    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
115        Self { configuration }
116    }
117}
118
119#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
120#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
121impl DevicesApi for DevicesApiClient {
122    async fn deactivate<'a>(&self, id: &'a str) -> Result<(), Error<DeactivateError>> {
123        let local_var_configuration = &self.configuration;
124
125        let local_var_client = &local_var_configuration.client;
126
127        let local_var_uri_str = format!(
128            "{}/devices/{id}",
129            local_var_configuration.base_path,
130            id = crate::apis::urlencode(id)
131        );
132        let mut local_var_req_builder =
133            local_var_client.request(reqwest::Method::DELETE, 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(ref local_var_token) = local_var_configuration.oauth_access_token {
140            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
141        };
142
143        let local_var_req = local_var_req_builder.build()?;
144        let local_var_resp = local_var_client.execute(local_var_req).await?;
145
146        let local_var_status = local_var_resp.status();
147        let local_var_content = local_var_resp.text().await?;
148
149        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
150            Ok(())
151        } else {
152            let local_var_entity: Option<DeactivateError> =
153                serde_json::from_str(&local_var_content).ok();
154            let local_var_error = ResponseContent {
155                status: local_var_status,
156                content: local_var_content,
157                entity: local_var_entity,
158            };
159            Err(Error::ResponseError(local_var_error))
160        }
161    }
162
163    async fn get<'a>(&self, id: &'a str) -> Result<models::DeviceResponseModel, Error<GetError>> {
164        let local_var_configuration = &self.configuration;
165
166        let local_var_client = &local_var_configuration.client;
167
168        let local_var_uri_str = format!(
169            "{}/devices/{id}",
170            local_var_configuration.base_path,
171            id = crate::apis::urlencode(id)
172        );
173        let mut local_var_req_builder =
174            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
175
176        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
177            local_var_req_builder = local_var_req_builder
178                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
179        }
180        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
181            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
182        };
183
184        let local_var_req = local_var_req_builder.build()?;
185        let local_var_resp = local_var_client.execute(local_var_req).await?;
186
187        let local_var_status = local_var_resp.status();
188        let local_var_content_type = local_var_resp
189            .headers()
190            .get("content-type")
191            .and_then(|v| v.to_str().ok())
192            .unwrap_or("application/octet-stream");
193        let local_var_content_type = super::ContentType::from(local_var_content_type);
194        let local_var_content = local_var_resp.text().await?;
195
196        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
197            match local_var_content_type {
198                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
199                ContentType::Text => {
200                    return Err(Error::from(serde_json::Error::custom(
201                        "Received `text/plain` content type response that cannot be converted to `models::DeviceResponseModel`",
202                    )));
203                }
204                ContentType::Unsupported(local_var_unknown_type) => {
205                    return Err(Error::from(serde_json::Error::custom(format!(
206                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::DeviceResponseModel`"
207                    ))));
208                }
209            }
210        } else {
211            let local_var_entity: Option<GetError> = serde_json::from_str(&local_var_content).ok();
212            let local_var_error = ResponseContent {
213                status: local_var_status,
214                content: local_var_content,
215                entity: local_var_entity,
216            };
217            Err(Error::ResponseError(local_var_error))
218        }
219    }
220
221    async fn get_all(
222        &self,
223    ) -> Result<models::DeviceAuthRequestResponseModelListResponseModel, Error<GetAllError>> {
224        let local_var_configuration = &self.configuration;
225
226        let local_var_client = &local_var_configuration.client;
227
228        let local_var_uri_str = format!("{}/devices", local_var_configuration.base_path);
229        let mut local_var_req_builder =
230            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
231
232        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
233            local_var_req_builder = local_var_req_builder
234                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
235        }
236        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
237            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
238        };
239
240        let local_var_req = local_var_req_builder.build()?;
241        let local_var_resp = local_var_client.execute(local_var_req).await?;
242
243        let local_var_status = local_var_resp.status();
244        let local_var_content_type = local_var_resp
245            .headers()
246            .get("content-type")
247            .and_then(|v| v.to_str().ok())
248            .unwrap_or("application/octet-stream");
249        let local_var_content_type = super::ContentType::from(local_var_content_type);
250        let local_var_content = local_var_resp.text().await?;
251
252        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
253            match local_var_content_type {
254                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
255                ContentType::Text => {
256                    return Err(Error::from(serde_json::Error::custom(
257                        "Received `text/plain` content type response that cannot be converted to `models::DeviceAuthRequestResponseModelListResponseModel`",
258                    )));
259                }
260                ContentType::Unsupported(local_var_unknown_type) => {
261                    return Err(Error::from(serde_json::Error::custom(format!(
262                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::DeviceAuthRequestResponseModelListResponseModel`"
263                    ))));
264                }
265            }
266        } else {
267            let local_var_entity: Option<GetAllError> =
268                serde_json::from_str(&local_var_content).ok();
269            let local_var_error = ResponseContent {
270                status: local_var_status,
271                content: local_var_content,
272                entity: local_var_entity,
273            };
274            Err(Error::ResponseError(local_var_error))
275        }
276    }
277
278    async fn get_by_identifier<'a>(
279        &self,
280        identifier: &'a str,
281    ) -> Result<models::DeviceResponseModel, Error<GetByIdentifierError>> {
282        let local_var_configuration = &self.configuration;
283
284        let local_var_client = &local_var_configuration.client;
285
286        let local_var_uri_str = format!(
287            "{}/devices/identifier/{identifier}",
288            local_var_configuration.base_path,
289            identifier = crate::apis::urlencode(identifier)
290        );
291        let mut local_var_req_builder =
292            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
293
294        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
295            local_var_req_builder = local_var_req_builder
296                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
297        }
298        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
299            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
300        };
301
302        let local_var_req = local_var_req_builder.build()?;
303        let local_var_resp = local_var_client.execute(local_var_req).await?;
304
305        let local_var_status = local_var_resp.status();
306        let local_var_content_type = local_var_resp
307            .headers()
308            .get("content-type")
309            .and_then(|v| v.to_str().ok())
310            .unwrap_or("application/octet-stream");
311        let local_var_content_type = super::ContentType::from(local_var_content_type);
312        let local_var_content = local_var_resp.text().await?;
313
314        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
315            match local_var_content_type {
316                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
317                ContentType::Text => {
318                    return Err(Error::from(serde_json::Error::custom(
319                        "Received `text/plain` content type response that cannot be converted to `models::DeviceResponseModel`",
320                    )));
321                }
322                ContentType::Unsupported(local_var_unknown_type) => {
323                    return Err(Error::from(serde_json::Error::custom(format!(
324                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::DeviceResponseModel`"
325                    ))));
326                }
327            }
328        } else {
329            let local_var_entity: Option<GetByIdentifierError> =
330                serde_json::from_str(&local_var_content).ok();
331            let local_var_error = ResponseContent {
332                status: local_var_status,
333                content: local_var_content,
334                entity: local_var_entity,
335            };
336            Err(Error::ResponseError(local_var_error))
337        }
338    }
339
340    async fn get_by_identifier_query<'a>(
341        &self,
342        x_request_email: &'a str,
343        x_device_identifier: &'a str,
344    ) -> Result<bool, Error<GetByIdentifierQueryError>> {
345        let local_var_configuration = &self.configuration;
346
347        let local_var_client = &local_var_configuration.client;
348
349        let local_var_uri_str =
350            format!("{}/devices/knowndevice", local_var_configuration.base_path);
351        let mut local_var_req_builder =
352            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
353
354        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
355            local_var_req_builder = local_var_req_builder
356                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
357        }
358        local_var_req_builder =
359            local_var_req_builder.header("x-Request-Email", x_request_email.to_string());
360        local_var_req_builder =
361            local_var_req_builder.header("x-Device-Identifier", x_device_identifier.to_string());
362        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
363            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
364        };
365
366        let local_var_req = local_var_req_builder.build()?;
367        let local_var_resp = local_var_client.execute(local_var_req).await?;
368
369        let local_var_status = local_var_resp.status();
370        let local_var_content_type = local_var_resp
371            .headers()
372            .get("content-type")
373            .and_then(|v| v.to_str().ok())
374            .unwrap_or("application/octet-stream");
375        let local_var_content_type = super::ContentType::from(local_var_content_type);
376        let local_var_content = local_var_resp.text().await?;
377
378        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
379            match local_var_content_type {
380                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
381                ContentType::Text => {
382                    return Err(Error::from(serde_json::Error::custom(
383                        "Received `text/plain` content type response that cannot be converted to `bool`",
384                    )));
385                }
386                ContentType::Unsupported(local_var_unknown_type) => {
387                    return Err(Error::from(serde_json::Error::custom(format!(
388                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `bool`"
389                    ))));
390                }
391            }
392        } else {
393            let local_var_entity: Option<GetByIdentifierQueryError> =
394                serde_json::from_str(&local_var_content).ok();
395            let local_var_error = ResponseContent {
396                status: local_var_status,
397                content: local_var_content,
398                entity: local_var_entity,
399            };
400            Err(Error::ResponseError(local_var_error))
401        }
402    }
403
404    async fn post<'a>(
405        &self,
406        device_request_model: Option<models::DeviceRequestModel>,
407    ) -> Result<models::DeviceResponseModel, Error<PostError>> {
408        let local_var_configuration = &self.configuration;
409
410        let local_var_client = &local_var_configuration.client;
411
412        let local_var_uri_str = format!("{}/devices", local_var_configuration.base_path);
413        let mut local_var_req_builder =
414            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
415
416        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
417            local_var_req_builder = local_var_req_builder
418                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
419        }
420        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
421            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
422        };
423        local_var_req_builder = local_var_req_builder.json(&device_request_model);
424
425        let local_var_req = local_var_req_builder.build()?;
426        let local_var_resp = local_var_client.execute(local_var_req).await?;
427
428        let local_var_status = local_var_resp.status();
429        let local_var_content_type = local_var_resp
430            .headers()
431            .get("content-type")
432            .and_then(|v| v.to_str().ok())
433            .unwrap_or("application/octet-stream");
434        let local_var_content_type = super::ContentType::from(local_var_content_type);
435        let local_var_content = local_var_resp.text().await?;
436
437        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
438            match local_var_content_type {
439                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
440                ContentType::Text => {
441                    return Err(Error::from(serde_json::Error::custom(
442                        "Received `text/plain` content type response that cannot be converted to `models::DeviceResponseModel`",
443                    )));
444                }
445                ContentType::Unsupported(local_var_unknown_type) => {
446                    return Err(Error::from(serde_json::Error::custom(format!(
447                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::DeviceResponseModel`"
448                    ))));
449                }
450            }
451        } else {
452            let local_var_entity: Option<PostError> = serde_json::from_str(&local_var_content).ok();
453            let local_var_error = ResponseContent {
454                status: local_var_status,
455                content: local_var_content,
456                entity: local_var_entity,
457            };
458            Err(Error::ResponseError(local_var_error))
459        }
460    }
461
462    async fn post_lost_trust(&self) -> Result<(), Error<PostLostTrustError>> {
463        let local_var_configuration = &self.configuration;
464
465        let local_var_client = &local_var_configuration.client;
466
467        let local_var_uri_str = format!("{}/devices/lost-trust", local_var_configuration.base_path);
468        let mut local_var_req_builder =
469            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
470
471        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
472            local_var_req_builder = local_var_req_builder
473                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
474        }
475        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
476            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
477        };
478
479        let local_var_req = local_var_req_builder.build()?;
480        let local_var_resp = local_var_client.execute(local_var_req).await?;
481
482        let local_var_status = local_var_resp.status();
483        let local_var_content = local_var_resp.text().await?;
484
485        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
486            Ok(())
487        } else {
488            let local_var_entity: Option<PostLostTrustError> =
489                serde_json::from_str(&local_var_content).ok();
490            let local_var_error = ResponseContent {
491                status: local_var_status,
492                content: local_var_content,
493                entity: local_var_entity,
494            };
495            Err(Error::ResponseError(local_var_error))
496        }
497    }
498
499    async fn post_untrust<'a>(
500        &self,
501        untrust_devices_request_model: Option<models::UntrustDevicesRequestModel>,
502    ) -> Result<(), Error<PostUntrustError>> {
503        let local_var_configuration = &self.configuration;
504
505        let local_var_client = &local_var_configuration.client;
506
507        let local_var_uri_str = format!("{}/devices/untrust", local_var_configuration.base_path);
508        let mut local_var_req_builder =
509            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
510
511        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
512            local_var_req_builder = local_var_req_builder
513                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
514        }
515        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
516            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
517        };
518        local_var_req_builder = local_var_req_builder.json(&untrust_devices_request_model);
519
520        let local_var_req = local_var_req_builder.build()?;
521        let local_var_resp = local_var_client.execute(local_var_req).await?;
522
523        let local_var_status = local_var_resp.status();
524        let local_var_content = local_var_resp.text().await?;
525
526        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
527            Ok(())
528        } else {
529            let local_var_entity: Option<PostUntrustError> =
530                serde_json::from_str(&local_var_content).ok();
531            let local_var_error = ResponseContent {
532                status: local_var_status,
533                content: local_var_content,
534                entity: local_var_entity,
535            };
536            Err(Error::ResponseError(local_var_error))
537        }
538    }
539
540    async fn post_update_trust<'a>(
541        &self,
542        update_devices_trust_request_model: Option<models::UpdateDevicesTrustRequestModel>,
543    ) -> Result<(), Error<PostUpdateTrustError>> {
544        let local_var_configuration = &self.configuration;
545
546        let local_var_client = &local_var_configuration.client;
547
548        let local_var_uri_str =
549            format!("{}/devices/update-trust", local_var_configuration.base_path);
550        let mut local_var_req_builder =
551            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
552
553        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
554            local_var_req_builder = local_var_req_builder
555                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
556        }
557        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
558            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
559        };
560        local_var_req_builder = local_var_req_builder.json(&update_devices_trust_request_model);
561
562        let local_var_req = local_var_req_builder.build()?;
563        let local_var_resp = local_var_client.execute(local_var_req).await?;
564
565        let local_var_status = local_var_resp.status();
566        let local_var_content = local_var_resp.text().await?;
567
568        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
569            Ok(())
570        } else {
571            let local_var_entity: Option<PostUpdateTrustError> =
572                serde_json::from_str(&local_var_content).ok();
573            let local_var_error = ResponseContent {
574                status: local_var_status,
575                content: local_var_content,
576                entity: local_var_entity,
577            };
578            Err(Error::ResponseError(local_var_error))
579        }
580    }
581
582    async fn put<'a>(
583        &self,
584        id: &'a str,
585        device_request_model: Option<models::DeviceRequestModel>,
586    ) -> Result<models::DeviceResponseModel, Error<PutError>> {
587        let local_var_configuration = &self.configuration;
588
589        let local_var_client = &local_var_configuration.client;
590
591        let local_var_uri_str = format!(
592            "{}/devices/{id}",
593            local_var_configuration.base_path,
594            id = crate::apis::urlencode(id)
595        );
596        let mut local_var_req_builder =
597            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
598
599        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
600            local_var_req_builder = local_var_req_builder
601                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
602        }
603        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
604            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
605        };
606        local_var_req_builder = local_var_req_builder.json(&device_request_model);
607
608        let local_var_req = local_var_req_builder.build()?;
609        let local_var_resp = local_var_client.execute(local_var_req).await?;
610
611        let local_var_status = local_var_resp.status();
612        let local_var_content_type = local_var_resp
613            .headers()
614            .get("content-type")
615            .and_then(|v| v.to_str().ok())
616            .unwrap_or("application/octet-stream");
617        let local_var_content_type = super::ContentType::from(local_var_content_type);
618        let local_var_content = local_var_resp.text().await?;
619
620        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
621            match local_var_content_type {
622                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
623                ContentType::Text => {
624                    return Err(Error::from(serde_json::Error::custom(
625                        "Received `text/plain` content type response that cannot be converted to `models::DeviceResponseModel`",
626                    )));
627                }
628                ContentType::Unsupported(local_var_unknown_type) => {
629                    return Err(Error::from(serde_json::Error::custom(format!(
630                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::DeviceResponseModel`"
631                    ))));
632                }
633            }
634        } else {
635            let local_var_entity: Option<PutError> = serde_json::from_str(&local_var_content).ok();
636            let local_var_error = ResponseContent {
637                status: local_var_status,
638                content: local_var_content,
639                entity: local_var_entity,
640            };
641            Err(Error::ResponseError(local_var_error))
642        }
643    }
644
645    async fn put_clear_token<'a>(
646        &self,
647        identifier: &'a str,
648    ) -> Result<(), Error<PutClearTokenError>> {
649        let local_var_configuration = &self.configuration;
650
651        let local_var_client = &local_var_configuration.client;
652
653        let local_var_uri_str = format!(
654            "{}/devices/identifier/{identifier}/clear-token",
655            local_var_configuration.base_path,
656            identifier = crate::apis::urlencode(identifier)
657        );
658        let mut local_var_req_builder =
659            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
660
661        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
662            local_var_req_builder = local_var_req_builder
663                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
664        }
665        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
666            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
667        };
668
669        let local_var_req = local_var_req_builder.build()?;
670        let local_var_resp = local_var_client.execute(local_var_req).await?;
671
672        let local_var_status = local_var_resp.status();
673        let local_var_content = local_var_resp.text().await?;
674
675        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
676            Ok(())
677        } else {
678            let local_var_entity: Option<PutClearTokenError> =
679                serde_json::from_str(&local_var_content).ok();
680            let local_var_error = ResponseContent {
681                status: local_var_status,
682                content: local_var_content,
683                entity: local_var_entity,
684            };
685            Err(Error::ResponseError(local_var_error))
686        }
687    }
688
689    async fn put_keys<'a>(
690        &self,
691        identifier: &'a str,
692        device_keys_request_model: Option<models::DeviceKeysRequestModel>,
693    ) -> Result<models::DeviceResponseModel, Error<PutKeysError>> {
694        let local_var_configuration = &self.configuration;
695
696        let local_var_client = &local_var_configuration.client;
697
698        let local_var_uri_str = format!(
699            "{}/devices/{identifier}/keys",
700            local_var_configuration.base_path,
701            identifier = crate::apis::urlencode(identifier)
702        );
703        let mut local_var_req_builder =
704            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
705
706        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
707            local_var_req_builder = local_var_req_builder
708                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
709        }
710        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
711            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
712        };
713        local_var_req_builder = local_var_req_builder.json(&device_keys_request_model);
714
715        let local_var_req = local_var_req_builder.build()?;
716        let local_var_resp = local_var_client.execute(local_var_req).await?;
717
718        let local_var_status = local_var_resp.status();
719        let local_var_content_type = local_var_resp
720            .headers()
721            .get("content-type")
722            .and_then(|v| v.to_str().ok())
723            .unwrap_or("application/octet-stream");
724        let local_var_content_type = super::ContentType::from(local_var_content_type);
725        let local_var_content = local_var_resp.text().await?;
726
727        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
728            match local_var_content_type {
729                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
730                ContentType::Text => {
731                    return Err(Error::from(serde_json::Error::custom(
732                        "Received `text/plain` content type response that cannot be converted to `models::DeviceResponseModel`",
733                    )));
734                }
735                ContentType::Unsupported(local_var_unknown_type) => {
736                    return Err(Error::from(serde_json::Error::custom(format!(
737                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::DeviceResponseModel`"
738                    ))));
739                }
740            }
741        } else {
742            let local_var_entity: Option<PutKeysError> =
743                serde_json::from_str(&local_var_content).ok();
744            let local_var_error = ResponseContent {
745                status: local_var_status,
746                content: local_var_content,
747                entity: local_var_entity,
748            };
749            Err(Error::ResponseError(local_var_error))
750        }
751    }
752
753    async fn put_token<'a>(
754        &self,
755        identifier: &'a str,
756        device_token_request_model: Option<models::DeviceTokenRequestModel>,
757    ) -> Result<(), Error<PutTokenError>> {
758        let local_var_configuration = &self.configuration;
759
760        let local_var_client = &local_var_configuration.client;
761
762        let local_var_uri_str = format!(
763            "{}/devices/identifier/{identifier}/token",
764            local_var_configuration.base_path,
765            identifier = crate::apis::urlencode(identifier)
766        );
767        let mut local_var_req_builder =
768            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
769
770        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
771            local_var_req_builder = local_var_req_builder
772                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
773        }
774        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
775            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
776        };
777        local_var_req_builder = local_var_req_builder.json(&device_token_request_model);
778
779        let local_var_req = local_var_req_builder.build()?;
780        let local_var_resp = local_var_client.execute(local_var_req).await?;
781
782        let local_var_status = local_var_resp.status();
783        let local_var_content = local_var_resp.text().await?;
784
785        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
786            Ok(())
787        } else {
788            let local_var_entity: Option<PutTokenError> =
789                serde_json::from_str(&local_var_content).ok();
790            let local_var_error = ResponseContent {
791                status: local_var_status,
792                content: local_var_content,
793                entity: local_var_entity,
794            };
795            Err(Error::ResponseError(local_var_error))
796        }
797    }
798
799    async fn put_web_push_auth<'a>(
800        &self,
801        identifier: &'a str,
802        web_push_auth_request_model: Option<models::WebPushAuthRequestModel>,
803    ) -> Result<(), Error<PutWebPushAuthError>> {
804        let local_var_configuration = &self.configuration;
805
806        let local_var_client = &local_var_configuration.client;
807
808        let local_var_uri_str = format!(
809            "{}/devices/identifier/{identifier}/web-push-auth",
810            local_var_configuration.base_path,
811            identifier = crate::apis::urlencode(identifier)
812        );
813        let mut local_var_req_builder =
814            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
815
816        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
817            local_var_req_builder = local_var_req_builder
818                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
819        }
820        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
821            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
822        };
823        local_var_req_builder = local_var_req_builder.json(&web_push_auth_request_model);
824
825        let local_var_req = local_var_req_builder.build()?;
826        let local_var_resp = local_var_client.execute(local_var_req).await?;
827
828        let local_var_status = local_var_resp.status();
829        let local_var_content = local_var_resp.text().await?;
830
831        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
832            Ok(())
833        } else {
834            let local_var_entity: Option<PutWebPushAuthError> =
835                serde_json::from_str(&local_var_content).ok();
836            let local_var_error = ResponseContent {
837                status: local_var_status,
838                content: local_var_content,
839                entity: local_var_entity,
840            };
841            Err(Error::ResponseError(local_var_error))
842        }
843    }
844}
845
846/// struct for typed errors of method [`DevicesApi::deactivate`]
847#[derive(Debug, Clone, Serialize, Deserialize)]
848#[serde(untagged)]
849pub enum DeactivateError {
850    UnknownValue(serde_json::Value),
851}
852/// struct for typed errors of method [`DevicesApi::get`]
853#[derive(Debug, Clone, Serialize, Deserialize)]
854#[serde(untagged)]
855pub enum GetError {
856    UnknownValue(serde_json::Value),
857}
858/// struct for typed errors of method [`DevicesApi::get_all`]
859#[derive(Debug, Clone, Serialize, Deserialize)]
860#[serde(untagged)]
861pub enum GetAllError {
862    UnknownValue(serde_json::Value),
863}
864/// struct for typed errors of method [`DevicesApi::get_by_identifier`]
865#[derive(Debug, Clone, Serialize, Deserialize)]
866#[serde(untagged)]
867pub enum GetByIdentifierError {
868    UnknownValue(serde_json::Value),
869}
870/// struct for typed errors of method [`DevicesApi::get_by_identifier_query`]
871#[derive(Debug, Clone, Serialize, Deserialize)]
872#[serde(untagged)]
873pub enum GetByIdentifierQueryError {
874    UnknownValue(serde_json::Value),
875}
876/// struct for typed errors of method [`DevicesApi::post`]
877#[derive(Debug, Clone, Serialize, Deserialize)]
878#[serde(untagged)]
879pub enum PostError {
880    UnknownValue(serde_json::Value),
881}
882/// struct for typed errors of method [`DevicesApi::post_lost_trust`]
883#[derive(Debug, Clone, Serialize, Deserialize)]
884#[serde(untagged)]
885pub enum PostLostTrustError {
886    UnknownValue(serde_json::Value),
887}
888/// struct for typed errors of method [`DevicesApi::post_untrust`]
889#[derive(Debug, Clone, Serialize, Deserialize)]
890#[serde(untagged)]
891pub enum PostUntrustError {
892    UnknownValue(serde_json::Value),
893}
894/// struct for typed errors of method [`DevicesApi::post_update_trust`]
895#[derive(Debug, Clone, Serialize, Deserialize)]
896#[serde(untagged)]
897pub enum PostUpdateTrustError {
898    UnknownValue(serde_json::Value),
899}
900/// struct for typed errors of method [`DevicesApi::put`]
901#[derive(Debug, Clone, Serialize, Deserialize)]
902#[serde(untagged)]
903pub enum PutError {
904    UnknownValue(serde_json::Value),
905}
906/// struct for typed errors of method [`DevicesApi::put_clear_token`]
907#[derive(Debug, Clone, Serialize, Deserialize)]
908#[serde(untagged)]
909pub enum PutClearTokenError {
910    UnknownValue(serde_json::Value),
911}
912/// struct for typed errors of method [`DevicesApi::put_keys`]
913#[derive(Debug, Clone, Serialize, Deserialize)]
914#[serde(untagged)]
915pub enum PutKeysError {
916    UnknownValue(serde_json::Value),
917}
918/// struct for typed errors of method [`DevicesApi::put_token`]
919#[derive(Debug, Clone, Serialize, Deserialize)]
920#[serde(untagged)]
921pub enum PutTokenError {
922    UnknownValue(serde_json::Value),
923}
924/// struct for typed errors of method [`DevicesApi::put_web_push_auth`]
925#[derive(Debug, Clone, Serialize, Deserialize)]
926#[serde(untagged)]
927pub enum PutWebPushAuthError {
928    UnknownValue(serde_json::Value),
929}