From c1568065e0e639f3d668fedf18d8ad29cb98184d Mon Sep 17 00:00:00 2001 From: nextel Date: Thu, 12 Sep 2019 21:31:25 +0300 Subject: [PATCH 1/8] add methods to send venue action --- src/core/requests/send_venue.rs | 130 +++++++++++++++++++++++++++++--- 1 file changed, 119 insertions(+), 11 deletions(-) diff --git a/src/core/requests/send_venue.rs b/src/core/requests/send_venue.rs index deac9b61..4b3010b6 100644 --- a/src/core/requests/send_venue.rs +++ b/src/core/requests/send_venue.rs @@ -1,4 +1,8 @@ -use crate::core::requests::{ChatId, RequestContext}; +use crate::core::network; +use crate::core::requests::{ + ChatId, Request, RequestContext, RequestFuture, ResponseResult, +}; +use crate::core::types::{Message, ReplyMarkup}; //TODO:: need implementation ///Use this method to send information about a venue. On success, the sent @@ -9,35 +13,139 @@ struct SendVenue<'a> { ctx: RequestContext<'a>, /// Integer or String Yes Unique identifier for the target chat or /// username of the target channel (in the format @channelusername) - chat_id: ChatId, + pub chat_id: ChatId, /// Float number Yes Latitude of the venue - latitude: f64, + pub latitude: f64, ///Float number Yes Longitude of the venue - longitude: f64, + pub longitude: f64, /// Yes Name of the venue - title: String, + pub title: String, ///String Yes Address of the venue - address: String, + pub address: String, /// String Optional Foursquare identifier of the venue #[serde(skip_serializing_if = "Option::is_none")] - foursquare_id: Option, + pub foursquare_id: Option, /// String Optional Foursquare type of the venue, if known. (For /// example, “arts_entertainment/default”, “arts_entertainment/aquarium” or /// “food/icecream”.) #[serde(skip_serializing_if = "Option::is_none")] - foursquare_type: Option, + pub foursquare_type: Option, /// Boolean Optional Sends the message silently. Users will receive a /// notification with no sound. #[serde(skip_serializing_if = "Option::is_none")] - disable_notification: Option, + pub disable_notification: Option, /// Integer Optional If the message is a reply, ID of the original /// message #[serde(skip_serializing_if = "Option::is_none")] - reply_to_message_id: Option, + pub reply_to_message_id: Option, /// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove or /// ForceReply Optional Additional interface options. A JSON-serialized /// object for an inline keyboard, custom reply keyboard, instructions to /// remove reply keyboard or to force a reply from the user. #[serde(skip_serializing_if = "Option::is_none")] - reply_markup: Option<()>, //TODO: need concrete type + pub reply_markup: Option, +} + +impl<'a> Request<'a> for SendVenue<'a> { + type ReturnValue = Message; + + fn send(self) -> RequestFuture<'a, ResponseResult> { + Box::pin(async move { + network::request_json( + &self.ctx.client, + &self.ctx.token, + "sendVenue", + Some(&self), + ) + .await + }) + } +} + +impl<'a> SendVenue<'a> { + pub fn new( + ctx: RequestContext<'a>, + chat_id: ChatId, + latitude: f64, + longitude: f64, + title: String, + address: String, + ) -> Self { + Self { + ctx, + chat_id, + latitude, + longitude, + title, + address, + foursquare_id: None, + foursquare_type: None, + disable_notification: None, + reply_to_message_id: None, + reply_markup: None, + } + } + pub fn chat_id(mut self, chat_id: T) -> Self + where + T: Into, + { + self.chat_id = chat_id.into(); + self + } + + pub fn longitude(mut self, longitude: T) -> Self + where + T: Into, + { + self.longitude = longitude.into(); + self + } + + pub fn latitude(mut self, latitude: T) -> Self + where + T: Into, + { + self.latitude = latitude.into(); + self + } + + pub fn title(mut self, title: T) -> Self + where + T: Into, + { + self.title = title.into(); + self + } + + pub fn address(mut self, address: T) -> Self + where + T: Into, + { + self.address = address.into(); + self + } + + pub fn foursquare_id(mut self, foursquare_id: T) -> Self + where + T: Into, + { + self.foursquare_id = Some(foursquare_id.into()); + self + } + + pub fn disable_notification(mut self, disable_notification: T) -> Self + where + T: Into, + { + self.disable_notification = Some(disable_notification.into()); + self + } + + pub fn foursquare_type(mut self, foursquare_type: T) -> Self + where + T: Into, + { + self.foursquare_type = Some(foursquare_type.into()); + self + } } From 8a9b2e1009404f0b94e8555ee2bb0678d496eed2 Mon Sep 17 00:00:00 2001 From: nextel Date: Fri, 13 Sep 2019 12:36:09 +0300 Subject: [PATCH 2/8] add replay markup setter --- src/core/requests/send_venue.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/core/requests/send_venue.rs b/src/core/requests/send_venue.rs index 4b3010b6..fafe4cb0 100644 --- a/src/core/requests/send_venue.rs +++ b/src/core/requests/send_venue.rs @@ -148,4 +148,13 @@ impl<'a> SendVenue<'a> { self.foursquare_type = Some(foursquare_type.into()); self } + + + pub fn reply_markup(mut self, reply_markup: T) -> Self + where + T: Into, + { + self.reply_markup = Some(ReplyMarkup.into()); + self + } } From d2612f21a0fec1b57e35169a96f28fcaa513cf35 Mon Sep 17 00:00:00 2001 From: nextel Date: Fri, 13 Sep 2019 12:38:01 +0300 Subject: [PATCH 3/8] apply cargo fmt --- src/core/requests/send_venue.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/core/requests/send_venue.rs b/src/core/requests/send_venue.rs index fafe4cb0..3c321e73 100644 --- a/src/core/requests/send_venue.rs +++ b/src/core/requests/send_venue.rs @@ -142,17 +142,16 @@ impl<'a> SendVenue<'a> { } pub fn foursquare_type(mut self, foursquare_type: T) -> Self - where - T: Into, + where + T: Into, { self.foursquare_type = Some(foursquare_type.into()); self } - pub fn reply_markup(mut self, reply_markup: T) -> Self - where - T: Into, + where + T: Into, { self.reply_markup = Some(ReplyMarkup.into()); self From 545063764900dc95b91751d26bb8743390fc2ac6 Mon Sep 17 00:00:00 2001 From: nextel Date: Fri, 13 Sep 2019 14:05:10 +0300 Subject: [PATCH 4/8] fix documentation --- src/core/requests/send_venue.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/core/requests/send_venue.rs b/src/core/requests/send_venue.rs index 3c321e73..0d91ff5e 100644 --- a/src/core/requests/send_venue.rs +++ b/src/core/requests/send_venue.rs @@ -4,37 +4,36 @@ use crate::core::requests::{ }; use crate::core::types::{Message, ReplyMarkup}; -//TODO:: need implementation ///Use this method to send information about a venue. On success, the sent /// Message is returned. #[derive(Debug, Clone, Serialize)] struct SendVenue<'a> { #[serde(skip_serializing)] ctx: RequestContext<'a>, - /// Integer or String Yes Unique identifier for the target chat or + ///Unique identifier for the target chat or /// username of the target channel (in the format @channelusername) pub chat_id: ChatId, - /// Float number Yes Latitude of the venue + /// Yes Latitude of the venue pub latitude: f64, - ///Float number Yes Longitude of the venue + /// Longitude of the venue pub longitude: f64, - /// Yes Name of the venue + /// Name of the venue pub title: String, - ///String Yes Address of the venue + /// Address of the venue pub address: String, - /// String Optional Foursquare identifier of the venue + /// Foursquare identifier of the venue #[serde(skip_serializing_if = "Option::is_none")] pub foursquare_id: Option, - /// String Optional Foursquare type of the venue, if known. (For + /// Foursquare type of the venue, if known. (For /// example, “arts_entertainment/default”, “arts_entertainment/aquarium” or /// “food/icecream”.) #[serde(skip_serializing_if = "Option::is_none")] pub foursquare_type: Option, - /// Boolean Optional Sends the message silently. Users will receive a + /// Sends the message silently. Users will receive a /// notification with no sound. #[serde(skip_serializing_if = "Option::is_none")] pub disable_notification: Option, - /// Integer Optional If the message is a reply, ID of the original + /// If the message is a reply, ID of the original /// message #[serde(skip_serializing_if = "Option::is_none")] pub reply_to_message_id: Option, From c1e78c19cf63afdfa4382ba998aae07b78c3860c Mon Sep 17 00:00:00 2001 From: nextel Date: Fri, 13 Sep 2019 14:05:32 +0300 Subject: [PATCH 5/8] fix documentation --- src/core/requests/send_venue.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/requests/send_venue.rs b/src/core/requests/send_venue.rs index 0d91ff5e..4422b45f 100644 --- a/src/core/requests/send_venue.rs +++ b/src/core/requests/send_venue.rs @@ -10,10 +10,10 @@ use crate::core::types::{Message, ReplyMarkup}; struct SendVenue<'a> { #[serde(skip_serializing)] ctx: RequestContext<'a>, - ///Unique identifier for the target chat or + /// Unique identifier for the target chat or /// username of the target channel (in the format @channelusername) pub chat_id: ChatId, - /// Yes Latitude of the venue + /// Latitude of the venue pub latitude: f64, /// Longitude of the venue pub longitude: f64, From 45f7e49e3b3924a29dc9ed6b7acbaa109a15c085 Mon Sep 17 00:00:00 2001 From: Mishko torop'izhko Date: Fri, 13 Sep 2019 15:08:29 +0300 Subject: [PATCH 6/8] Update src/core/requests/send_venue.rs Co-Authored-By: Waffle Lapkin --- src/core/requests/send_venue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/requests/send_venue.rs b/src/core/requests/send_venue.rs index 4422b45f..eff1819b 100644 --- a/src/core/requests/send_venue.rs +++ b/src/core/requests/send_venue.rs @@ -15,7 +15,7 @@ struct SendVenue<'a> { pub chat_id: ChatId, /// Latitude of the venue pub latitude: f64, - /// Longitude of the venue + /// Longitude of the venue pub longitude: f64, /// Name of the venue pub title: String, From 766be3381d86d12339aae35369d8565700dfcc36 Mon Sep 17 00:00:00 2001 From: Mishko torop'izhko Date: Fri, 13 Sep 2019 15:08:40 +0300 Subject: [PATCH 7/8] Update src/core/requests/send_venue.rs Co-Authored-By: Waffle Lapkin --- src/core/requests/send_venue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/requests/send_venue.rs b/src/core/requests/send_venue.rs index eff1819b..424a33e7 100644 --- a/src/core/requests/send_venue.rs +++ b/src/core/requests/send_venue.rs @@ -4,7 +4,7 @@ use crate::core::requests::{ }; use crate::core::types::{Message, ReplyMarkup}; -///Use this method to send information about a venue. On success, the sent +/// Use this method to send information about a venue. /// Message is returned. #[derive(Debug, Clone, Serialize)] struct SendVenue<'a> { From 1f4ec47f3933e70e4b0e8dbbc33c0244ebf59700 Mon Sep 17 00:00:00 2001 From: Mishko torop'izhko Date: Fri, 13 Sep 2019 15:08:50 +0300 Subject: [PATCH 8/8] Update src/core/requests/send_venue.rs Co-Authored-By: Waffle Lapkin --- src/core/requests/send_venue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/requests/send_venue.rs b/src/core/requests/send_venue.rs index 424a33e7..efdaccf0 100644 --- a/src/core/requests/send_venue.rs +++ b/src/core/requests/send_venue.rs @@ -19,7 +19,7 @@ struct SendVenue<'a> { pub longitude: f64, /// Name of the venue pub title: String, - /// Address of the venue + /// Address of the venue pub address: String, /// Foursquare identifier of the venue #[serde(skip_serializing_if = "Option::is_none")]