mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
Add multipart::{Payload, Request}
This commit is contained in:
parent
602d07623b
commit
4c2e8029a9
1 changed files with 36 additions and 0 deletions
|
@ -141,3 +141,39 @@ pub mod json {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod multipart {
|
||||
use serde::de::DeserializeOwned;
|
||||
use reqwest::multipart;
|
||||
|
||||
use crate::{Bot, network};
|
||||
use super::ResponseResult;
|
||||
|
||||
pub trait Payload {
|
||||
type Output;
|
||||
|
||||
const METHOD: &'static str;
|
||||
|
||||
fn payload(&self) -> multipart::Form;
|
||||
}
|
||||
|
||||
pub struct Request<'b, P> {
|
||||
pub(crate) bot: &'b Bot,
|
||||
pub(crate) payload: P,
|
||||
}
|
||||
|
||||
impl<P> Request<'_, P>
|
||||
where
|
||||
P: Payload,
|
||||
P::Output: DeserializeOwned,
|
||||
{
|
||||
pub async fn send(&self) -> ResponseResult<P::Output> {
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
P::METHOD,
|
||||
self.payload.payload(),
|
||||
).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue