1use crate::SailhouseClient;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Deserialize)]
5pub struct RegisterResult {
6 pub outcome: String, }
8
9#[derive(Debug, Serialize)]
10pub struct FilterOption {
11 pub path: String,
12 pub value: String,
13}
14
15#[derive(Debug, Serialize)]
16struct RegisterPushSubscriptionRequest {
17 #[serde(rename = "type")]
18 pub subscription_type: String,
19 pub endpoint: String,
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub filter: Option<FilterOption>,
22}
23
24#[derive(Debug)]
25pub struct AdminClient {
26 client: SailhouseClient,
27}
28
29impl AdminClient {
30 pub fn new(client: SailhouseClient) -> Self {
31 Self { client }
32 }
33
34 pub async fn register_push_subscription(
35 &self,
36 topic: &str,
37 subscription: &str,
38 endpoint: &str,
39 filter: Option<FilterOption>,
40 ) -> Result<RegisterResult, reqwest::Error> {
41 let url = format!(
42 "{}/topics/{}/subscriptions/{}",
43 self.client.base_url, topic, subscription
44 );
45
46 let request_body = RegisterPushSubscriptionRequest {
47 subscription_type: "push".to_string(),
48 endpoint: endpoint.to_string(),
49 filter,
50 };
51
52 let req = self.client.client.put(&url).json(&request_body);
53
54 let response = self.client.do_req(req).await?;
55 let result = response.json::<RegisterResult>().await?;
56
57 Ok(result)
58 }
59}