mirror of
https://github.com/lifegpc/pixiv_downloader.git
synced 2026-07-08 01:32:41 +08:00
Update EveryPush Client
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
/// [EveryPush](https://github.com/PeanutMelonSeedBigAlmond/EveryPush) client
|
||||
pub mod every_push;
|
||||
|
||||
Reference in New Issue
Block a user