Merge pull request #8 from Mr-Andersen/dev

Added dummy types into core/types/not_implemented_types.rs; Added Mes…
This commit is contained in:
Temirkhan Myrzamadi 2019-09-03 17:20:06 +06:00 committed by GitHub
commit d8c70b9fc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 126 additions and 30 deletions

View file

@ -32,16 +32,14 @@ impl FormBuilder {
where where
T: Serialize, T: Serialize,
{ {
Self { match value {
form: value.map_or_else( None => Self { form: self.form },
|| self.form, Some(value) => Self {
|value| { form: self.form.text(
self.form.text(
name.to_owned(), name.to_owned(),
serde_json::to_string(value).expect("serde_json::to_string failed"), serde_json::to_string(value).expect("serde_json::to_string failed"),
) )
}, }
),
} }
} }

View file

@ -18,7 +18,7 @@ impl Request for GetMe {
type ReturnValue = User; type ReturnValue = User;
fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>> { fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>> {
Box::new(async { Box::new(async move {
request(&self.info.client, &self.info.token, "getMe", None).await request(&self.info.client, &self.info.token, "getMe", None).await
}) })
} }

View file

@ -22,9 +22,9 @@ pub type RequestFuture<T> = Box<dyn Future<Output = T>>;
// todo: better name? // todo: better name?
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct RequestInfo { pub struct RequestInfo {
pub(crate) client: Client, pub client: Client,
pub(crate) token: String, pub token: String,
} }
/// Unique identifier for the target chat or username of the target channel (in /// Unique identifier for the target chat or username of the target channel (in

View file

@ -37,7 +37,7 @@ impl Request for SendMessage {
fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>> { fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>> {
Box::new(async { Box::new(async move {
let params = FormBuilder::new() let params = FormBuilder::new()
.add("chat_id", &self.chat_id) .add("chat_id", &self.chat_id)
.add("text", &self.text) .add("text", &self.text)

View file

@ -1,4 +1,4 @@
use serde::Deserialize; use crate::core::types::PhotoSize;
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)] #[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
pub struct Document { pub struct Document {

View file

@ -1,6 +1,12 @@
use serde::Deserialize; // use serde::Deserialize;
use crate::core::types::{Chat, Document, Invoice, SuccessfulPayment, User}; use crate::core::types::{
Animation, Audio, Chat, Contact,
Document, Game, Invoice, InlineKeyboardMarkup,
PhotoSize, MessageEntity, Location, PassportData, Poll,
Sticker, SuccessfulPayment,
User, Video, VideoNote, Venue, Voice,
};
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)] #[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
pub struct Message { pub struct Message {
@ -26,7 +32,7 @@ pub struct Message {
pub animation: Option<Animation>, pub animation: Option<Animation>,
pub game: Option<Game>, pub game: Option<Game>,
pub photo: Option<Vec<PhotoSize>>, pub photo: Option<Vec<PhotoSize>>,
pub sticker: Option<Stickers>, pub sticker: Option<Sticker>,
pub video: Option<Video>, pub video: Option<Video>,
pub voice: Option<Voice>, pub voice: Option<Voice>,
pub video_note: Option<VideoNote>, pub video_note: Option<VideoNote>,

View file

@ -0,0 +1,36 @@
use crate::core::types::User;
#[derive(Deserialize, Debug, PartialEq, Hash, Eq)]
pub struct MessageEntity {
#[serde(flatten)]
pub kind: MessageEntityKind,
pub offset: usize,
pub length: usize,
}
#[derive(Deserialize, Debug, PartialEq, Hash, Eq)]
#[serde(rename_all = "snake_case")]
#[serde(tag = "type")]
pub enum MessageEntityKind {
Mention, Hashtag, Cashtag, BotCommand, Url, Email, PhoneNumber,
Bold, Italic, Code, Pre,
TextLink { url: String },
TextMention { user: User }
}
#[test]
fn recursive_kind() {
use serde_json::from_str;
assert_eq!(
MessageEntity {
kind: MessageEntityKind::TextLink { url: "ya.ru".into() },
offset: 1,
length: 2
},
from_str::<MessageEntity>(
r#"{"type":"text_link","url":"ya.ru","offset":1,"length":2}"#
).unwrap()
);
}

View file

@ -1,10 +1,27 @@
mod not_implemented_types;
use self::not_implemented_types::*;
pub use self::{ pub use self::{
answer_pre_checkout_query::AnswerPreCheckoutQuery, answer_shipping_query::AnswerShippingQuery, answer_pre_checkout_query::AnswerPreCheckoutQuery,
chat::Chat, chat_permissions::ChatPermissions, chat_photo::ChatPhoto, document::Document, answer_shipping_query::AnswerShippingQuery,
invoice::Invoice, label_price::LabeledPrice, message::Message, order_info::OrderInfo, chat::Chat,
pre_checkout_query::PreCheckoutQuery, send_invoice::SendInvoice, chat_permissions::ChatPermissions,
shipping_address::ShippingAddress, shipping_option::ShippingOption, chat_photo::ChatPhoto,
shipping_query::ShippingQuery, successful_payment::SuccessfulPayment, user::User, document::Document,
invoice::Invoice,
label_price::LabeledPrice,
message::Message,
message_entity::MessageEntity,
order_info::OrderInfo,
pre_checkout_query::PreCheckoutQuery,
send_invoice::SendInvoice,
shipping_address::ShippingAddress,
shipping_option::ShippingOption,
shipping_query::ShippingQuery,
sticker::Sticker,
successful_payment::SuccessfulPayment,
user::User,
}; };
mod answer_pre_checkout_query; mod answer_pre_checkout_query;
@ -16,11 +33,13 @@ mod document;
mod invoice; mod invoice;
mod label_price; mod label_price;
mod message; mod message;
mod message_entity;
mod order_info; mod order_info;
mod pre_checkout_query; mod pre_checkout_query;
mod send_invoice; mod send_invoice;
mod shipping_address; mod shipping_address;
mod shipping_option; mod shipping_option;
mod shipping_query; mod shipping_query;
mod sticker;
mod successful_payment; mod successful_payment;
mod user; mod user;

View file

@ -0,0 +1,41 @@
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
pub struct PhotoSize;
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
pub struct Location;
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
pub struct InlineKeyboardMarkup;
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
pub struct PassportData;
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
pub struct Poll;
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
pub struct Animation;
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
pub struct Audio;
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
pub struct Game;
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
pub struct Contact;
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
pub struct Video;
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
pub struct VideoNote;
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
pub struct Venue;
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
pub struct Voice;
#[derive(Debug, Deserialize, Serialize, PartialEq, Hash, Eq)]
pub struct MaskPosition;

View file

@ -1,6 +1,4 @@
use serde::Deserialize; use crate::core::types::{InlineKeyboardMarkup, LabeledPrice};
use crate::core::types::LabeledPrice;
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)] #[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
pub struct SendInvoice { pub struct SendInvoice {

View file

@ -1,5 +1,3 @@
#![feature(async_await)]
#[macro_use] #[macro_use]
extern crate derive_more; extern crate derive_more;
#[macro_use] #[macro_use]