add DingTalk::from_token
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "dingtalk"
|
name = "dingtalk"
|
||||||
version = "1.3.1"
|
version = "1.3.2"
|
||||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "DingTalk Robot Util, Send text/markdown/link messages using DingTalk robot, 钉钉机器人"
|
description = "DingTalk Robot Util, Send text/markdown/link messages using DingTalk robot, 钉钉机器人"
|
||||||
|
|||||||
@@ -109,6 +109,8 @@ WeChat Work config:
|
|||||||
|
|
||||||
#### Changelog
|
#### Changelog
|
||||||
|
|
||||||
|
* v1.3.2
|
||||||
|
* Add `DingTalk::from_token`
|
||||||
* v1.3.1
|
* v1.3.1
|
||||||
* Add `DingTalk::new_wechat`
|
* Add `DingTalk::new_wechat`
|
||||||
* v1.3.0
|
* v1.3.0
|
||||||
|
|||||||
21
src/lib.rs
21
src/lib.rs
@@ -183,6 +183,27 @@ impl <'a> DingTalkMessage<'a> {
|
|||||||
|
|
||||||
impl <'a> DingTalk<'a> {
|
impl <'a> DingTalk<'a> {
|
||||||
|
|
||||||
|
/// Create `DingTalk` from token:
|
||||||
|
/// wechatwork:access_token
|
||||||
|
/// dingtalk:access_token?sec_token
|
||||||
|
pub fn from_token(token: &str) -> XResult<Self> {
|
||||||
|
if token.starts_with("dingtalk:") {
|
||||||
|
let token_and_or_sec = &token["dingtalk:".len()..];
|
||||||
|
let mut token_and_or_sec_vec = token_and_or_sec.split('?');
|
||||||
|
let access_token = match token_and_or_sec_vec.next() {
|
||||||
|
Some(t) => t, None => token_and_or_sec,
|
||||||
|
};
|
||||||
|
let sec_token = match token_and_or_sec_vec.next() {
|
||||||
|
Some(t) => t, None => "",
|
||||||
|
};
|
||||||
|
Ok(Self::new(Self::string_to_a_str(access_token), Self::string_to_a_str(sec_token)))
|
||||||
|
} else if token.starts_with("wechatwork:") {
|
||||||
|
Ok(Self::new_wechat(Self::string_to_a_str(&token["wechatwork:".len()..])))
|
||||||
|
} else {
|
||||||
|
Err(Box::new(Error::new(ErrorKind::Other, format!("Tokne format erorr: {}", token))))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Create `DingTalk` from file
|
/// Create `DingTalk` from file
|
||||||
///
|
///
|
||||||
/// Format see `DingTalk::from_json(json: &str)`
|
/// Format see `DingTalk::from_json(json: &str)`
|
||||||
|
|||||||
Reference in New Issue
Block a user