Put all the existing types into core/types

This commit is contained in:
Temirkhan Myrzamadi 2019-09-02 16:55:19 +06:00
parent c4fcc13dcd
commit 72be7ee750
22 changed files with 220 additions and 175 deletions

View file

@ -1,5 +1,3 @@
mod network;
mod requests;
mod other;
mod payments;
pub mod requests;
pub mod types;

View file

@ -1,114 +0,0 @@
use crate::core::other::User;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct SendInvoice {
chat_id: i64,
title: String,
description: String,
payload: String,
provider_token: String,
start_parameter: String,
currency: String,
prices: Vec<LabeledPrice>,
provider_data: Option<String>,
photo_url: Option<String>,
photo_size: Option<i64>,
photo_width: Option<i64>,
photo_height: Option<i64>,
need_name: Option<bool>,
need_phone_number: Option<bool>,
need_email: Option<bool>,
need_shipping_address: Option<bool>,
send_phone_number_to_provider: Option<bool>,
send_email_to_provider: Option<bool>,
is_flexible: Option<bool>,
disable_notification: Option<bool>,
reply_to_message_id: Option<i64>,
reply_markup: Option<InlineKeyboardMarkup>,
}
#[derive(Debug, Deserialize)]
pub struct AnswerShippingQuery {
shipping_query_id: String,
ok: bool,
shipping_options: Option<Vec<ShippingOption>>,
error_message: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct AnswerPreCheckoutQuery {
pre_checkout_query_id: String,
ok: bool,
error_message: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct LabeledPrice {
label: String,
amount: i64,
}
#[derive(Debug, Deserialize)]
pub struct Invoice {
title: String,
description: String,
start_parameter: String,
currency: String,
total_amount: i64,
}
#[derive(Debug, Deserialize)]
pub struct ShippingAddress {
country_code: String,
state: String,
city: String,
street_line1: String,
street_line2: String,
post_code: String,
}
#[derive(Debug, Deserialize)]
pub struct OrderInfo {
name: String,
phone_number: String,
email: String,
shipping_address: ShippingAddress,
}
#[derive(Debug, Deserialize)]
pub struct ShippingOption {
id: i64,
title: String,
prices: Vec<LabeledPrice>,
}
#[derive(Debug, Deserialize)]
pub struct SuccessfulPayment {
currency: String,
total_amount: i64,
invoice_payload: String,
shipping_option_id: Option<String>,
order_info: Option<OrderInfo>,
telegram_payment_charge_id: String,
provider_payment_charge_id: String,
}
#[derive(Debug, Deserialize)]
pub struct ShippingQuery {
id: String,
from: User,
invoice_payload: String,
shipping_address: ShippingAddress,
}
#[derive(Debug, Deserialize)]
pub struct PreCheckoutQuery {
id: String,
from: User,
currency: String,
total_amount: i64,
invoice_payload: String,
shipping_option_id: Option<String>,
order_info: Option<OrderInfo>,
}

View file

@ -1,7 +1,7 @@
use super::Request;
use crate::core::other::User;
use reqwest::r#async::multipart::Form;
use crate::core::types::User;
#[derive(Debug, Constructor, PartialEq, Eq)]
pub struct GetMe {

View file

@ -1,5 +1,5 @@
use super::{ChatId, Request};
use crate::core::other::Message;
use crate::core::types::Message;
use reqwest::r#async::multipart::Form;

View file

@ -0,0 +1,8 @@
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct AnswerPreCheckoutQuery {
pre_checkout_query_id: String,
ok: bool,
error_message: Option<String>,
}

View file

@ -0,0 +1,10 @@
use serde::Deserialize;
use crate::core::types::ShippingOption;
#[derive(Debug, Deserialize)]
pub struct AnswerShippingQuery {
shipping_query_id: String,
ok: bool,
shipping_options: Option<Vec<ShippingOption>>,
error_message: Option<String>,
}

19
src/core/types/chat.rs Normal file
View file

@ -0,0 +1,19 @@
use serde::Deserialize;
use crate::core::types::{ChatPhoto, ChatPermissions, Message};
#[derive(Debug, Deserialize)]
pub struct Chat {
id: i64,
chat_type: String,
title: Option<String>,
username: Option<String>,
first_name: Option<String>,
last_name: Option<String>,
photo: Option<ChatPhoto>,
description: Option<String>,
invite_link: Option<String>,
pinned_message: Option<Box<Message>>,
permissions: Option<ChatPermissions>,
sticker_set_name: Option<String>,
can_set_sticker_set: Option<bool>,
}

View file

@ -0,0 +1,13 @@
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct ChatPermissions {
can_send_messages: Option<bool>,
can_send_media_messages: Option<bool>,
can_send_polls: Option<bool>,
can_send_other_messages: Option<bool>,
can_add_web_page_previews: Option<bool>,
can_change_info: Option<bool>,
can_invite_users: Option<bool>,
can_pin_messages: Option<bool>,
}

View file

@ -0,0 +1,7 @@
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct ChatPhoto {
small_file_id: String,
big_file_id: String,
}

View file

@ -0,0 +1,10 @@
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct Document {
file_id: String,
thumb: Option<PhotoSize>,
file_name: Option<String>,
mime_type: Option<String>,
file_size: Option<i64>,
}

10
src/core/types/invoice.rs Normal file
View file

@ -0,0 +1,10 @@
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct Invoice {
title: String,
description: String,
start_parameter: String,
currency: String,
total_amount: i64,
}

View file

@ -0,0 +1,7 @@
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct LabeledPrice {
label: String,
amount: i64,
}

View file

@ -1,32 +1,5 @@
use crate::core::payments::{Invoice, SuccessfulPayment};
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct User {
id: i64,
is_bot: bool,
first_name: String,
last_name: Option<String>,
username: Option<String>,
language_code: Option<String>,
}
#[derive(Debug, Deserialize)]
pub struct Chat {
id: i64,
chat_type: String,
title: Option<String>,
username: Option<String>,
first_name: Option<String>,
last_name: Option<String>,
photo: Option<ChatPhoto>,
description: Option<String>,
invite_link: Option<String>,
pinned_message: Option<Box<Message>>,
permissions: Option<ChatPermissions>,
sticker_set_name: Option<String>,
can_set_sticker_set: Option<bool>,
}
use crate::core::types::{User, Chat, Document, Invoice, SuccessfulPayment};
#[derive(Debug, Deserialize)]
pub struct Message {
@ -78,30 +51,3 @@ pub struct Message {
passport_data: Option<PassportData>,
reply_markup: Option<InlineKeyboardMarkup>,
}
#[derive(Debug, Deserialize)]
pub struct ChatPhoto {
small_file_id: String,
big_file_id: String,
}
#[derive(Debug, Deserialize)]
pub struct ChatPermissions {
can_send_messages: Option<bool>,
can_send_media_messages: Option<bool>,
can_send_polls: Option<bool>,
can_send_other_messages: Option<bool>,
can_add_web_page_previews: Option<bool>,
can_change_info: Option<bool>,
can_invite_users: Option<bool>,
can_pin_messages: Option<bool>,
}
#[derive(Debug, Deserialize)]
pub struct Document {
file_id: String,
thumb: Option<PhotoSize>,
file_name: Option<String>,
mime_type: Option<String>,
file_size: Option<i64>,
}

25
src/core/types/mod.rs Normal file
View file

@ -0,0 +1,25 @@
pub use self::{
answer_pre_checkout_query::AnswerPreCheckoutQuery, answer_shipping_query::AnswerShippingQuery,
chat::Chat, chat_permissions::ChatPermissions, chat_photo::ChatPhoto, document::Document,
invoice::Invoice, label_price::LabeledPrice, message::Message, order_info::OrderInfo,
pre_checkout_query::PreCheckoutQuery, send_invoice::SendInvoice, shipping_address::ShippingAddress,
shipping_option::ShippingOption, shipping_query::ShippingQuery, successful_payment::SuccessfulPayment, user::User,
};
mod answer_pre_checkout_query;
mod answer_shipping_query;
mod chat;
mod chat_permissions;
mod chat_photo;
mod document;
mod invoice;
mod label_price;
mod message;
mod order_info;
mod pre_checkout_query;
mod send_invoice;
mod shipping_address;
mod shipping_option;
mod shipping_query;
mod successful_payment;
mod user;

View file

@ -0,0 +1,10 @@
use serde::Deserialize;
use crate::core::types::ShippingAddress;
#[derive(Debug, Deserialize)]
pub struct OrderInfo {
name: String,
phone_number: String,
email: String,
shipping_address: ShippingAddress,
}

View file

@ -0,0 +1,13 @@
use serde::Deserialize;
use crate::core::types::{User, OrderInfo};
#[derive(Debug, Deserialize)]
pub struct PreCheckoutQuery {
id: String,
from: User,
currency: String,
total_amount: i64,
invoice_payload: String,
shipping_option_id: Option<String>,
order_info: Option<OrderInfo>,
}

View file

@ -0,0 +1,29 @@
use serde::Deserialize;
use crate::core::types::LabeledPrice;
#[derive(Debug, Deserialize)]
pub struct SendInvoice {
chat_id: i64,
title: String,
description: String,
payload: String,
provider_token: String,
start_parameter: String,
currency: String,
prices: Vec<LabeledPrice>,
provider_data: Option<String>,
photo_url: Option<String>,
photo_size: Option<i64>,
photo_width: Option<i64>,
photo_height: Option<i64>,
need_name: Option<bool>,
need_phone_number: Option<bool>,
need_email: Option<bool>,
need_shipping_address: Option<bool>,
send_phone_number_to_provider: Option<bool>,
send_email_to_provider: Option<bool>,
is_flexible: Option<bool>,
disable_notification: Option<bool>,
reply_to_message_id: Option<i64>,
reply_markup: Option<InlineKeyboardMarkup>,
}

View file

@ -0,0 +1,11 @@
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct ShippingAddress {
country_code: String,
state: String,
city: String,
street_line1: String,
street_line2: String,
post_code: String,
}

View file

@ -0,0 +1,9 @@
use serde::Deserialize;
use crate::core::types::LabeledPrice;
#[derive(Debug, Deserialize)]
pub struct ShippingOption {
id: i64,
title: String,
prices: Vec<LabeledPrice>,
}

View file

@ -0,0 +1,10 @@
use serde::Deserialize;
use crate::core::types::{User, ShippingAddress};
#[derive(Debug, Deserialize)]
pub struct ShippingQuery {
id: String,
from: User,
invoice_payload: String,
shipping_address: ShippingAddress,
}

View file

@ -0,0 +1,13 @@
use serde::Deserialize;
use crate::core::types::OrderInfo;
#[derive(Debug, Deserialize)]
pub struct SuccessfulPayment {
currency: String,
total_amount: i64,
invoice_payload: String,
shipping_option_id: Option<String>,
order_info: Option<OrderInfo>,
telegram_payment_charge_id: String,
provider_payment_charge_id: String,
}

11
src/core/types/user.rs Normal file
View file

@ -0,0 +1,11 @@
use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct User {
id: i64,
is_bot: bool,
first_name: String,
last_name: Option<String>,
username: Option<String>,
language_code: Option<String>,
}