1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use crate::{methods::Method, request::Request, types::StickerSet};
use serde::Serialize;
#[derive(Clone, Debug, Serialize)]
pub struct GetStickerSet {
name: String,
}
impl GetStickerSet {
pub fn new<S: Into<String>>(name: S) -> Self {
GetStickerSet { name: name.into() }
}
}
impl Method for GetStickerSet {
type Response = StickerSet;
fn into_request(self) -> Request {
Request::json("getStickerSet", self)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::request::{RequestBody, RequestMethod};
use serde_json::Value;
#[test]
fn get_sticker_set() {
let request = GetStickerSet::new("name").into_request();
assert_eq!(request.get_method(), RequestMethod::Post);
assert_eq!(
request.build_url("base-url", "token"),
"base-url/bottoken/getStickerSet"
);
if let RequestBody::Json(data) = request.into_body() {
let data: Value = serde_json::from_str(&data.unwrap()).unwrap();
assert_eq!(data["name"], "name");
} else {
panic!("Unexpected request body");
}
}
}