From d383c120199dcd97888d9113e3bc26af3fb75fa2 Mon Sep 17 00:00:00 2001 From: Waffle Date: Sat, 21 Sep 2019 01:56:16 +0300 Subject: [PATCH] Add `GetUpdates` method --- src/requests/get_updates.rs | 88 +++++++++++++++++++++++++++++++++++++ src/requests/mod.rs | 1 + 2 files changed, 89 insertions(+) create mode 100644 src/requests/get_updates.rs diff --git a/src/requests/get_updates.rs b/src/requests/get_updates.rs new file mode 100644 index 00000000..2d733662 --- /dev/null +++ b/src/requests/get_updates.rs @@ -0,0 +1,88 @@ +use crate::{ + network, + requests::{Request, RequestContext, RequestFuture, ResponseResult}, + types::Update, +}; + +#[derive(Debug, Clone, Serialize)] +pub struct GetUpdates<'a> { + #[serde(skip_serializing)] + ctx: RequestContext<'a>, + + pub offset: Option, + pub limit: Option, + pub timeout: Option, + pub allowed_updates: Option>, +} + +#[derive(Debug, Serialize, Eq, Hash, PartialEq, Clone, Copy)] +#[serde(rename_all = "snake_case")] +pub enum AllowedUpdate { + Message, + EditedMessage, + ChannelPost, + EditedChannelPost, + InlineQuery, + ChosenInlineResult, + CallbackQuery, +} + +impl<'a> Request<'a> for GetUpdates<'a> { + type ReturnValue = Vec; + + fn send(self) -> RequestFuture<'a, ResponseResult> { + Box::pin(async move { + network::request_json( + &self.ctx.client, + &self.ctx.token, + "getUpdates", + &self, + ) + .await + }) + } +} + +impl<'a> GetUpdates<'a> { + pub(crate) fn new(ctx: RequestContext<'a>) -> Self { + Self { + ctx, + offset: None, + limit: None, + timeout: None, + allowed_updates: None, + } + } + + pub fn offset(mut self, offset: T) -> Self + where + T: Into, + { + self.offset = Some(offset.into()); + self + } + + pub fn limit(mut self, limit: T) -> Self + where + T: Into, + { + self.limit = Some(limit.into()); + self + } + + pub fn timeout(mut self, timeout: T) -> Self + where + T: Into, + { + self.timeout = Some(timeout.into()); + self + } + + pub fn allowed_updates(mut self, allowed_updates: T) -> Self + where + T: Into>, + { + self.allowed_updates = Some(allowed_updates.into()); + self + } +} diff --git a/src/requests/mod.rs b/src/requests/mod.rs index 69750eec..0c793a52 100644 --- a/src/requests/mod.rs +++ b/src/requests/mod.rs @@ -70,6 +70,7 @@ pub mod forward_message; pub mod get_chat; pub mod get_file; pub mod get_me; +pub mod get_updates; pub mod get_user_profile_photos; pub mod kick_chat_member; pub mod restrict_chat_member;