Run cargo fmt

This commit is contained in:
Waffle 2019-09-19 01:30:30 +03:00
parent 2b1ce74d94
commit fda1d37e77
52 changed files with 303 additions and 297 deletions

View file

@ -1,24 +1,15 @@
use reqwest::r#async::Client; use reqwest::r#async::Client;
use crate::core::{ use crate::core::{
types::{
InputFile,
InputMedia,
},
requests::{ requests::{
ChatId,
RequestContext,
get_me::GetMe,
send_message::SendMessage,
edit_message_live_location::EditMessageLiveLocation, edit_message_live_location::EditMessageLiveLocation,
forward_message::ForwardMessage, forward_message::ForwardMessage, get_me::GetMe, send_audio::SendAudio,
send_audio::SendAudio, send_location::SendLocation, send_media_group::SendMediaGroup,
send_location::SendLocation, send_message::SendMessage, send_photo::SendPhoto,
send_media_group::SendMediaGroup, stop_message_live_location::StopMessageLiveLocation, ChatId,
send_photo::SendPhoto, RequestContext,
stop_message_live_location::StopMessageLiveLocation, },
} types::{InputFile, InputMedia},
}; };
pub struct Bot { pub struct Bot {
@ -60,11 +51,7 @@ impl Bot {
C: Into<ChatId>, C: Into<ChatId>,
T: Into<String>, T: Into<String>,
{ {
SendMessage::new( SendMessage::new(self.ctx(), chat_id.into(), text.into())
self.ctx(),
chat_id.into(),
text.into(),
)
} }
pub fn edit_message_live_location<Lt, Lg>( pub fn edit_message_live_location<Lt, Lg>(
@ -87,7 +74,7 @@ impl Bot {
&self, &self,
chat_id: C, chat_id: C,
from_chat_id: F, from_chat_id: F,
message_id: M message_id: M,
) -> ForwardMessage ) -> ForwardMessage
where where
C: Into<ChatId>, C: Into<ChatId>,
@ -107,11 +94,7 @@ impl Bot {
C: Into<ChatId>, C: Into<ChatId>,
A: Into<InputFile>, A: Into<InputFile>,
{ {
SendAudio::new( SendAudio::new(self.ctx(), chat_id.into(), audio.into())
self.ctx(),
chat_id.into(),
audio.into()
)
} }
pub fn send_location<C, Lt, Lg>( pub fn send_location<C, Lt, Lg>(
@ -136,30 +119,20 @@ impl Bot {
pub fn send_media_group<C, M>(&self, chat_id: C, media: M) -> SendMediaGroup pub fn send_media_group<C, M>(&self, chat_id: C, media: M) -> SendMediaGroup
where where
C: Into<ChatId>, C: Into<ChatId>,
M: Into<Vec<InputMedia>> M: Into<Vec<InputMedia>>,
{ {
SendMediaGroup::new( SendMediaGroup::new(self.ctx(), chat_id.into(), media.into())
self.ctx(),
chat_id.into(),
media.into(),
)
} }
pub fn send_photo<C, P>(&self, chat_id: C, photo: P) -> SendPhoto pub fn send_photo<C, P>(&self, chat_id: C, photo: P) -> SendPhoto
where where
C: Into<ChatId>, C: Into<ChatId>,
P: Into<InputFile> P: Into<InputFile>,
{ {
SendPhoto::new( SendPhoto::new(self.ctx(), chat_id.into(), photo.into())
self.ctx(),
chat_id.into(),
photo.into(),
)
} }
pub fn stop_message_live_location(&self) -> StopMessageLiveLocation { pub fn stop_message_live_location(&self) -> StopMessageLiveLocation {
StopMessageLiveLocation::new( StopMessageLiveLocation::new(self.ctx())
self.ctx()
)
} }
} }

View file

@ -1,6 +1,6 @@
use crate::core::{ use crate::core::{
requests::{RequestContext, Request, RequestFuture, ResponseResult}, network,
network requests::{Request, RequestContext, RequestFuture, ResponseResult},
}; };
#[derive(Debug, Serialize, Clone)] #[derive(Debug, Serialize, Clone)]
@ -40,8 +40,9 @@ impl<'a> Request<'a> for AnswerPreCheckoutQuery<'a> {
&self.ctx.client, &self.ctx.client,
&self.ctx.token, &self.ctx.token,
"answerPreCheckoutQuery", "answerPreCheckoutQuery",
&self &self,
).await )
.await
}) })
} }
} }
@ -50,32 +51,35 @@ impl<'a> AnswerPreCheckoutQuery<'a> {
pub(crate) fn new( pub(crate) fn new(
ctx: RequestContext<'a>, ctx: RequestContext<'a>,
pre_checkout_query_id: String, pre_checkout_query_id: String,
ok: bool ok: bool,
) -> Self { ) -> Self {
Self { Self {
ctx, ctx,
pre_checkout_query_id, pre_checkout_query_id,
ok, ok,
error_message: None error_message: None,
} }
} }
pub fn pre_checkout_query_id<T>(mut self, pre_checkout_query_id: T) -> Self pub fn pre_checkout_query_id<T>(mut self, pre_checkout_query_id: T) -> Self
where T: Into<String> where
T: Into<String>,
{ {
self.pre_checkout_query_id = pre_checkout_query_id.into(); self.pre_checkout_query_id = pre_checkout_query_id.into();
self self
} }
pub fn ok<T>(mut self, ok: T) -> Self pub fn ok<T>(mut self, ok: T) -> Self
where T: Into<bool> where
T: Into<bool>,
{ {
self.ok = ok.into(); self.ok = ok.into();
self self
} }
pub fn error_message<T>(mut self, error_message: T) -> Self pub fn error_message<T>(mut self, error_message: T) -> Self
where T: Into<String> where
T: Into<String>,
{ {
self.error_message = Some(error_message.into()); self.error_message = Some(error_message.into());
self self

View file

@ -1,6 +1,8 @@
use crate::core::types::ShippingOption;
use crate::core::requests::{RequestContext, Request, RequestFuture, ResponseResult};
use crate::core::network; use crate::core::network;
use crate::core::requests::{
Request, RequestContext, RequestFuture, ResponseResult,
};
use crate::core::types::ShippingOption;
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
/// If you sent an invoice requesting a shipping address and the parameter /// If you sent an invoice requesting a shipping address and the parameter
@ -40,8 +42,9 @@ impl<'a> Request<'a> for AnswerShippingQuery<'a> {
&self.ctx.client, &self.ctx.client,
&self.ctx.token, &self.ctx.token,
"answerShippingQuery", "answerShippingQuery",
&self &self,
).await )
.await
}) })
} }
} }
@ -50,40 +53,44 @@ impl<'a> AnswerShippingQuery<'a> {
pub(crate) fn new( pub(crate) fn new(
ctx: RequestContext<'a>, ctx: RequestContext<'a>,
shipping_query_id: String, shipping_query_id: String,
ok: bool ok: bool,
) -> Self { ) -> Self {
Self { Self {
ctx, ctx,
shipping_query_id, shipping_query_id,
ok, ok,
shipping_options: None, shipping_options: None,
error_message: None error_message: None,
} }
} }
pub fn shipping_query_id<T>(mut self, shipping_query_id: T) -> Self pub fn shipping_query_id<T>(mut self, shipping_query_id: T) -> Self
where T: Into<String> where
T: Into<String>,
{ {
self.shipping_query_id = shipping_query_id.into(); self.shipping_query_id = shipping_query_id.into();
self self
} }
pub fn ok<T>(mut self, ok: T) -> Self pub fn ok<T>(mut self, ok: T) -> Self
where T: Into<bool> where
T: Into<bool>,
{ {
self.ok = ok.into(); self.ok = ok.into();
self self
} }
pub fn shipping_options<T>(mut self, shipping_options: T) -> Self pub fn shipping_options<T>(mut self, shipping_options: T) -> Self
where T: Into<Vec<ShippingOption>> where
T: Into<Vec<ShippingOption>>,
{ {
self.shipping_options = Some(shipping_options.into()); self.shipping_options = Some(shipping_options.into());
self self
} }
pub fn error_message<T>(mut self, error_message: T) -> Self pub fn error_message<T>(mut self, error_message: T) -> Self
where T: Into<String> where
T: Into<String>,
{ {
self.error_message = Some(error_message.into()); self.error_message = Some(error_message.into());
self self

View file

@ -1,11 +1,7 @@
use crate::core::{ use crate::core::{
network, network,
requests::{ requests::{
ChatId, ChatId, Request, RequestContext, RequestFuture, ResponseResult,
Request,
RequestFuture,
RequestContext,
ResponseResult,
}, },
types::Message, types::Message,
}; };

View file

@ -1,9 +1,11 @@
use crate::core::requests::{RequestContext, RequestFuture, ResponseResult, Request};
use crate::core::types::File;
use crate::core::network; use crate::core::network;
use crate::core::requests::{
Request, RequestContext, RequestFuture, ResponseResult,
};
use crate::core::types::File;
/// Use this method to get basic info about a file and prepare it for downloading. /// Use this method to get basic info about a file and prepare it for
/// For the moment, bots can download files of up to 20MB in size. /// downloading. For the moment, bots can download files of up to 20MB in size.
/// On success, a File object is returned. /// On success, a File object is returned.
/// The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, /// The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>,
/// where <file_path> is taken from the response. /// where <file_path> is taken from the response.
@ -14,10 +16,9 @@ struct GetFile<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
ctx: RequestContext<'a>, ctx: RequestContext<'a>,
/// File identifier to get info about /// File identifier to get info about
file_id: String file_id: String,
} }
impl<'a> Request<'a> for GetFile<'a> { impl<'a> Request<'a> for GetFile<'a> {
type ReturnValue = File; type ReturnValue = File;
@ -29,16 +30,15 @@ impl<'a> Request<'a> for GetFile<'a> {
"getFile", "getFile",
&self, &self,
) )
.await .await
}) })
} }
} }
impl<'a> GetFile<'a> {
impl<'a> GetFile<'a>{
pub fn file_id<T>(mut self, file_id: T) -> Self pub fn file_id<T>(mut self, file_id: T) -> Self
where where
T: Into<String>, T: Into<String>,
{ {
self.file_id = file_id.into(); self.file_id = file_id.into();
self self

View file

@ -1,9 +1,12 @@
use crate::core::network; use crate::core::network;
use crate::core::requests::{ChatId, Request, RequestContext, RequestFuture, ResponseResult}; use crate::core::requests::{
ChatId, Request, RequestContext, RequestFuture, ResponseResult,
};
///Use this method when you need to tell the user that something is happening on the bot's side. ///Use this method when you need to tell the user that something is happening
///The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). /// on the bot's side. The status is set for 5 seconds or less (when a message
///Returns True on success. /// arrives from your bot, Telegram clients clear its typing status).
/// Returns True on success.
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
struct SendChatAction<'a> { struct SendChatAction<'a> {
#[serde(skip_serializing)] #[serde(skip_serializing)]
@ -45,7 +48,7 @@ impl<'a> Request<'a> for SendChatAction<'a> {
"sendChatAction", "sendChatAction",
&self, &self,
) )
.await .await
}) })
} }
} }
@ -64,19 +67,18 @@ impl<'a> SendChatAction<'a> {
} }
pub fn chat_id<T>(mut self, chat_id: T) -> Self pub fn chat_id<T>(mut self, chat_id: T) -> Self
where where
T: Into<ChatId>, T: Into<ChatId>,
{ {
self.chat_id = chat_id.into(); self.chat_id = chat_id.into();
self self
} }
pub fn action<T>(mut self, action: T) -> Self pub fn action<T>(mut self, action: T) -> Self
where where
T: Into<ChatAction>, T: Into<ChatAction>,
{ {
self.action = action.into(); self.action = action.into();
self self
} }
} }

