telegram_bot_fork_raw/requests/
get_file.rs

1use requests::*;
2use types::*;
3
4/// Use this method to get basic info about a file and prepare it for downloading.
5/// For the moment, bots can download files of up to 20MB in size.
6#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
7#[must_use = "requests do nothing unless sent"]
8pub struct GetFile {
9    file_id: FileRef,
10}
11
12impl<'s> Request for GetFile {
13    type Type = JsonRequestType<Self>;
14    type Response = JsonIdResponse<File>;
15
16    fn serialize(&self) -> Result<HttpRequest, Error> {
17        Self::Type::serialize(RequestUrl::method("getFile"), self)
18    }
19}
20
21impl GetFile {
22    pub fn new<F>(file: F) -> Self
23    where
24        F: ToFileRef,
25    {
26        Self {
27            file_id: file.to_file_ref(),
28        }
29    }
30}
31
32/// Get basic info about a file and prepare it for downloading.
33pub trait CanGetFile {
34    fn get_file(&self) -> GetFile;
35}
36
37impl<F> CanGetFile for F
38where
39    F: ToFileRef,
40{
41    fn get_file(&self) -> GetFile {
42        GetFile::new(self)
43    }
44}