Make all fields of all the types public

This commit is contained in:
Temirkhan Myrzamadi 2019-09-02 17:10:55 +06:00
parent 8ca3e95193
commit 65f153734d
22 changed files with 184 additions and 168 deletions

View file

@ -1,4 +1,3 @@
use super::requests::Request;
use apply::Apply; use apply::Apply;
use futures::compat::Future01CompatExt; use futures::compat::Future01CompatExt;
use reqwest::r#async::Client; use reqwest::r#async::Client;
@ -6,6 +5,8 @@ use reqwest::StatusCode;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use serde_json::Value; use serde_json::Value;
use super::requests::Request;
const TELEGRAM_API_URL: &str = "https://api.telegram.org"; const TELEGRAM_API_URL: &str = "https://api.telegram.org";
fn method_url(base: &str, token: &str, method_name: &str) -> String { fn method_url(base: &str, token: &str, method_name: &str) -> String {
@ -43,7 +44,11 @@ pub async fn request<T: DeserializeOwned, R: Request<ReturnValue = T>>(
request: R, request: R,
) -> ResponseResult<T> { ) -> ResponseResult<T> {
let mut response = client let mut response = client
.post(&method_url(TELEGRAM_API_URL, request.token(), request.name())) .post(&method_url(
TELEGRAM_API_URL,
request.token(),
request.name(),
))
.apply(|request_builder| { .apply(|request_builder| {
if let Some(params) = request.params() { if let Some(params) = request.params() {
request_builder.multipart(params) request_builder.multipart(params)
@ -84,7 +89,7 @@ mod tests {
let url = method_url( let url = method_url(
TELEGRAM_API_URL, TELEGRAM_API_URL,
"535362388:AAF7-g0gYncWnm5IyfZlpPRqRRv6kNAGlao", "535362388:AAF7-g0gYncWnm5IyfZlpPRqRRv6kNAGlao",
"methodName" "methodName",
); );
assert_eq!( assert_eq!(
@ -98,7 +103,7 @@ mod tests {
let url = file_url( let url = file_url(
TELEGRAM_API_URL, TELEGRAM_API_URL,
"535362388:AAF7-g0gYncWnm5IyfZlpPRqRRv6kNAGlao", "535362388:AAF7-g0gYncWnm5IyfZlpPRqRRv6kNAGlao",
"AgADAgADyqoxG2g8aEsu_KjjVsGF4-zetw8ABAEAAwIAA20AA_8QAwABFgQ" "AgADAgADyqoxG2g8aEsu_KjjVsGF4-zetw8ABAEAAwIAA20AA_8QAwABFgQ",
); );
assert_eq!( assert_eq!(

View file

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

View file

@ -1,7 +1,8 @@
use super::{ChatId, Request}; use reqwest::r#async::multipart::Form;
use crate::core::types::Message; use crate::core::types::Message;
use reqwest::r#async::multipart::Form; use super::{ChatId, Request};
#[derive(Debug, TypedBuilder, PartialEq, Eq)] #[derive(Debug, TypedBuilder, PartialEq, Eq)]
pub struct SendMessage { pub struct SendMessage {
@ -10,7 +11,8 @@ pub struct SendMessage {
text: String, text: String,
#[builder(default)] #[builder(default)]
parse_mode: Option<String>, // TODO: enum parse_mode: Option<String>,
// TODO: enum
#[builder(default)] #[builder(default)]
disable_web_page_preview: Option<bool>, disable_web_page_preview: Option<bool>,
#[builder(default)] #[builder(default)]

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,53 +1,54 @@
use serde::Deserialize; use serde::Deserialize;
use crate::core::types::{User, Chat, Document, Invoice, SuccessfulPayment};
use crate::core::types::{Chat, Document, Invoice, SuccessfulPayment, User};
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
pub struct Message { pub struct Message {
message_id: i64, pub message_id: i64,
from: Option<Box<User>>, pub from: Option<Box<User>>,
date: i64, pub date: i64,
chat: Chat, pub chat: Chat,
forward_from: Option<User>, pub forward_from: Option<User>,
forward_from_chat: Option<Chat>, pub forward_from_chat: Option<Chat>,
forward_from_message_id: Option<i64>, pub forward_from_message_id: Option<i64>,
forward_signature: Option<String>, pub forward_signature: Option<String>,
forward_sender_name: Option<String>, pub forward_sender_name: Option<String>,
forward_date: Option<i64>, pub forward_date: Option<i64>,
reply_to_message: Option<Box<Message>>, pub reply_to_message: Option<Box<Message>>,
edit_date: Option<i64>, pub edit_date: Option<i64>,
media_group_id: Option<String>, pub media_group_id: Option<String>,
author_signature: Option<String>, pub author_signature: Option<String>,
text: Option<String>, pub text: Option<String>,
entities: Option<Vec<MessageEntity>>, pub entities: Option<Vec<MessageEntity>>,
caption_entities: Option<Vec<MessageEntity>>, pub caption_entities: Option<Vec<MessageEntity>>,
audio: Option<Audio>, pub audio: Option<Audio>,
document: Option<Document>, pub document: Option<Document>,
animation: Option<Animation>, pub animation: Option<Animation>,
game: Option<Game>, pub game: Option<Game>,
photo: Option<Vec<PhotoSize>>, pub photo: Option<Vec<PhotoSize>>,
sticker: Option<Stickers>, pub sticker: Option<Stickers>,
video: Option<Video>, pub video: Option<Video>,
voice: Option<Voice>, pub voice: Option<Voice>,
video_note: Option<VideoNote>, pub video_note: Option<VideoNote>,
caption: Option<String>, pub caption: Option<String>,
contact: Option<Contact>, pub contact: Option<Contact>,
location: Option<Location>, pub location: Option<Location>,
venue: Option<Venue>, pub venue: Option<Venue>,
poll: Option<Poll>, pub poll: Option<Poll>,
new_chat_members: Option<Vec<User>>, pub new_chat_members: Option<Vec<User>>,
left_chat_member: Option<User>, pub left_chat_member: Option<User>,
new_chat_title: Option<String>, pub new_chat_title: Option<String>,
new_chat_photo: Option<Vec<PhotoSize>>, pub new_chat_photo: Option<Vec<PhotoSize>>,
delete_chat_photo: Option<bool>, pub delete_chat_photo: Option<bool>,
group_chat_created: Option<bool>, pub group_chat_created: Option<bool>,
supergroup_chat_created: Option<bool>, pub supergroup_chat_created: Option<bool>,
channel_chat_created: Option<bool>, pub channel_chat_created: Option<bool>,
migrate_to_chat_id: Option<i64>, pub migrate_to_chat_id: Option<i64>,
migrate_from_chat_id: Option<i64>, pub migrate_from_chat_id: Option<i64>,
pinned_message: Option<Box<Message>>, pub pinned_message: Option<Box<Message>>,
invoice: Option<Invoice>, pub invoice: Option<Invoice>,
successful_payment: Option<SuccessfulPayment>, pub successful_payment: Option<SuccessfulPayment>,
connected_website: Option<String>, pub connected_website: Option<String>,
passport_data: Option<PassportData>, pub passport_data: Option<PassportData>,
reply_markup: Option<InlineKeyboardMarkup>, pub reply_markup: Option<InlineKeyboardMarkup>,
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,12 +1,10 @@
#![feature(async_await)] #![feature(async_await)]
#[macro_use]
extern crate typed_builder;
#[macro_use] #[macro_use]
extern crate derive_more; extern crate derive_more;
#[macro_use] #[macro_use]
extern crate serde; extern crate serde;
#[macro_use]
extern crate typed_builder;
mod core; mod core;