Merge pull request #25 from async-telegram-bot/feature/GetFile

add getFile implementation
This commit is contained in:
Temirkhan Myrzamadi 2019-09-18 00:04:44 +06:00 committed by GitHub
commit 2b49b22b42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,8 +1,46 @@
use crate::core::requests::RequestContext;
//TODO:: need implementation
use crate::core::requests::{RequestContext, RequestFuture, ResponseResult, Request};
use crate::core::types::File;
use crate::core::network;
/// Use this method to get basic info about a file and prepare it for downloading.
/// For the moment, bots can download files of up to 20MB in size.
/// On success, a File object is returned.
/// The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>,
/// where <file_path> is taken from the response.
/// It is guaranteed that the link will be valid for at least 1 hour.
/// When the link expires, a new one can be requested by calling getFile again.
#[derive(Debug, Clone, Serialize)]
struct GetFile<'a> {
#[serde(skip_serializing)]
ctx: RequestContext<'a>,
/// File identifier to get info about
file_id: String
}
impl<'a> Request<'a> for GetFile<'a> {
type ReturnValue = File;
fn send(self) -> RequestFuture<'a, ResponseResult<Self::ReturnValue>> {
Box::pin(async move {
network::request_json(
&self.ctx.client,
&self.ctx.token,
"getFile",
&self,
)
.await
})
}
}
impl<'a> GetFile<'a>{
pub fn file_id<T>(mut self, file_id: T) -> Self
where
T: Into<String>,
{
self.file_id = message_id.into();
self
}
}