From 546f0d53d9887e0f75c1c98cd2ab00b48b9516e0 Mon Sep 17 00:00:00 2001 From: nextel Date: Fri, 13 Sep 2019 13:05:40 +0300 Subject: [PATCH 1/7] add base struct for sendContact action --- src/core/requests/send_contact.rs | 32 ++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/core/requests/send_contact.rs b/src/core/requests/send_contact.rs index 6ffd1f2a..d17812f6 100644 --- a/src/core/requests/send_contact.rs +++ b/src/core/requests/send_contact.rs @@ -1,7 +1,37 @@ -use crate::core::requests::RequestContext; +use crate::core::requests::{ChatId, RequestContext}; +use crate::core::types::ReplyMarkup; + //TODO:: need implementation #[derive(Debug, Clone, Serialize)] struct SendContact<'a> { #[serde(skip_serializing)] 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, + /// String Yes Contact's phone number + phone_number: String, + /// String Yes Contact's first name + first_name: String, + /// String Optional Contact's last name + #[serde(skip_serializing_if = "Option::is_none")] + last_name: Option, + /// String Optional Additional data about the contact in the form of a + /// vCard, 0-2048 bytes + #[serde(skip_serializing_if = "Option::is_none")] + vcard: 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, + /// 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, + /// 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 keyboard or to force a reply from the user. + #[serde(skip_serializing_if = "Option::is_none")] + reply_markup: Option, } From d81072bba8b15bb8204677fac91b1a9543956307 Mon Sep 17 00:00:00 2001 From: nextel Date: Fri, 13 Sep 2019 13:30:59 +0300 Subject: [PATCH 2/7] add sendContact implementation --- src/core/requests/send_contact.rs | 127 +++++++++++++++++++++++++++--- 1 file changed, 116 insertions(+), 11 deletions(-) diff --git a/src/core/requests/send_contact.rs b/src/core/requests/send_contact.rs index d17812f6..b08d05fb 100644 --- a/src/core/requests/send_contact.rs +++ b/src/core/requests/send_contact.rs @@ -1,37 +1,142 @@ -use crate::core::requests::{ChatId, RequestContext}; -use crate::core::types::ReplyMarkup; +use crate::core::network; +use crate::core::requests::{ChatId, Request, RequestContext, RequestFuture, ResponseResult}; +use crate::core::types::{Message, ReplyMarkup}; -//TODO:: need implementation #[derive(Debug, Clone, Serialize)] struct SendContact<'a> { #[serde(skip_serializing)] 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, /// String Yes Contact's phone number - phone_number: String, + pub phone_number: String, /// String Yes Contact's first name - first_name: String, + pub first_name: String, /// String Optional Contact's last name #[serde(skip_serializing_if = "Option::is_none")] - last_name: Option, + pub last_name: Option, /// String Optional Additional data about the contact in the form of a /// vCard, 0-2048 bytes #[serde(skip_serializing_if = "Option::is_none")] - vcard: Option, + pub vcard: 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 keyboard or to force a reply from the user. #[serde(skip_serializing_if = "Option::is_none")] - reply_markup: Option, + pub reply_markup: Option, +} + + +impl<'a> Request<'a> for SendContact<'a> { + type ReturnValue = Message; + + fn send(self) -> RequestFuture<'a, ResponseResult> { + Box::pin(async move { + network::request_json( + &self.ctx.client, + &self.ctx.token, + "sendContact", + &self, + ) + .await + }) + } +} + + +impl<'a> SendContact<'a> { + pub(crate) fn new( + ctx: RequestContext<'a>, + chat_id: ChatId, + phone_number: String, + first_name: String, + ) -> Self { + Self { + ctx, + chat_id, + phone_number, + first_name, + last_name: None, + vcard: 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 phone_number(mut self, phone_number: T) -> Self + where + T: Into, + { + self.phone_number = phone_number.into(); + self + } + + pub fn first_name(mut self, first_name: T) -> Self + where + T: Into, + { + self.first_name = first_name.into(); + self + } + + pub fn last_name(mut self, last_name: T) -> Self + where + T: Into, + { + self.last_name = Some(last_name.into()); + self + } + + pub fn vcard(mut self, vcard: T) -> Self + where + T: Into, + { + self.vcard = Some(vcard.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 reply_to_message_id(mut self, reply_to_message_id: T) -> Self + where + T: Into, + { + self.reply_to_message_id = Some(reply_to_message_id.into()); + self + } + + + pub fn reply_markup(mut self, reply_markup: T) -> Self + where + T: Into, + { + self.reply_markup = Some(reply_markup.into()); + self + } } From 02f3d60a96c658fcad3de2f3aacddca9dc16b546 Mon Sep 17 00:00:00 2001 From: nextel Date: Fri, 13 Sep 2019 14:00:57 +0300 Subject: [PATCH 3/7] add struct comment --- src/core/requests/send_contact.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/requests/send_contact.rs b/src/core/requests/send_contact.rs index b08d05fb..9a170924 100644 --- a/src/core/requests/send_contact.rs +++ b/src/core/requests/send_contact.rs @@ -2,6 +2,7 @@ use crate::core::network; use crate::core::requests::{ChatId, Request, RequestContext, RequestFuture, ResponseResult}; use crate::core::types::{Message, ReplyMarkup}; +///Use this method to send phone contacts. On success, the sent Message is returned. #[derive(Debug, Clone, Serialize)] struct SendContact<'a> { #[serde(skip_serializing)] From 466ec638a4c45731770ab4e7f87dec2022fad515 Mon Sep 17 00:00:00 2001 From: nextel Date: Fri, 13 Sep 2019 14:02:29 +0300 Subject: [PATCH 4/7] fix documentation --- src/core/requests/send_contact.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/requests/send_contact.rs b/src/core/requests/send_contact.rs index 9a170924..99d997f0 100644 --- a/src/core/requests/send_contact.rs +++ b/src/core/requests/send_contact.rs @@ -7,25 +7,25 @@ use crate::core::types::{Message, ReplyMarkup}; struct SendContact<'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, - /// String Yes Contact's phone number + /// Contact's phone number pub phone_number: String, - /// String Yes Contact's first name + /// Contact's first name pub first_name: String, - /// String Optional Contact's last name + /// Contact's last name #[serde(skip_serializing_if = "Option::is_none")] pub last_name: Option, - /// String Optional Additional data about the contact in the form of a + /// Additional data about the contact in the form of a /// vCard, 0-2048 bytes #[serde(skip_serializing_if = "Option::is_none")] pub vcard: 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 334ee73a40fed5af6f67691a66d73b0dcb1cdad2 Mon Sep 17 00:00:00 2001 From: nextel Date: Fri, 13 Sep 2019 14:03:12 +0300 Subject: [PATCH 5/7] cargo fmt --- src/core/requests/send_contact.rs | 45 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/core/requests/send_contact.rs b/src/core/requests/send_contact.rs index 99d997f0..26cb438c 100644 --- a/src/core/requests/send_contact.rs +++ b/src/core/requests/send_contact.rs @@ -1,8 +1,11 @@ use crate::core::network; -use crate::core::requests::{ChatId, Request, RequestContext, RequestFuture, ResponseResult}; +use crate::core::requests::{ + ChatId, Request, RequestContext, RequestFuture, ResponseResult, +}; use crate::core::types::{Message, ReplyMarkup}; -///Use this method to send phone contacts. On success, the sent Message is returned. +///Use this method to send phone contacts. On success, the sent Message is +/// returned. #[derive(Debug, Clone, Serialize)] struct SendContact<'a> { #[serde(skip_serializing)] @@ -37,7 +40,6 @@ struct SendContact<'a> { pub reply_markup: Option, } - impl<'a> Request<'a> for SendContact<'a> { type ReturnValue = Message; @@ -49,12 +51,11 @@ impl<'a> Request<'a> for SendContact<'a> { "sendContact", &self, ) - .await + .await }) } } - impl<'a> SendContact<'a> { pub(crate) fn new( ctx: RequestContext<'a>, @@ -76,66 +77,64 @@ impl<'a> SendContact<'a> { } pub fn chat_id(mut self, chat_id: T) -> Self - where - T: Into, + where + T: Into, { self.chat_id = chat_id.into(); self } pub fn phone_number(mut self, phone_number: T) -> Self - where - T: Into, + where + T: Into, { self.phone_number = phone_number.into(); self } pub fn first_name(mut self, first_name: T) -> Self - where - T: Into, + where + T: Into, { self.first_name = first_name.into(); self } pub fn last_name(mut self, last_name: T) -> Self - where - T: Into, + where + T: Into, { self.last_name = Some(last_name.into()); self } pub fn vcard(mut self, vcard: T) -> Self - where - T: Into, + where + T: Into, { self.vcard = Some(vcard.into()); self } pub fn disable_notification(mut self, disable_notification: T) -> Self - where - T: Into, + where + T: Into, { self.disable_notification = Some(disable_notification.into()); self } - pub fn reply_to_message_id(mut self, reply_to_message_id: T) -> Self - where - T: Into, + where + T: Into, { self.reply_to_message_id = Some(reply_to_message_id.into()); self } - pub fn reply_markup(mut self, reply_markup: T) -> Self - where - T: Into, + where + T: Into, { self.reply_markup = Some(reply_markup.into()); self From b9364d737bcf0060667c3a8d5404a47a9267e672 Mon Sep 17 00:00:00 2001 From: nextel Date: Fri, 13 Sep 2019 14:07:05 +0300 Subject: [PATCH 6/7] fix docs --- src/core/requests/send_contact.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/requests/send_contact.rs b/src/core/requests/send_contact.rs index 26cb438c..3e1e9eb1 100644 --- a/src/core/requests/send_contact.rs +++ b/src/core/requests/send_contact.rs @@ -10,21 +10,21 @@ use crate::core::types::{Message, ReplyMarkup}; struct SendContact<'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, - /// Contact's phone number + /// Contact's phone number pub phone_number: String, - /// Contact's first name + /// Contact's first name pub first_name: String, - /// Contact's last name + /// Contact's last name #[serde(skip_serializing_if = "Option::is_none")] pub last_name: Option, - /// Additional data about the contact in the form of a + /// Additional data about the contact in the form of a /// vCard, 0-2048 bytes #[serde(skip_serializing_if = "Option::is_none")] pub vcard: Option, - /// 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, @@ -32,7 +32,7 @@ struct SendContact<'a> { /// message #[serde(skip_serializing_if = "Option::is_none")] pub reply_to_message_id: Option, - /// InlineKeyboardMarkup or ReplyKeyboardMarkup or ReplyKeyboardRemove + /// 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 keyboard or to force a reply from the user. From 1932741f1a5abd3c1817e64bff810feb8f092538 Mon Sep 17 00:00:00 2001 From: Mishko torop'izhko Date: Fri, 13 Sep 2019 15:07:54 +0300 Subject: [PATCH 7/7] Update src/core/requests/send_contact.rs Co-Authored-By: Waffle Lapkin --- src/core/requests/send_contact.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/requests/send_contact.rs b/src/core/requests/send_contact.rs index 3e1e9eb1..16cbec0e 100644 --- a/src/core/requests/send_contact.rs +++ b/src/core/requests/send_contact.rs @@ -4,7 +4,7 @@ use crate::core::requests::{ }; use crate::core::types::{Message, ReplyMarkup}; -///Use this method to send phone contacts. On success, the sent Message is +/// Use this method to send phone contacts. /// returned. #[derive(Debug, Clone, Serialize)] struct SendContact<'a> {