mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-08 03:22:06 +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::{
|
use crate::{
|
||||||
|
payloads,
|
||||||
requests::{
|
requests::{
|
||||||
AddStickerToSet, AnswerCallbackQuery, AnswerInlineQuery, AnswerPreCheckoutQuery,
|
AddStickerToSet, AnswerCallbackQuery, AnswerInlineQuery, AnswerPreCheckoutQuery,
|
||||||
AnswerShippingQuery, CreateNewStickerSet, DeleteChatPhoto, DeleteChatStickerSet,
|
AnswerShippingQuery, CreateNewStickerSet, DeleteChatPhoto, DeleteChatStickerSet,
|
||||||
|
@ -8,14 +9,15 @@ use crate::{
|
||||||
EditMessageReplyMarkup, EditMessageText, ExportChatInviteLink, ForwardMessage, GetChat,
|
EditMessageReplyMarkup, EditMessageText, ExportChatInviteLink, ForwardMessage, GetChat,
|
||||||
GetChatAdministrators, GetChatMember, GetChatMembersCount, GetFile, GetGameHighScores,
|
GetChatAdministrators, GetChatMember, GetChatMembersCount, GetFile, GetGameHighScores,
|
||||||
GetMe, GetMyCommands, GetStickerSet, GetUpdates, GetUpdatesNonStrict, GetUserProfilePhotos,
|
GetMe, GetMyCommands, GetStickerSet, GetUpdates, GetUpdatesNonStrict, GetUserProfilePhotos,
|
||||||
GetWebhookInfo, KickChatMember, LeaveChat, PinChatMessage, PromoteChatMember,
|
GetWebhookInfo, JsonRequest, KickChatMember, LeaveChat, PinChatMessage, PromoteChatMember,
|
||||||
RestrictChatMember, SendAnimation, SendAudio, SendChatAction, SendChatActionKind,
|
Requester, RestrictChatMember, SendAnimation, SendAudio, SendChatAction,
|
||||||
SendContact, SendDice, SendDocument, SendGame, SendInvoice, SendLocation, SendMediaGroup,
|
SendChatActionKind, SendContact, SendDice, SendDocument, SendGame, SendInvoice,
|
||||||
SendMessage, SendPhoto, SendPoll, SendSticker, SendVenue, SendVideo, SendVideoNote,
|
SendLocation, SendMediaGroup, SendMessage, SendPhoto, SendPoll, SendSticker, SendVenue,
|
||||||
SendVoice, SetChatAdministratorCustomTitle, SetChatDescription, SetChatPermissions,
|
SendVideo, SendVideoNote, SendVoice, SetChatAdministratorCustomTitle, SetChatDescription,
|
||||||
SetChatPhoto, SetChatStickerSet, SetChatTitle, SetGameScore, SetMyCommands,
|
SetChatPermissions, SetChatPhoto, SetChatStickerSet, SetChatTitle, SetGameScore,
|
||||||
SetStickerPositionInSet, SetStickerSetThumb, SetWebhook, StopInlineMessageLiveLocation,
|
SetMyCommands, SetStickerPositionInSet, SetStickerSetThumb, SetWebhook,
|
||||||
StopMessageLiveLocation, StopPoll, UnbanChatMember, UnpinChatMessage, UploadStickerFile,
|
StopInlineMessageLiveLocation, StopMessageLiveLocation, StopPoll, UnbanChatMember,
|
||||||
|
UnpinChatMessage, UploadStickerFile,
|
||||||
},
|
},
|
||||||
types::{
|
types::{
|
||||||
BotCommand, ChatId, ChatPermissions, InlineQueryResult, InputFile, InputMedia,
|
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},
|
errors::{ApiErrorKind, DownloadError, KnownApiErrorKind, RequestError},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub mod payloads;
|
||||||
|
pub mod prelude;
|
||||||
pub mod requests;
|
pub mod requests;
|
||||||
pub mod types;
|
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 all;
|
||||||
mod json;
|
mod json;
|
||||||
mod multipart;
|
mod multipart;
|
||||||
|
mod requester;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
pub use all::*;
|
pub use all::*;
|
||||||
pub use json::JsonRequest;
|
pub use json::JsonRequest;
|
||||||
pub use multipart::MultipartRequest;
|
pub use multipart::MultipartRequest;
|
||||||
|
pub use requester::Requester;
|
||||||
|
|
||||||
/// A type that is returned after making a request to Telegram.
|
/// A type that is returned after making a request to Telegram.
|
||||||
pub type ResponseResult<T> = Result<T, crate::RequestError>;
|
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