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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
use crate::{
methods::Method,
request::{Form, Request},
types::{ChatId, InputFile, Integer, Message, ParseMode, ReplyMarkup, ReplyMarkupError},
};
#[derive(Debug)]
pub struct SendVideo {
form: Form,
}
impl SendVideo {
pub fn new<C, V>(chat_id: C, video: V) -> Self
where
C: Into<ChatId>,
V: Into<InputFile>,
{
let mut form = Form::new();
form.insert_field("chat_id", chat_id.into());
form.insert_field("video", video.into());
SendVideo { form }
}
pub fn duration(mut self, value: Integer) -> Self {
self.form.insert_field("duration", value);
self
}
pub fn width(mut self, value: Integer) -> Self {
self.form.insert_field("width", value);
self
}
pub fn height(mut self, value: Integer) -> Self {
self.form.insert_field("height", value);
self
}
pub fn thumb<V>(mut self, value: V) -> Self
where
V: Into<InputFile>,
{
self.form.insert_field("thumb", value.into());
self
}
pub fn caption<S: Into<String>>(mut self, value: S) -> Self {
self.form.insert_field("caption", value.into());
self
}
pub fn parse_mode(mut self, value: ParseMode) -> Self {
self.form.insert_field("parse_mode", value);
self
}
pub fn supports_streaming(mut self, value: bool) -> Self {
self.form.insert_field("supports_streaming", value);
self
}
pub fn disable_notification(mut self, value: bool) -> Self {
self.form.insert_field("disable_notification", value);
self
}
pub fn reply_to_message_id(mut self, value: Integer) -> Self {
self.form.insert_field("reply_to_message_id", value);
self
}
pub fn reply_markup<R: Into<ReplyMarkup>>(mut self, value: R) -> Result<Self, ReplyMarkupError> {
let value = value.into();
self.form.insert_field("reply_markup", value.serialize()?);
Ok(self)
}
}
impl Method for SendVideo {
type Response = Message;
fn into_request(self) -> Request {
Request::form("sendVideo", self.form)
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::{
request::{RequestBody, RequestMethod},
types::ForceReply,
};
#[test]
fn send_video() {
let request = SendVideo::new(1, InputFile::file_id("file-id"))
.duration(100)
.width(200)
.height(300)
.thumb(InputFile::file_id("thumb-id"))
.caption("caption")
.parse_mode(ParseMode::Markdown)
.supports_streaming(true)
.disable_notification(true)
.reply_to_message_id(1)
.reply_markup(ForceReply::new(true))
.unwrap()
.into_request();
assert_eq!(request.get_method(), RequestMethod::Post);
assert_eq!(request.build_url("base-url", "token"), "base-url/bottoken/sendVideo");
if let RequestBody::Form(form) = request.into_body() {
assert_eq!(form.fields["chat_id"].get_text().unwrap(), "1");
assert!(form.fields["video"].get_file().is_some());
assert_eq!(form.fields["duration"].get_text().unwrap(), "100");
assert_eq!(form.fields["width"].get_text().unwrap(), "200");
assert_eq!(form.fields["height"].get_text().unwrap(), "300");
assert!(form.fields["thumb"].get_file().is_some());
assert_eq!(form.fields["caption"].get_text().unwrap(), "caption");
assert_eq!(form.fields["parse_mode"].get_text().unwrap(), "Markdown");
assert_eq!(form.fields["supports_streaming"].get_text().unwrap(), "true");
assert_eq!(form.fields["disable_notification"].get_text().unwrap(), "true");
assert_eq!(form.fields["reply_to_message_id"].get_text().unwrap(), "1");
assert_eq!(
form.fields["reply_markup"].get_text().unwrap(),
r#"{"force_reply":true}"#
);
} else {
panic!("Unexpected request body");
}
}
}