diff --git a/src/core/requests/answer_shipping_query.rs b/src/core/requests/answer_shipping_query.rs new file mode 100644 index 00000000..09bffe78 --- /dev/null +++ b/src/core/requests/answer_shipping_query.rs @@ -0,0 +1,90 @@ +use crate::core::types::ShippingOption; +use crate::core::requests::{RequestContext, Request, RequestFuture, ResponseResult}; +use crate::core::network; + +#[derive(Debug, Clone, Serialize)] +/// If you sent an invoice requesting a shipping address and the parameter +/// is_flexible was specified, the Bot API will send an [`Update`] with a +/// shipping_query field to the bot. Use this method to reply to shipping +/// queries. On success, True is returned. +pub struct AnswerShippingQuery<'a> { + ctx: RequestContext<'a>, + + /// Unique identifier for the query to be answered + pub shipping_query_id: String, + /// Specify True if delivery to the specified address is possible and False + /// if there are any problems (for example, if delivery to the specified + /// address is not possible) + pub ok: bool, + + #[serde(skip_serializing_if = "Option::is_none")] + /// Required if ok is True. A JSON-serialized array of available shipping + /// options. + pub shipping_options: Option>, + + #[serde(skip_serializing_if = "Option::is_none")] + /// Required if ok is False. Error message in human readable form that + /// explains why it is impossible to complete the order (e.g. "Sorry, + /// delivery to your desired address is unavailable'). Telegram will + /// display this message to the user. + pub error_message: Option, +} + +impl<'a> Request<'a> for AnswerShippingQuery<'a> { + type ReturnValue = bool; + + fn send(self) -> RequestFuture<'a, ResponseResult> { + Box::pin(async move { + network::request_json( + &self.ctx.client, + &self.ctx.token, + "answerShippingQuery", + &self + ) + }) + } +} + +impl<'a> AnswerShippingQuery<'a> { + pub(crate) fn new( + ctx: RequestContext<'a>, + shipping_query_id: String, + ok: bool + ) -> Self { + Self { + ctx, + shipping_query_id, + ok, + shipping_options: None, + error_message: None + } + } + + pub fn shipping_query_id(mut self, shipping_query_id: T) -> Self + where T: Into + { + self.shipping_query_id = shipping_query_id.into(); + self + } + + pub fn ok(mut self, ok: T) -> Self + where T: Into + { + self.ok = ok.into(); + self + } + + pub fn shipping_options(mut self, shipping_options: T) -> Self + where T: Into> + { + self.shipping_options = shipping_options; + self + } + + pub fn error_message(mut self, error_message: T) -> Self + where T: Into + { + self.error_message = Some(error_message.into()); + self + } +} diff --git a/src/core/requests/mod.rs b/src/core/requests/mod.rs index bb7c4310..a1dfa82f 100644 --- a/src/core/requests/mod.rs +++ b/src/core/requests/mod.rs @@ -90,6 +90,7 @@ mod tests { } pub mod answer_pre_checkout_query; +pub mod answer_shipping_query; pub mod edit_message_live_location; pub mod forward_message; pub mod get_file; diff --git a/src/core/types/answer_shipping_query.rs b/src/core/types/answer_shipping_query.rs deleted file mode 100644 index c04c016b..00000000 --- a/src/core/types/answer_shipping_query.rs +++ /dev/null @@ -1,11 +0,0 @@ -use crate::core::types::ShippingOption; - -#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)] -pub struct AnswerShippingQuery { - pub shipping_query_id: String, - pub ok: bool, - #[serde(skip_serializing_if = "Option::is_none")] - pub shipping_options: Option>, - #[serde(skip_serializing_if = "Option::is_none")] - pub error_message: Option, -} diff --git a/src/core/types/mod.rs b/src/core/types/mod.rs index bd76f782..3c1cca89 100644 --- a/src/core/types/mod.rs +++ b/src/core/types/mod.rs @@ -1,6 +1,5 @@ use self::not_implemented_types::*; pub use self::{ - answer_shipping_query::AnswerShippingQuery, animation::Animation, audio::Audio, callback_query::CallbackQuery, @@ -50,7 +49,6 @@ pub use self::{ }; mod animation; -mod answer_shipping_query; mod audio; mod callback_query; mod chat;