View file

@ -1,11 +1,7 @@
use crate::core::{ use crate::core::{
network, network,
requests::{ requests::{
ChatId, ChatId, Request, RequestContext, RequestFuture, ResponseResult,
Request,
RequestFuture,
RequestContext,
ResponseResult,
}, },
types::{Message, ParseMode, ReplyMarkup}, types::{Message, ParseMode, ReplyMarkup},
}; };

View file

@ -1,11 +1,7 @@
use crate::core::{ use crate::core::{
network, network,
requests::{ requests::{
ChatId, ChatId, Request, RequestContext, RequestFuture, ResponseResult,
Request,
RequestFuture,
RequestContext,
ResponseResult,
}, },
types::{InlineKeyboardMarkup, Message}, types::{InlineKeyboardMarkup, Message},
}; };

View file

@ -2,11 +2,7 @@ use std::path::PathBuf;
use bytes::{Bytes, BytesMut}; use bytes::{Bytes, BytesMut};
use reqwest::r#async::multipart::Part; use reqwest::r#async::multipart::Part;
use tokio::{ use tokio::{codec::FramedRead, prelude::*};
prelude::*,
codec::FramedRead,
};
struct FileDecoder; struct FileDecoder;

View file

@ -19,7 +19,7 @@ pub struct Animation {
/// Optional. MIME type of the file as defined by sender /// Optional. MIME type of the file as defined by sender
pub mime_type: Option<String>, pub mime_type: Option<String>,
/// Optional. File size /// Optional. File size
pub file_size: Option<u32> pub file_size: Option<u32>,
} }
#[cfg(test)] #[cfg(test)]
@ -51,11 +51,11 @@ mod tests {
file_id: "id".to_string(), file_id: "id".to_string(),
width: 320, width: 320,
height: 320, height: 320,
file_size: Some(3452) file_size: Some(3452),
}), }),
file_name: Some("some".to_string()), file_name: Some("some".to_string()),
mime_type: Some("gif".to_string()), mime_type: Some("gif".to_string()),
file_size: Some(6500) file_size: Some(6500),
}; };
let actual = serde_json::from_str::<Animation>(json).unwrap(); let actual = serde_json::from_str::<Animation>(json).unwrap();
assert_eq!(actual, expected) assert_eq!(actual, expected)

