use std::env;
static WEBHOOK_URL: &str = "https://pushmore.io/webhook/";
#[derive(Default)]
pub struct PushMore {
key: String,
}
impl PushMore {
pub fn new() -> Self {
let env_key = "PUSH_MORE_KEY";
match env::var(env_key) {
Ok(val) => PushMore::new_with_key(val),
Err(e) => panic!("Invalid value for {}: `{}`", env_key, e),
}
}
pub fn new_with_key(key: String) -> Self {
PushMore { key }
}
pub fn send(&self, body: String) -> bool {
let url = format!("{}{}", WEBHOOK_URL, self.key);
if let Ok(resp) = ureq::post(&url).send_string(&body) {
if let Ok(b) = resp.into_string() {
return b.contains("OK");
}
}
false
}
}