Skip to main content

chipa_webhooks/platform/
generic.rs

1use serde_json::{Map, Value, json};
2
3use super::Platform;
4
5pub struct Generic {
6    url: String,
7    body_key: String,
8}
9
10impl Generic {
11    /// Posts `{ "<body_key>": "<rendered>" }` to `url`.
12    /// Default body key is `"text"`.
13    pub fn new(url: impl Into<String>) -> Self {
14        Self {
15            url: url.into(),
16            body_key: "text".to_owned(),
17        }
18    }
19
20    pub fn with_body_key(mut self, key: impl Into<String>) -> Self {
21        self.body_key = key.into();
22        self
23    }
24}
25
26impl Platform for Generic {
27    fn build_payload(&self, rendered: &str, _hints: &Map<String, Value>) -> Value {
28        json!({ self.body_key.as_str(): rendered })
29    }
30
31    fn endpoint(&self) -> &str {
32        &self.url
33    }
34}