nodeless_rs/
paywall_webhook.rs

1//! Paywall Webhook
2
3use crate::error::NodelessError;
4use crate::webhook::{CreateWebhook, Webhook};
5use crate::Nodeless;
6
7impl Nodeless {
8    /// Get Paywall Webhooks
9    pub async fn get_paywall_webhooks(
10        &self,
11        paywall_id: &str,
12    ) -> Result<Vec<Webhook>, NodelessError> {
13        let url = self
14            .base_url
15            .join(&format!("api/v1/paywall/{}/webhook", paywall_id))?;
16
17        let res = self.make_get(url).await?;
18        Ok(serde_json::from_value(res["data"].to_owned())?)
19    }
20
21    /// Get Paywall Webhook
22    pub async fn get_paywall_webhook(
23        &self,
24        paywall_id: &str,
25        webhook_id: &str,
26    ) -> Result<Webhook, NodelessError> {
27        let url = self.base_url.join(&format!(
28            "api/v1/paywall/{}/webhook/{}",
29            paywall_id, webhook_id
30        ))?;
31
32        let res = self.make_get(url).await?;
33        Ok(serde_json::from_value(res["data"].to_owned())?)
34    }
35
36    /// Create Paywall Webhook
37    pub async fn create_paywall_webhook(
38        &self,
39        paywall_id: &str,
40        webhook: CreateWebhook,
41    ) -> Result<Webhook, NodelessError> {
42        let url = self
43            .base_url
44            .join(&format!("api/v1/paywall/{}/webhook", paywall_id))?;
45
46        let res = self
47            .make_post(url, Some(serde_json::to_value(webhook)?))
48            .await?;
49        Ok(serde_json::from_value(res["data"].to_owned())?)
50    }
51
52    /// Delete Paywall Webhook
53    pub async fn delete_paywall_webhook(
54        &self,
55        paywall_id: &str,
56        webhook_id: &str,
57    ) -> Result<(), NodelessError> {
58        let url = self.base_url.join(&format!(
59            "api/v1/paywall/{}/webhook/{}",
60            paywall_id, webhook_id
61        ))?;
62
63        let _res = self.make_delete(url).await.ok();
64        Ok(())
65    }
66
67    /// Update Paywall Webhook
68    pub async fn update_paywall_webhook(
69        &self,
70        paywall_id: &str,
71        webhook_id: &str,
72        webhook: CreateWebhook,
73    ) -> Result<Webhook, NodelessError> {
74        let url = self.base_url.join(&format!(
75            "api/v1/paywall/{}/webhook/{}",
76            paywall_id, webhook_id
77        ))?;
78
79        let res = self
80            .make_put(url, Some(serde_json::to_value(webhook)?))
81            .await?;
82        Ok(serde_json::from_value(res["data"].to_owned())?)
83    }
84}