1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::prelude::*;
use rive_models::payload::PushSubscribePayload;

impl Client {
    /// Create a new Web Push subscription.
    ///
    /// If an existing subscription exists on this session, it will be removed.
    pub async fn push_subscribe(&self, payload: PushSubscribePayload) -> Result<()> {
        self.client
            .post(ep!(self, "/push/subscribe"))
            .json(&payload)
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?;
        Ok(())
    }

    /// Remove the Web Push subscription associated with the current session.
    pub async fn push_unsubscribe(&self) -> Result<()> {
        self.client
            .post(ep!(self, "/push/unsubscribe"))
            .auth(&self.authentication)
            .send()
            .await?
            .process_error()
            .await?;
        Ok(())
    }
}