View file

@ -1,6 +1,7 @@
use crate::core::types::{User, Message}; use crate::core::types::{Message, User};
/// This object represents an incoming callback query from a callback button in an inline keyboard. /// This object represents an incoming callback query from a callback button in
/// an inline keyboard.
#[derive(Debug, Deserialize, PartialEq, Clone)] #[derive(Debug, Deserialize, PartialEq, Clone)]
pub struct CallbackQuery { pub struct CallbackQuery {
/// Unique identifier for this query /// Unique identifier for this query
@ -8,12 +9,14 @@ pub struct CallbackQuery {
/// Sender /// Sender
pub from: User, pub from: User,
/// Message with the callback button that originated the query. /// Message with the callback button that originated the query.
/// Note that message content and message date will not be available if the message is too old /// Note that message content and message date will not be available if the
/// message is too old
pub message: Message, pub message: Message,
/// Global identifier, uniquely corresponding to the chat to which the message /// Global identifier, uniquely corresponding to the chat to which the
/// with the callback button was sent. Useful for high scores in games. /// message with the callback button was sent. Useful for high scores
/// in games.
pub chat_instance: String, pub chat_instance: String,
/// Data associated with the callback button. Be aware that a bad client can /// Data associated with the callback button. Be aware that a bad client
/// send arbitrary data in this field. /// can send arbitrary data in this field.
pub data: String, pub data: String,
} }

View file

@ -1,6 +1,5 @@
use crate::core::types::{ChatPermissions, ChatPhoto, Message}; use crate::core::types::{ChatPermissions, ChatPhoto, Message};
#[derive(Debug, Deserialize, PartialEq, Clone)] #[derive(Debug, Deserialize, PartialEq, Clone)]
pub struct Chat { pub struct Chat {
pub id: i64, pub id: i64,
@ -9,7 +8,6 @@ pub struct Chat {
pub photo: Option<ChatPhoto>, pub photo: Option<ChatPhoto>,
} }
#[derive(Debug, Deserialize, PartialEq, Clone)] #[derive(Debug, Deserialize, PartialEq, Clone)]
#[serde(untagged)] #[serde(untagged)]
pub enum ChatKind { pub enum ChatKind {

View file

@ -1,4 +1,4 @@
use crate::core::types::{User, Location}; use crate::core::types::{Location, User};
#[derive(Debug, Deserialize, Clone, PartialEq)] #[derive(Debug, Deserialize, Clone, PartialEq)]
/// Represents a result of an inline query that was chosen by the user and /// Represents a result of an inline query that was chosen by the user and
@ -11,9 +11,9 @@ pub struct ChosenInlineResult {
pub from: User, pub from: User,
/// Optional. Sender location, only for bots that require user location /// Optional. Sender location, only for bots that require user location
pub location: Option<Location>, pub location: Option<Location>,
/// Optional. Identifier of the sent inline message. Available only if there is an inline /// Optional. Identifier of the sent inline message. Available only if
/// keyboard attached to the message. Will be also received in callback queries and can /// there is an inline keyboard attached to the message. Will be also
/// be used to edit the message. /// received in callback queries and can be used to edit the message.
pub inline_message_id: Option<String>, pub inline_message_id: Option<String>,
/// The query that was used to obtain the result /// The query that was used to obtain the result
pub query: String, pub query: String,

View file

@ -12,4 +12,4 @@ pub struct Contact {
/// Optional. Additional data about the contact in the form of a /// Optional. Additional data about the contact in the form of a
/// [vCard](https://en.wikipedia.org/wiki/VCard) /// [vCard](https://en.wikipedia.org/wiki/VCard)
pub vcard: Option<String>, pub vcard: Option<String>,
} }

View file

@ -2,5 +2,5 @@
pub struct File { pub struct File {
pub file_id: String, pub file_id: String,
pub file_size: u32, pub file_size: u32,
pub file_path: String pub file_path: String,
} }

View file

@ -1,10 +1,10 @@
use serde::Deserialize; use serde::Deserialize;
use crate::core::types::{MessageEntity, PhotoSize, Animation}; use crate::core::types::{Animation, MessageEntity, PhotoSize};
#[derive(Debug, Deserialize, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Deserialize, Clone, PartialEq, Eq, Hash)]
/// This object represents a game. Use BotFather to create and edit games, their short names /// This object represents a game. Use BotFather to create and edit games, their
/// will act as unique identifiers. /// short names will act as unique identifiers.
pub struct Game { pub struct Game {
/// Title of the game /// Title of the game
pub title: String, pub title: String,
@ -12,13 +12,15 @@ pub struct Game {
pub description: String, pub description: String,
/// Photo that will be displayed in the game message in chats. /// Photo that will be displayed in the game message in chats.
pub photo: Vec<PhotoSize>, pub photo: Vec<PhotoSize>,
/// Optional. Brief description of the game or high scores included in the game message. /// Optional. Brief description of the game or high scores included in the
/// Can be automatically edited to include current high scores for the game when /// game message. Can be automatically edited to include current high
/// the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters. /// scores for the game when the bot calls setGameScore, or manually
/// edited using editMessageText. 0-4096 characters.
pub text: Option<String>, pub text: Option<String>,
/// Optional. Special entities that appear in text, such as usernames, URLs, bot commands, etc. /// Optional. Special entities that appear in text, such as usernames,
/// URLs, bot commands, etc.
pub text_entities: Option<Vec<MessageEntity>>, pub text_entities: Option<Vec<MessageEntity>>,
/// Optional. Animation that will be displayed in the game message in chats. /// Optional. Animation that will be displayed in the game message in
/// Upload via BotFather /// chats. Upload via BotFather
pub animation: Option<Animation>, pub animation: Option<Animation>,
} }

View file

@ -62,32 +62,37 @@ impl InlineKeyboardButton {
} }
} }
pub fn callback(text: String, callback_data: String) pub fn callback(
-> InlineKeyboardButton { text: String,
callback_data: String,
) -> InlineKeyboardButton {
InlineKeyboardButton { InlineKeyboardButton {
text, text,
kind: InlineKeyboardButtonKind::CallbackData(callback_data), kind: InlineKeyboardButtonKind::CallbackData(callback_data),
} }
} }
pub fn switch_inline_query(text: String, switch_inline_query: String) pub fn switch_inline_query(
-> InlineKeyboardButton { text: String,
switch_inline_query: String,
) -> InlineKeyboardButton {
InlineKeyboardButton { InlineKeyboardButton {
text, text,
kind: InlineKeyboardButtonKind::SwitchInlineQuery(switch_inline_query) kind: InlineKeyboardButtonKind::SwitchInlineQuery(
switch_inline_query,
),
} }
} }
pub fn switch_inline_query_current_chat( pub fn switch_inline_query_current_chat(
text: String, text: String,
switch_inline_query_current_chat: String switch_inline_query_current_chat: String,
) -> InlineKeyboardButton { ) -> InlineKeyboardButton {
InlineKeyboardButton { InlineKeyboardButton {
text, text,
kind: InlineKeyboardButtonKind::SwitchInlineQueryCurrentChat( kind: InlineKeyboardButtonKind::SwitchInlineQueryCurrentChat(
switch_inline_query_current_chat switch_inline_query_current_chat,
) ),
} }
} }
} }

