jmap_client/push_subscription/
get.rs

1/*
2 * Copyright Stalwart Labs LLC See the COPYING
3 * file at the top-level directory of this distribution.
4 *
5 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
8 * option. This file may not be copied, modified, or distributed
9 * except according to those terms.
10 */
11
12use crate::{core::get::GetObject, Get, Set, DataType};
13
14use super::{Keys, PushSubscription};
15
16impl PushSubscription<Get> {
17    pub fn id(&self) -> Option<&str> {
18        self.id.as_deref()
19    }
20
21    pub fn take_id(&mut self) -> String {
22        self.id.take().unwrap_or_default()
23    }
24
25    pub fn device_client_id(&self) -> Option<&str> {
26        self.device_client_id.as_deref()
27    }
28
29    pub fn url(&self) -> Option<&str> {
30        self.url.as_deref()
31    }
32
33    pub fn keys(&self) -> Option<&Keys> {
34        self.keys.as_ref()
35    }
36
37    pub fn verification_code(&self) -> Option<&str> {
38        self.verification_code.as_deref()
39    }
40
41    pub fn expires(&self) -> Option<i64> {
42        self.expires.map(|v| v.timestamp())
43    }
44
45    pub fn types(&self) -> Option<&[DataType]> {
46        self.types.as_deref()
47    }
48}
49
50impl Keys {
51    pub fn p256dh(&self) -> Option<Vec<u8>> {
52        base64::decode_config(&self.p256dh, base64::URL_SAFE).ok()
53    }
54
55    pub fn auth(&self) -> Option<Vec<u8>> {
56        base64::decode_config(&self.auth, base64::URL_SAFE).ok()
57    }
58}
59
60impl GetObject for PushSubscription<Set> {
61    type GetArguments = ();
62}
63
64impl GetObject for PushSubscription<Get> {
65    type GetArguments = ();
66}