Refine core/network/mod.rs

This commit is contained in:
Temirkhan Myrzamadi 2019-09-03 20:34:29 +06:00
parent 3d6479be62
commit 383ea99e81

View file

@ -8,7 +8,9 @@ use crate::core::requests::{RequestError, ResponseResult};
const TELEGRAM_API_URL: &str = "https://api.telegram.org";
/// Create url for macking requests, see [telegram docs](https://core.telegram.org/bots/api#making-requests)
/// Creates URL for making HTTPS requests. See the [Telegram documentation].
///
/// [Telegram documentation]: https://core.telegram.org/bots/api#making-requests
fn method_url(base: &str, token: &str, method_name: &str) -> String {
format!(
"{url}/bot{token}/{method}",
@ -18,7 +20,9 @@ fn method_url(base: &str, token: &str, method_name: &str) -> String {
)
}
/// Create url for downloading file, see [telegram docs](https://core.telegram.org/bots/api#file)
/// Creates URL for downloading a file. See the [Telegram documentation].
///
/// [Telegram documentation] (https://core.telegram.org/bots/api#file)
fn file_url(base: &str, token: &str, file_path: &str) -> String {
format!(
"{url}/file/bot{token}/{file}",
@ -37,11 +41,10 @@ pub async fn request<T: DeserializeOwned>(
let mut response = client
.post(&method_url(TELEGRAM_API_URL, token, method_name))
.apply(|request_builder| {
if let Some(params) = params {
request_builder.multipart(params)
} else {
request_builder
}
params.map_or_else(
|| request_builder,
|params| request_builder.multipart(params),
)
})
.send()
.compat()