View file

@ -17,22 +17,19 @@ pub struct InlineKeyboardMarkup {
/// Example: /// Example:
/// ``` /// ```
/// use async_telegram_bot::core::types::{ /// use async_telegram_bot::core::types::{
/// InlineKeyboardMarkup, /// InlineKeyboardButton, InlineKeyboardMarkup,
/// InlineKeyboardButton
/// }; /// };
/// ///
///
/// let url_button = InlineKeyboardButton::url( /// let url_button = InlineKeyboardButton::url(
/// "text".to_string(), /// "text".to_string(),
/// "http://url.com".to_string() /// "http://url.com".to_string(),
/// ); /// );
/// let keyboard = InlineKeyboardMarkup::new() /// let keyboard = InlineKeyboardMarkup::new().append_row(vec![url_button]);
/// .append_row(vec![url_button]);
/// ``` /// ```
impl InlineKeyboardMarkup { impl InlineKeyboardMarkup {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
inline_keyboard: vec![] inline_keyboard: vec![],
} }
} }
@ -41,11 +38,14 @@ impl InlineKeyboardMarkup {
self self
} }
pub fn append_to_row(mut self, button: InlineKeyboardButton, index: usize) pub fn append_to_row(
-> Self { mut self,
button: InlineKeyboardButton,
index: usize,
) -> Self {
match self.inline_keyboard.get_mut(index) { match self.inline_keyboard.get_mut(index) {
Some(buttons) => buttons.push(button), Some(buttons) => buttons.push(button),
None => self.inline_keyboard.push(vec![button]) None => self.inline_keyboard.push(vec![button]),
}; };
self self
} }
@ -68,9 +68,7 @@ mod tests {
let markup = InlineKeyboardMarkup::new() let markup = InlineKeyboardMarkup::new()
.append_row(vec![button1.clone(), button2.clone()]); .append_row(vec![button1.clone(), button2.clone()]);
let expected = InlineKeyboardMarkup { let expected = InlineKeyboardMarkup {
inline_keyboard: vec![ inline_keyboard: vec![vec![button1.clone(), button2.clone()]],
vec![button1.clone(), button2.clone()]
]
}; };
assert_eq!(markup, expected); assert_eq!(markup, expected);
} }
@ -89,9 +87,7 @@ mod tests {
.append_row(vec![button1.clone()]) .append_row(vec![button1.clone()])
.append_to_row(button2.clone(), 0); .append_to_row(button2.clone(), 0);
let expected = InlineKeyboardMarkup { let expected = InlineKeyboardMarkup {
inline_keyboard: vec![ inline_keyboard: vec![vec![button1.clone(), button2.clone()]],
vec![button1.clone(), button2.clone()]
]
}; };
assert_eq!(markup, expected); assert_eq!(markup, expected);
} }
@ -110,10 +106,7 @@ mod tests {
.append_row(vec![button1.clone()]) .append_row(vec![button1.clone()])
.append_to_row(button2.clone(), 1); .append_to_row(button2.clone(), 1);
let expected = InlineKeyboardMarkup { let expected = InlineKeyboardMarkup {
inline_keyboard: vec![ inline_keyboard: vec![vec![button1.clone()], vec![button2.clone()]],
vec![button1.clone()],
vec![button2.clone()]
]
}; };
assert_eq!(markup, expected); assert_eq!(markup, expected);
} }

View file

