Update EveryPush Client

This commit is contained in:
2023-10-02 00:10:12 +00:00
committed by GitHub
parent b6da2c9d9c
commit 22ed24762d
2 changed files with 29 additions and 3 deletions

View File

@@ -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<String>,
typ: Option<String>,
typ: Option<EveryPushTextType>,
) -> Result<(), String> {
let mut params: HashMap<String, String> = 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
{

View File

@@ -1 +1,2 @@
/// [EveryPush](https://github.com/PeanutMelonSeedBigAlmond/EveryPush) client
pub mod every_push;