1use url::Url;
2
3pub struct Webhook {
4 pub webhook: Url,
5}
6
7impl Webhook {
8 #[allow(clippy::result_large_err)]
14 #[cfg(feature = "ureq")]
15 pub fn send_ureq(&self, body: &str) -> Result<(), ureq::Error> {
16 ureq::post(self.webhook.as_str())
17 .set("User-Agent", crate::USER_AGENT)
18 .send_string(body)?;
19 Ok(())
20 }
21
22 #[cfg(feature = "reqwest")]
28 pub async fn send_reqwest(&self, body: &str) -> reqwest::Result<()> {
29 reqwest::ClientBuilder::new()
30 .user_agent(crate::USER_AGENT)
31 .build()?
32 .post(self.webhook.clone())
33 .body(body.to_owned())
34 .send()
35 .await
36 .and_then(reqwest::Response::error_for_status)
37 .map_err(reqwest::Error::without_url)?;
38 Ok(())
39 }
40}