diff --git a/src/push/every_push.rs b/src/push/every_push.rs index 773d4c2..6eac5b1 100644 --- a/src/push/every_push.rs +++ b/src/push/every_push.rs @@ -1,6 +1,24 @@ use crate::webclient::WebClient; use std::collections::HashMap; +#[derive(Debug, Clone, Copy, Eq, PartialEq)] +/// Text type +pub enum EveryPushTextType { + Text, + Image, + Markdown, +} + +impl std::fmt::Display for EveryPushTextType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + EveryPushTextType::Text => write!(f, "text"), + EveryPushTextType::Image => write!(f, "image"), + EveryPushTextType::Markdown => write!(f, "markdown"), + } + } +} + pub struct EveryPushClient { client: WebClient, server: String, @@ -14,12 +32,19 @@ impl EveryPushClient { } } + /// push message to server + /// * `push_token` - push token + /// * `text` - text + /// * `title` - title + /// * `typ` - text type + /// + /// For more information, see [API document](https://github.com/PeanutMelonSeedBigAlmond/EveryPush.Server/blob/main/api.md#推送消息) pub async fn push_message( &self, push_token: String, text: String, title: Option, - typ: Option, + typ: Option, ) -> Result<(), String> { let mut params: HashMap = HashMap::new(); params.insert(String::from("pushToken"), push_token); @@ -29,7 +54,7 @@ impl EveryPushClient { None => None, }; match typ { - Some(t) => params.insert(String::from("type"), t), + Some(t) => params.insert(String::from("type"), format!("{}", t)), None => None, }; let re = self @@ -70,7 +95,7 @@ async fn test_every_push_push() { token, String::from("Push Test"), Some(String::from("Push")), - None, + Some(EveryPushTextType::Text), ) .await { diff --git a/src/push/mod.rs b/src/push/mod.rs index f937820..6ea4abd 100644 --- a/src/push/mod.rs +++ b/src/push/mod.rs @@ -1 +1,2 @@ +/// [EveryPush](https://github.com/PeanutMelonSeedBigAlmond/EveryPush) client pub mod every_push;