mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-05 10:24:32 +01:00
add Requester trait and GetMe payload
This commit is contained in:
parent
f3e0005335
commit
2cabc5fb4e
8 changed files with 73 additions and 8 deletions
|
@ -1,4 +1,5 @@
|
|||
use crate::{
|
||||
payloads,
|
||||
requests::{
|
||||
AddStickerToSet, AnswerCallbackQuery, AnswerInlineQuery, AnswerPreCheckoutQuery,
|
||||
AnswerShippingQuery, CreateNewStickerSet, DeleteChatPhoto, DeleteChatStickerSet,
|
||||
|
@ -8,14 +9,15 @@ use crate::{
|
|||
EditMessageReplyMarkup, EditMessageText, ExportChatInviteLink, ForwardMessage, GetChat,
|
||||
GetChatAdministrators, GetChatMember, GetChatMembersCount, GetFile, GetGameHighScores,
|
||||
GetMe, GetMyCommands, GetStickerSet, GetUpdates, GetUpdatesNonStrict, GetUserProfilePhotos,
|
||||
GetWebhookInfo, KickChatMember, LeaveChat, PinChatMessage, PromoteChatMember,
|
||||
RestrictChatMember, SendAnimation, SendAudio, SendChatAction, SendChatActionKind,
|
||||
SendContact, SendDice, SendDocument, SendGame, SendInvoice, SendLocation, SendMediaGroup,
|
||||
SendMessage, SendPhoto, SendPoll, SendSticker, SendVenue, SendVideo, SendVideoNote,
|
||||
SendVoice, SetChatAdministratorCustomTitle, SetChatDescription, SetChatPermissions,
|
||||
SetChatPhoto, SetChatStickerSet, SetChatTitle, SetGameScore, SetMyCommands,
|
||||
SetStickerPositionInSet, SetStickerSetThumb, SetWebhook, StopInlineMessageLiveLocation,
|
||||
StopMessageLiveLocation, StopPoll, UnbanChatMember, UnpinChatMessage, UploadStickerFile,
|
||||
GetWebhookInfo, JsonRequest, KickChatMember, LeaveChat, PinChatMessage, PromoteChatMember,
|
||||
Requester, RestrictChatMember, SendAnimation, SendAudio, SendChatAction,
|
||||
SendChatActionKind, SendContact, SendDice, SendDocument, SendGame, SendInvoice,
|
||||
SendLocation, SendMediaGroup, SendMessage, SendPhoto, SendPoll, SendSticker, SendVenue,
|
||||
SendVideo, SendVideoNote, SendVoice, SetChatAdministratorCustomTitle, SetChatDescription,
|
||||
SetChatPermissions, SetChatPhoto, SetChatStickerSet, SetChatTitle, SetGameScore,
|
||||
SetMyCommands, SetStickerPositionInSet, SetStickerSetThumb, SetWebhook,
|
||||
StopInlineMessageLiveLocation, StopMessageLiveLocation, StopPoll, UnbanChatMember,
|
||||
UnpinChatMessage, UploadStickerFile,
|
||||
},
|
||||
types::{
|
||||
BotCommand, ChatId, ChatPermissions, InlineQueryResult, InputFile, InputMedia,
|
||||
|
@ -1701,3 +1703,11 @@ impl Bot {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Requester for Bot {
|
||||
type GetMe = JsonRequest<payloads::GetMe>;
|
||||
|
||||
fn get_me(&self) -> JsonRequest<payloads::GetMe> {
|
||||
Self::GetMe::new(self.clone(), payloads::GetMe::new())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@ pub use self::{
|
|||
errors::{ApiErrorKind, DownloadError, KnownApiErrorKind, RequestError},
|
||||
};
|
||||
|
||||
pub mod payloads;
|
||||
pub mod prelude;
|
||||
pub mod requests;
|
||||
pub mod types;
|
||||
|
||||
|
|
29
src/payloads/get_me.rs
Normal file
29
src/payloads/get_me.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
requests::{HasPayload, Payload},
|
||||
types::User,
|
||||
};
|
||||
|
||||
/// A filter method for testing your bot's auth token. Requires no parameters.
|
||||
/// Returns basic information about the bot in form of a [`User`] object.
|
||||
///
|
||||
/// [`User`]: crate::types::User
|
||||
#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, Default, Deserialize, Serialize)]
|
||||
pub struct GetMe {}
|
||||
|
||||
impl GetMe {
|
||||
pub const fn new() -> Self {
|
||||
GetMe {}
|
||||
}
|
||||
}
|
||||
|
||||
impl Payload for GetMe {
|
||||
type Output = User;
|
||||
|
||||
const NAME: &'static str = "getMe";
|
||||
}
|
||||
|
||||
pub trait GetMeSetters: HasPayload<Payload = GetMe> + Sized {}
|
||||
|
||||
impl<P> GetMeSetters for P where P: HasPayload<Payload = GetMe> {}
|
5
src/payloads/mod.rs
Normal file
5
src/payloads/mod.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
pub mod setters;
|
||||
|
||||
mod get_me;
|
||||
|
||||
pub use get_me::{GetMe, GetMeSetters};
|
1
src/payloads/setters.rs
Normal file
1
src/payloads/setters.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub use crate::payloads::{GetMeSetters as _};
|
1
src/prelude.rs
Normal file
1
src/prelude.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub use crate::requests::Requester;
|
|
@ -9,11 +9,13 @@ pub use self::{has_payload::HasPayload, payload::Payload, request::Request};
|
|||
mod all;
|
||||
mod json;
|
||||
mod multipart;
|
||||
mod requester;
|
||||
mod utils;
|
||||
|
||||
pub use all::*;
|
||||
pub use json::JsonRequest;
|
||||
pub use multipart::MultipartRequest;
|
||||
pub use requester::Requester;
|
||||
|
||||
/// A type that is returned after making a request to Telegram.
|
||||
pub type ResponseResult<T> = Result<T, crate::RequestError>;
|
||||
|
|
15
src/requests/requester.rs
Normal file
15
src/requests/requester.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
use crate::{payloads::GetMe, requests::Request};
|
||||
|
||||
/// The trait implemented by all bots & bot wrappers.
|
||||
/// Essentially a request builder factory (?).
|
||||
///
|
||||
/// _This trait is included in the crate's [`prelude`](crate::prelude)_.
|
||||
#[cfg_attr(all(docsrs, feature = "nightly"), doc(spotlight))]
|
||||
pub trait Requester {
|
||||
type GetMe: Request<Payload = GetMe>;
|
||||
|
||||
/// For telegram documentation of the method see [`GetMe`].
|
||||
fn get_me(&self) -> Self::GetMe;
|
||||
|
||||
// FIXME(waffle): add remaining 69 methods
|
||||
}
|
Loading…
Reference in a new issue