@ -1,4 +1,4 @@
use crate::core::types::{User, Location}; use crate::core::types::{Location, User};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQuery { pub struct InlineQuery {

View file

@ -1,26 +1,16 @@
use crate::core::types::{ use crate::core::types::{
InlineQueryResultCachedAudio, InlineQueryResultArticle, InlineQueryResultAudio,
InlineQueryResultCachedDocument, InlineQueryResultCachedAudio, InlineQueryResultCachedDocument,
InlineQueryResultCachedGif, InlineQueryResultCachedGif, InlineQueryResultCachedMpeg4Gif,
InlineQueryResultCachedMpeg4Gif, InlineQueryResultCachedPhoto, InlineQueryResultCachedSticker,
InlineQueryResultCachedPhoto, InlineQueryResultCachedVideo, InlineQueryResultCachedVoice,
InlineQueryResultCachedSticker, InlineQueryResultContact, InlineQueryResultDocument, InlineQueryResultGame,
InlineQueryResultCachedVideo, InlineQueryResultGif, InlineQueryResultLocation, InlineQueryResultMpeg4Gif,
InlineQueryResultCachedVoice, InlineQueryResultPhoto, InlineQueryResultVenue, InlineQueryResultVideo,
InlineQueryResultArticle, InlineQueryResultVoice,
InlineQueryResultAudio,
InlineQueryResultContact,
InlineQueryResultGame,
InlineQueryResultDocument,
InlineQueryResultGif,
InlineQueryResultLocation,
InlineQueryResultMpeg4Gif,
InlineQueryResultPhoto,
InlineQueryResultVenue,
InlineQueryResultVideo,
InlineQueryResultVoice
}; };
/// This object represents one result of an inline query.
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
#[serde(tag = "type")] #[serde(tag = "type")]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
@ -59,24 +49,26 @@ pub enum InlineQueryResult {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crate::core::types::{InlineQueryResult, InlineQueryResultCachedAudio, InputMessageContent};
use crate::core::types::parse_mode::ParseMode;
use crate::core::types::inline_keyboard_markup::InlineKeyboardMarkup; use crate::core::types::inline_keyboard_markup::InlineKeyboardMarkup;
use crate::core::types::parse_mode::ParseMode;
use crate::core::types::{
InlineQueryResult, InlineQueryResultCachedAudio, InputMessageContent,
};
#[test] #[test]
fn cached_audio_min_serialize() { fn cached_audio_min_serialize() {
let structure = InlineQueryResult::CachedAudio( let structure =
InlineQueryResultCachedAudio { InlineQueryResult::CachedAudio(InlineQueryResultCachedAudio {
id: String::from("id"), id: String::from("id"),
audio_file_id: String::from("audio_file_id"), audio_file_id: String::from("audio_file_id"),
caption: None, caption: None,
parse_mode: None, parse_mode: None,
reply_markup: None, reply_markup: None,
input_message_content: None input_message_content: None,
} });
);
let expected_json = r#"{"type":"audio","id":"id","audio_file_id":"audio_file_id"}"#; let expected_json =
r#"{"type":"audio","id":"id","audio_file_id":"audio_file_id"}"#;
let actual_json = serde_json::to_string(&structure).unwrap(); let actual_json = serde_json::to_string(&structure).unwrap();
assert_eq!(expected_json, actual_json); assert_eq!(expected_json, actual_json);
@ -84,8 +76,8 @@ mod tests {
#[test] #[test]
fn cached_audio_full_serialize() { fn cached_audio_full_serialize() {
let structure = InlineQueryResult::CachedAudio( let structure =
InlineQueryResultCachedAudio { InlineQueryResult::CachedAudio(InlineQueryResultCachedAudio {
id: String::from("id"), id: String::from("id"),
audio_file_id: String::from("audio_file_id"), audio_file_id: String::from("audio_file_id"),
caption: Some(String::from("caption")), caption: Some(String::from("caption")),
@ -94,10 +86,9 @@ mod tests {
input_message_content: Some(InputMessageContent::Text { input_message_content: Some(InputMessageContent::Text {
message_text: String::from("message_text"), message_text: String::from("message_text"),
parse_mode: Some(ParseMode::Markdown), parse_mode: Some(ParseMode::Markdown),
disable_web_page_preview: Some(true) disable_web_page_preview: Some(true),
}) }),
} });
);
let expected_json = r#"{"type":"audio","id":"id","audio_file_id":"audio_file_id","caption":"caption","parse_mode":"HTML","reply_markup":{"inline_keyboard":[]},"input_message_content":{"message_text":"message_text","parse_mode":"Markdown","disable_web_page_preview":true}}"#; let expected_json = r#"{"type":"audio","id":"id","audio_file_id":"audio_file_id","caption":"caption","parse_mode":"HTML","reply_markup":{"inline_keyboard":[]},"input_message_content":{"message_text":"message_text","parse_mode":"Markdown","disable_web_page_preview":true}}"#;
let actual_json = serde_json::to_string(&structure).unwrap(); let actual_json = serde_json::to_string(&structure).unwrap();
@ -106,4 +97,4 @@ mod tests {
} }
// TODO: Add more tests // TODO: Add more tests
} }

View file

@ -1,4 +1,4 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; use crate::core::types::{InlineKeyboardMarkup, InputMessageContent};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultArticle { pub struct InlineQueryResultArticle {
@ -14,7 +14,8 @@ pub struct InlineQueryResultArticle {
/// Optional. URL of the result /// Optional. URL of the result
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub url: Option<String>, pub url: Option<String>,
/// Optional. Pass True, if you don't want the URL to be shown in the message /// Optional. Pass True, if you don't want the URL to be shown in the
/// message
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub hide_url: Option<bool>, pub hide_url: Option<bool>,
/// Optional. Short description of the result /// Optional. Short description of the result

View file

@ -1,4 +1,6 @@
use crate::core::types::{ParseMode, InlineKeyboardMarkup, InputMessageContent}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultAudio { pub struct InlineQueryResultAudio {
@ -17,4 +19,4 @@ pub struct InlineQueryResultAudio {
pub reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>, pub input_message_content: Option<InputMessageContent>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultCachedAudio { pub struct InlineQueryResultCachedAudio {
@ -12,4 +14,4 @@ pub struct InlineQueryResultCachedAudio {
pub reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>, pub input_message_content: Option<InputMessageContent>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultCachedDocument { pub struct InlineQueryResultCachedDocument {
@ -15,4 +17,4 @@ pub struct InlineQueryResultCachedDocument {
pub reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>, pub input_message_content: Option<InputMessageContent>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultCachedGif { pub struct InlineQueryResultCachedGif {
@ -14,4 +16,4 @@ pub struct InlineQueryResultCachedGif {
pub reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>, pub input_message_content: Option<InputMessageContent>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultCachedMpeg4Gif { pub struct InlineQueryResultCachedMpeg4Gif {
@ -14,4 +16,4 @@ pub struct InlineQueryResultCachedMpeg4Gif {
pub reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>, pub input_message_content: Option<InputMessageContent>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultCachedPhoto { pub struct InlineQueryResultCachedPhoto {
@ -16,4 +18,4 @@ pub struct InlineQueryResultCachedPhoto {
pub reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>, pub input_message_content: Option<InputMessageContent>,
} }

View file

@ -1,4 +1,4 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup}; use crate::core::types::{InlineKeyboardMarkup, InputMessageContent};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultCachedSticker { pub struct InlineQueryResultCachedSticker {
@ -8,4 +8,4 @@ pub struct InlineQueryResultCachedSticker {
pub reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>, pub input_message_content: Option<InputMessageContent>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultCachedVideo { pub struct InlineQueryResultCachedVideo {
@ -15,4 +17,4 @@ pub struct InlineQueryResultCachedVideo {
pub reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>, pub input_message_content: Option<InputMessageContent>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultCachedVoice { pub struct InlineQueryResultCachedVoice {
@ -13,4 +15,4 @@ pub struct InlineQueryResultCachedVoice {
pub reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>, pub input_message_content: Option<InputMessageContent>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultContact { pub struct InlineQueryResultContact {
@ -19,4 +21,4 @@ pub struct InlineQueryResultContact {
pub thumb_width: Option<i32>, pub thumb_width: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub thumb_height: Option<i32>, pub thumb_height: Option<i32>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultDocument { pub struct InlineQueryResultDocument {
@ -22,4 +24,4 @@ pub struct InlineQueryResultDocument {
pub thumb_width: Option<i32>, pub thumb_width: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub thumb_height: Option<i32>, pub thumb_height: Option<i32>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, Hash, PartialEq, Eq, Clone)] #[derive(Debug, Serialize, Hash, PartialEq, Eq, Clone)]
pub struct InlineQueryResultGame { pub struct InlineQueryResultGame {
@ -6,4 +8,4 @@ pub struct InlineQueryResultGame {
pub game_short_name: String, pub game_short_name: String,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultGif { pub struct InlineQueryResultGif {
@ -21,4 +23,4 @@ pub struct InlineQueryResultGif {
pub reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>, pub input_message_content: Option<InputMessageContent>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultLocation { pub struct InlineQueryResultLocation {
@ -18,4 +20,4 @@ pub struct InlineQueryResultLocation {
pub thumb_width: Option<i32>, pub thumb_width: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub thumb_height: Option<i32>, pub thumb_height: Option<i32>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultMpeg4Gif { pub struct InlineQueryResultMpeg4Gif {
@ -21,4 +23,4 @@ pub struct InlineQueryResultMpeg4Gif {
pub reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>, pub input_message_content: Option<InputMessageContent>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultPhoto { pub struct InlineQueryResultPhoto {
@ -21,4 +23,4 @@ pub struct InlineQueryResultPhoto {
pub reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>, pub input_message_content: Option<InputMessageContent>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultVenue { pub struct InlineQueryResultVenue {
@ -21,4 +23,4 @@ pub struct InlineQueryResultVenue {
pub thumb_width: Option<i32>, pub thumb_width: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub thumb_height: Option<i32>, pub thumb_height: Option<i32>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultVideo { pub struct InlineQueryResultVideo {
@ -23,4 +25,4 @@ pub struct InlineQueryResultVideo {
pub reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>, pub input_message_content: Option<InputMessageContent>,
} }

View file

@ -1,4 +1,6 @@
use crate::core::types::{InputMessageContent, InlineKeyboardMarkup, ParseMode}; use crate::core::types::{
InlineKeyboardMarkup, InputMessageContent, ParseMode,
};
#[derive(Debug, Serialize, PartialEq, Clone)] #[derive(Debug, Serialize, PartialEq, Clone)]
pub struct InlineQueryResultVoice { pub struct InlineQueryResultVoice {
@ -15,4 +17,4 @@ pub struct InlineQueryResultVoice {
pub reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub input_message_content: Option<InputMessageContent>, pub input_message_content: Option<InputMessageContent>,
} }

View file

@ -8,18 +8,20 @@ use crate::core::types::ParseMode;
/// a result of an inline query. /// a result of an inline query.
/// [More](https://core.telegram.org/bots/api#inputmessagecontent) /// [More](https://core.telegram.org/bots/api#inputmessagecontent)
pub enum InputMessageContent { pub enum InputMessageContent {
/// Represents the content of a text message to be sent as the result of an inline query. /// Represents the content of a text message to be sent as the result of an
/// inline query.
Text { Text {
/// Text of the message to be sent, 1-4096 characters /// Text of the message to be sent, 1-4096 characters
message_text: String, message_text: String,
/// Send [Markdown] or [HTML], /// Send [Markdown] or [HTML],
/// if you want Telegram apps to show [bold, italic, fixed-width text or inline URLs] /// if you want Telegram apps to show [bold, italic, fixed-width text
/// in the media caption. /// or inline URLs] in the media caption.
/// ///
/// [Markdown]: crate::core::types::ParseMode::Markdown /// [Markdown]: crate::core::types::ParseMode::Markdown
/// [Html]: crate::core::types::ParseMode::Html /// [Html]: crate::core::types::ParseMode::Html
/// [bold, italic, fixed-width text or inline URLs]: crate::core::types::ParseMode /// [bold, italic, fixed-width text or inline URLs]:
/// crate::core::types::ParseMode
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
parse_mode: Option<ParseMode>, parse_mode: Option<ParseMode>,
@ -27,18 +29,21 @@ pub enum InputMessageContent {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
disable_web_page_preview: Option<bool>, disable_web_page_preview: Option<bool>,
}, },
/// Represents the content of a location message to be sent as the result of an inline query. /// Represents the content of a location message to be sent as the result
/// of an inline query.
Location { Location {
/// Latitude of the location in degrees /// Latitude of the location in degrees
latitude: f64, latitude: f64,
/// Longitude of the location in degrees /// Longitude of the location in degrees
longitude: f64, longitude: f64,
/// Period in seconds for which the location can be updated, should be between 60 and 86400. /// Period in seconds for which the location can be updated, should be
/// between 60 and 86400.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
live_period: Option<u32>, live_period: Option<u32>,
}, },
/// Represents the content of a venue message to be sent as the result of an inline query. /// Represents the content of a venue message to be sent as the result of
/// an inline query.
Venue { Venue {
/// Latitude of the venue in degrees /// Latitude of the venue in degrees
latitude: f64, latitude: f64,
@ -53,12 +58,14 @@ pub enum InputMessageContent {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
foursquare_id: Option<String>, foursquare_id: Option<String>,
/// Foursquare type of the venue, if known. (For example, “arts_entertainment/default”, /// Foursquare type of the venue, if known. (For example,
/// “arts_entertainment/aquarium” or “food/icecream”.) /// “arts_entertainment/default”, “arts_entertainment/aquarium”
/// or “food/icecream”.)
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
foursquare_type: Option<String>, foursquare_type: Option<String>,
}, },
/// Represents the content of a contact message to be sent as the result of an inline query. /// Represents the content of a contact message to be sent as the result of
/// an inline query.
Contact { Contact {
/// Contact's phone number /// Contact's phone number
phone_number: String, phone_number: String,
@ -124,7 +131,8 @@ mod tests {
#[test] #[test]
fn contact_serialize() { fn contact_serialize() {
let expected_json = r#"{"phone_number":"+3800000000","first_name":"jhon"}"#; let expected_json =
r#"{"phone_number":"+3800000000","first_name":"jhon"}"#;
let contact_content = InputMessageContent::Contact { let contact_content = InputMessageContent::Contact {
phone_number: String::from("+3800000000"), phone_number: String::from("+3800000000"),
first_name: String::from("jhon"), first_name: String::from("jhon"),
@ -135,4 +143,4 @@ mod tests {
let actual_json = serde_json::to_string(&contact_content).unwrap(); let actual_json = serde_json::to_string(&contact_content).unwrap();
assert_eq!(expected_json, actual_json); assert_eq!(expected_json, actual_json);
} }
} }

View file

@ -20,7 +20,7 @@ mod tests {
fn serialize() { fn serialize() {
let labeled_price = LabeledPrice { let labeled_price = LabeledPrice {
label: "Label".to_string(), label: "Label".to_string(),
amount: 60 amount: 60,
}; };
let expected = r#"{"label":"Label","amount":60}"#; let expected = r#"{"label":"Label","amount":60}"#;
let actual = serde_json::to_string(&labeled_price).unwrap(); let actual = serde_json::to_string(&labeled_price).unwrap();

View file

@ -5,4 +5,4 @@ pub struct Location {
pub longitude: f64, pub longitude: f64,
/// Latitude as defined by sender /// Latitude as defined by sender
pub latitude: f64, pub latitude: f64,
} }

View file

@ -5,4 +5,3 @@ pub struct MaskPosition {
pub y_shift: f64, pub y_shift: f64,
pub scale: f64, pub scale: f64,
} }

View file

@ -10,12 +10,36 @@ pub use self::{
chosen_inline_result::ChosenInlineResult, chosen_inline_result::ChosenInlineResult,
contact::Contact, contact::Contact,
document::Document, document::Document,
file::File,
force_reply::ForceReply, force_reply::ForceReply,
game::Game, game::Game,
inline_keyboard_button::{InlineKeyboardButton, InlineKeyboardButtonKind}, inline_keyboard_button::{InlineKeyboardButton, InlineKeyboardButtonKind},
inline_keyboard_markup::InlineKeyboardMarkup, inline_keyboard_markup::InlineKeyboardMarkup,
inline_query::InlineQuery,
inline_query_result::InlineQueryResult,
inline_query_result_article::InlineQueryResultArticle,
inline_query_result_audio::InlineQueryResultAudio,
inline_query_result_cached_audio::InlineQueryResultCachedAudio,
inline_query_result_cached_document::InlineQueryResultCachedDocument,
inline_query_result_cached_gif::InlineQueryResultCachedGif,
inline_query_result_cached_mpeg4_gif::InlineQueryResultCachedMpeg4Gif,
inline_query_result_cached_photo::InlineQueryResultCachedPhoto,
inline_query_result_cached_sticker::InlineQueryResultCachedSticker,
inline_query_result_cached_video::InlineQueryResultCachedVideo,
inline_query_result_cached_voice::InlineQueryResultCachedVoice,
inline_query_result_contact::InlineQueryResultContact,
inline_query_result_document::InlineQueryResultDocument,
inline_query_result_game::InlineQueryResultGame,
inline_query_result_gif::InlineQueryResultGif,
inline_query_result_location::InlineQueryResultLocation,
inline_query_result_mpeg4_gif::InlineQueryResultMpeg4Gif,
inline_query_result_photo::InlineQueryResultPhoto,
inline_query_result_venue::InlineQueryResultVenue,
inline_query_result_video::InlineQueryResultVideo,
inline_query_result_voice::InlineQueryResultVoice,
input_file::InputFile, input_file::InputFile,
input_media::InputMedia, input_media::InputMedia,
input_message_content::InputMessageContent,
invoice::Invoice, invoice::Invoice,
keyboard_button::KeyboardButton, keyboard_button::KeyboardButton,
label_price::LabeledPrice, label_price::LabeledPrice,
@ -46,31 +70,6 @@ pub use self::{
video::Video, video::Video,
video_note::VideoNote, video_note::VideoNote,
voice::Voice, voice::Voice,
file::File,
input_message_content::InputMessageContent,
inline_query::InlineQuery,
inline_query_result::InlineQueryResult,
inline_query_result_cached_audio::InlineQueryResultCachedAudio,
inline_query_result_cached_document::InlineQueryResultCachedDocument,
inline_query_result_cached_gif::InlineQueryResultCachedGif,
inline_query_result_cached_mpeg4_gif::InlineQueryResultCachedMpeg4Gif,
inline_query_result_cached_photo::InlineQueryResultCachedPhoto,
inline_query_result_cached_sticker::InlineQueryResultCachedSticker,
inline_query_result_cached_video::InlineQueryResultCachedVideo,
inline_query_result_cached_voice::InlineQueryResultCachedVoice,
inline_query_result_article::InlineQueryResultArticle,
inline_query_result_audio::InlineQueryResultAudio,
inline_query_result_contact::InlineQueryResultContact,
inline_query_result_game::InlineQueryResultGame,
inline_query_result_document::InlineQueryResultDocument,
inline_query_result_gif::InlineQueryResultGif,
inline_query_result_location::InlineQueryResultLocation,
inline_query_result_mpeg4_gif::InlineQueryResultMpeg4Gif,
inline_query_result_photo::InlineQueryResultPhoto,
inline_query_result_venue::InlineQueryResultVenue,
inline_query_result_video::InlineQueryResultVideo,
inline_query_result_voice::InlineQueryResultVoice,
}; };
mod animation; mod animation;
@ -83,12 +82,14 @@ mod chat_photo;
mod chosen_inline_result; mod chosen_inline_result;
mod contact; mod contact;
mod document; mod document;
mod file;
mod force_reply; mod force_reply;
mod game; mod game;
mod inline_keyboard_button; mod inline_keyboard_button;
mod inline_keyboard_markup; mod inline_keyboard_markup;
mod input_file; mod input_file;
mod input_media; mod input_media;
mod input_message_content;
mod invoice; mod invoice;
mod keyboard_button; mod keyboard_button;
mod label_price; mod label_price;
@ -118,11 +119,11 @@ mod venue;
mod video; mod video;
mod video_note; mod video_note;
mod voice; mod voice;
mod file;
mod input_message_content;
mod inline_query; mod inline_query;
mod inline_query_result; mod inline_query_result;
mod inline_query_result_article;
mod inline_query_result_audio;
mod inline_query_result_cached_audio; mod inline_query_result_cached_audio;
mod inline_query_result_cached_document; mod inline_query_result_cached_document;
mod inline_query_result_cached_gif; mod inline_query_result_cached_gif;
@ -131,11 +132,9 @@ mod inline_query_result_cached_photo;
mod inline_query_result_cached_sticker; mod inline_query_result_cached_sticker;
mod inline_query_result_cached_video; mod inline_query_result_cached_video;
mod inline_query_result_cached_voice; mod inline_query_result_cached_voice;
mod inline_query_result_article;
mod inline_query_result_audio;
mod inline_query_result_contact; mod inline_query_result_contact;
mod inline_query_result_game;
mod inline_query_result_document; mod inline_query_result_document;
mod inline_query_result_game;
mod inline_query_result_gif; mod inline_query_result_gif;
mod inline_query_result_location; mod inline_query_result_location;
mod inline_query_result_mpeg4_gif; mod inline_query_result_mpeg4_gif;

View file

@ -24,7 +24,7 @@ mod tests {
file_id: "id".to_string(), file_id: "id".to_string(),
width: 320, width: 320,
height: 320, height: 320,
file_size: Some(3452) file_size: Some(3452),
}; };
let actual = serde_json::from_str::<PhotoSize>(json).unwrap(); let actual = serde_json::from_str::<PhotoSize>(json).unwrap();
assert_eq!(actual, expected); assert_eq!(actual, expected);

View file

@ -1,5 +1,5 @@
use crate::core::types::{InlineKeyboardMarkup, LabeledPrice};
use crate::core::requests::ChatId; use crate::core::requests::ChatId;
use crate::core::types::{InlineKeyboardMarkup, LabeledPrice};
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]
pub struct SendInvoice { pub struct SendInvoice {

View file

@ -20,9 +20,10 @@ mod tests {
let shipping_option = ShippingOption { let shipping_option = ShippingOption {
id: "0".to_string(), id: "0".to_string(),
title: "Option".to_string(), title: "Option".to_string(),
prices: vec![ prices: vec![LabeledPrice {
LabeledPrice { label: "Label".to_string(), amount: 60 } label: "Label".to_string(),
] amount: 60,
}],
}; };
let expected = r#"{"id":"0","title":"Option","prices":[{"label":"Label","amount":60}]}"#; let expected = r#"{"id":"0","title":"Option","prices":[{"label":"Label","amount":60}]}"#;
let actual = serde_json::to_string(&shipping_option).unwrap(); let actual = serde_json::to_string(&shipping_option).unwrap();

View file

@ -1,6 +1,4 @@
use crate::core::types::{ use crate::core::types::{CallbackQuery, ChosenInlineResult, Message};
Message, ChosenInlineResult, CallbackQuery,
};
#[derive(Debug, Deserialize, PartialEq, Clone)] #[derive(Debug, Deserialize, PartialEq, Clone)]
pub struct Update { pub struct Update {

View file

@ -1,6 +1,5 @@
use crate::core::types::Location; use crate::core::types::Location;
/// This object represents a venue. /// This object represents a venue.
#[derive(Debug, Deserialize, PartialEq, Serialize, Clone)] #[derive(Debug, Deserialize, PartialEq, Serialize, Clone)]
pub struct Venue { pub struct Venue {
@ -13,7 +12,9 @@ pub struct Venue {
/// Foursquare identifier of the venue /// Foursquare identifier of the venue
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub foursquare_id: Option<String>, pub foursquare_id: Option<String>,
/// Foursquare type of the venue. (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.) /// Foursquare type of the venue. (For example,
/// “arts_entertainment/default”, “arts_entertainment/aquarium” or
/// “food/icecream”.)
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub foursquare_type: Option<String>, // TODO: is this enum?... pub foursquare_type: Option<String>, // TODO: is this enum?...
} }

View file

@ -1,5 +1,5 @@
use serde::Deserialize;
use crate::core::types::PhotoSize; use crate::core::types::PhotoSize;
use serde::Deserialize;
#[derive(Debug, Deserialize, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Deserialize, Clone, PartialEq, Eq, Hash)]
/// This object represents a [video message](https://telegram.org/blog/video-messages-and-telescope) /// This object represents a [video message](https://telegram.org/blog/video-messages-and-telescope)
@ -7,7 +7,8 @@ use crate::core::types::PhotoSize;
pub struct VideoNote { pub struct VideoNote {
/// Identifier for this file /// Identifier for this file
pub file_id: String, pub file_id: String,
/// Video width and height (diameter of the video message) as defined by sender /// Video width and height (diameter of the video message) as defined by
/// sender
pub length: u32, pub length: u32,
/// Duration of the video in seconds as defined by sender /// Duration of the video in seconds as defined by sender
pub duration: u32, pub duration: u32,
@ -15,4 +16,4 @@ pub struct VideoNote {
pub thumb: Option<PhotoSize>, pub thumb: Option<PhotoSize>,
/// Optional. File size /// Optional. File size
pub file_size: Option<u32>, pub file_size: Option<u32>,
} }

View file

@ -11,4 +11,4 @@ pub struct Voice {
pub mime_type: Option<String>, pub mime_type: Option<String>,
/// Optional. File size /// Optional. File size
pub file_size: Option<u64>, pub file_size: Option<u64>,
} }