nodeless_rs/
store_webhook.rs1use crate::error::NodelessError;
4use crate::webhook::{CreateWebhook, Webhook};
5use crate::Nodeless;
6
7impl Nodeless {
8 pub async fn get_store_webhooks(&self, store_id: &str) -> Result<Vec<Webhook>, NodelessError> {
10 let url = self
11 .base_url
12 .join(&format!("api/v1/store/{}/webhook", store_id))?;
13
14 let res = self.make_get(url).await?;
15 Ok(serde_json::from_value(res["data"].to_owned())?)
16 }
17
18 pub async fn get_store_webhook(
20 &self,
21 store_id: &str,
22 webhook_id: &str,
23 ) -> Result<Webhook, NodelessError> {
24 let url = self
25 .base_url
26 .join(&format!("api/v1/store/{}/webhook/{}", store_id, webhook_id))?;
27
28 let res = self.make_get(url).await?;
29 Ok(serde_json::from_value(res["data"].to_owned())?)
30 }
31
32 pub async fn create_store_webhook(
34 &self,
35 store_id: &str,
36 webhook: CreateWebhook,
37 ) -> Result<Webhook, NodelessError> {
38 let url = self
39 .base_url
40 .join(&format!("api/v1/store/{}/webhook", store_id))?;
41
42 let res = self
43 .make_post(url, Some(serde_json::to_value(webhook)?))
44 .await?;
45 Ok(serde_json::from_value(res["data"].to_owned())?)
46 }
47
48 pub async fn delete_store_webhook(
50 &self,
51 store_id: &str,
52 webhook_id: &str,
53 ) -> Result<(), NodelessError> {
54 let url = self
55 .base_url
56 .join(&format!("api/v1/store/{}/webhook/{}", store_id, webhook_id))?;
57
58 let _res = self.make_delete(url).await.ok();
59 Ok(())
60 }
61
62 pub async fn update_store_webhook(
64 &self,
65 store_id: &str,
66 webhook_id: &str,
67 webhook: CreateWebhook,
68 ) -> Result<Webhook, NodelessError> {
69 let url = self
70 .base_url
71 .join(&format!("api/v1/store/{}/webhook/{}", store_id, webhook_id))?;
72
73 let res = self
74 .make_put(url, Some(serde_json::to_value(webhook)?))
75 .await?;
76 Ok(serde_json::from_value(res["data"].to_owned())?)
77 }
78}