Skip to main content

openapp_sdk_core/resources/
me.rs

1//! `Me` resource group.
2
3use std::sync::Arc;
4
5use reqwest::Method;
6
7use super::types;
8use crate::{
9    error::SdkError,
10    transport::{RequestSpec, Transport},
11};
12
13#[derive(Debug, Clone)]
14pub struct MeClient {
15    transport: Arc<Transport>,
16}
17
18impl MeClient {
19    pub(crate) fn new(transport: Arc<Transport>) -> Self {
20        Self { transport }
21    }
22
23    pub async fn apartments(&self) -> Result<types::MeApartmentsResponse, SdkError> {
24        self.transport
25            .request_json::<(), types::MeApartmentsResponse>(RequestSpec {
26                method: Method::GET,
27                path: "/me/apartments",
28                ..Default::default()
29            })
30            .await
31    }
32
33    pub async fn invitations(&self) -> Result<types::MeInvitationsResponse, SdkError> {
34        self.transport
35            .request_json::<(), types::MeInvitationsResponse>(RequestSpec {
36                method: Method::GET,
37                path: "/me/invitations",
38                ..Default::default()
39            })
40            .await
41    }
42
43    pub async fn push_subscription_status(
44        &self,
45    ) -> Result<types::MePushSubscriptionStatusResponse, SdkError> {
46        self.transport
47            .request_json::<(), types::MePushSubscriptionStatusResponse>(RequestSpec {
48                method: Method::GET,
49                path: "/me/push-subscription-status",
50                ..Default::default()
51            })
52            .await
53    }
54
55    pub async fn push_vapid_public_key(
56        &self,
57    ) -> Result<types::MePushVapidPublicKeyResponse, SdkError> {
58        self.transport
59            .request_json::<(), types::MePushVapidPublicKeyResponse>(RequestSpec {
60                method: Method::GET,
61                path: "/me/push-vapid-public-key",
62                ..Default::default()
63            })
64            .await
65    }
66
67    pub async fn subscribe_push(
68        &self,
69        body: &types::PostMePushSubscriptionPayload,
70    ) -> Result<(), SdkError> {
71        self.transport
72            .request_json::<types::PostMePushSubscriptionPayload, ()>(RequestSpec {
73                method: Method::POST,
74                path: "/me/push-subscriptions",
75                body: Some(body),
76                ..Default::default()
77            })
78            .await
79    }
80}