mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 17:52:12 +01:00
Refine core/network/mod.rs
This commit is contained in:
parent
3d6479be62
commit
383ea99e81
1 changed files with 10 additions and 7 deletions
|
@ -8,7 +8,9 @@ use crate::core::requests::{RequestError, ResponseResult};
|
||||||
|
|
||||||
const TELEGRAM_API_URL: &str = "https://api.telegram.org";
|
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 {
|
fn method_url(base: &str, token: &str, method_name: &str) -> String {
|
||||||
format!(
|
format!(
|
||||||
"{url}/bot{token}/{method}",
|
"{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 {
|
fn file_url(base: &str, token: &str, file_path: &str) -> String {
|
||||||
format!(
|
format!(
|
||||||
"{url}/file/bot{token}/{file}",
|
"{url}/file/bot{token}/{file}",
|
||||||
|
@ -37,11 +41,10 @@ pub async fn request<T: DeserializeOwned>(
|
||||||
let mut response = client
|
let mut response = client
|
||||||
.post(&method_url(TELEGRAM_API_URL, token, method_name))
|
.post(&method_url(TELEGRAM_API_URL, token, method_name))
|
||||||
.apply(|request_builder| {
|
.apply(|request_builder| {
|
||||||
if let Some(params) = params {
|
params.map_or_else(
|
||||||
request_builder.multipart(params)
|
|| request_builder,
|
||||||
} else {
|
|params| request_builder.multipart(params),
|
||||||
request_builder
|
)
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.send()
|
.send()
|
||||||
.compat()
|
.compat()
|
||||||
|
|
Loading…
Reference in a new issue