From 23c63a612bf4964d5fe2cc887b60554cb434c89e Mon Sep 17 00:00:00 2001 From: nextel Date: Tue, 17 Sep 2019 20:59:07 +0300 Subject: [PATCH] add getFile implementation --- src/core/requests/get_file.rs | 42 +++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/core/requests/get_file.rs b/src/core/requests/get_file.rs index 7a00e587..648d6452 100644 --- a/src/core/requests/get_file.rs +++ b/src/core/requests/get_file.rs @@ -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/, +/// where 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> { + Box::pin(async move { + network::request_json( + &self.ctx.client, + &self.ctx.token, + "getFile", + &self, + ) + .await + }) + } +} + + +impl<'a> GetFile<'a>{ + pub fn file_id(mut self, file_id: T) -> Self + where + T: Into, + { + self.file_id = message_id.into(); + self + } }