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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
use std::net::IpAddr;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use crate::types::AllowedUpdate;
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct WebhookInfo {
#[serde(with = "crate::types::option_url_from_string")]
pub url: Option<reqwest::Url>,
pub has_custom_certificate: bool,
pub pending_update_count: u32,
pub ip_address: Option<IpAddr>,
#[serde(default, with = "crate::types::serde_opt_date_from_unix_timestamp")]
pub last_error_date: Option<DateTime<Utc>>,
pub last_error_message: Option<String>,
#[serde(default, with = "crate::types::serde_opt_date_from_unix_timestamp")]
pub last_synchronization_error_date: Option<DateTime<Utc>>,
pub max_connections: Option<u32>,
pub allowed_updates: Option<Vec<AllowedUpdate>>,
}
#[test]
fn empty_url() {
let json = r#"{"url":"","has_custom_certificate":false,"pending_update_count":0,"allowed_updates":["message"]}"#;
let actual: WebhookInfo = serde_json::from_str(json).unwrap();
let expected = WebhookInfo {
url: None,
has_custom_certificate: false,
pending_update_count: 0,
ip_address: None,
last_error_date: None,
last_error_message: None,
last_synchronization_error_date: None,
max_connections: None,
allowed_updates: Some(vec![AllowedUpdate::Message]),
};
assert_eq!(actual, expected);
let json = r#"{"ok":true,"result":{"url":"","has_custom_certificate":false,"pending_update_count":0,"allowed_updates":["message"]}}"#;
serde_json::from_str::<crate::net::TelegramResponse<WebhookInfo>>(json).unwrap();
}