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