From 65f153734da058c3d769431e3fefaf8cc4660b6a Mon Sep 17 00:00:00 2001 From: Temirkhan Myrzamadi Date: Mon, 2 Sep 2019 17:10:55 +0600 Subject: [PATCH] Make all fields of all the types public --- src/core/network/mod.rs | 13 ++- src/core/requests/get_me.rs | 5 +- src/core/requests/send_message.rs | 8 +- src/core/types/answer_pre_checkout_query.rs | 6 +- src/core/types/answer_shipping_query.rs | 9 +- src/core/types/chat.rs | 29 +++--- src/core/types/chat_permissions.rs | 16 ++-- src/core/types/chat_photo.rs | 4 +- src/core/types/document.rs | 10 +-- src/core/types/invoice.rs | 10 +-- src/core/types/label_price.rs | 4 +- src/core/types/message.rs | 97 +++++++++++---------- src/core/types/mod.rs | 5 +- src/core/types/order_info.rs | 9 +- src/core/types/pre_checkout_query.rs | 17 ++-- src/core/types/send_invoice.rs | 47 +++++----- src/core/types/shipping_address.rs | 12 +-- src/core/types/shipping_option.rs | 7 +- src/core/types/shipping_query.rs | 11 +-- src/core/types/successful_payment.rs | 15 ++-- src/core/types/user.rs | 12 +-- src/lib.rs | 6 +- 22 files changed, 184 insertions(+), 168 deletions(-) diff --git a/src/core/network/mod.rs b/src/core/network/mod.rs index 6db2da67..07d90391 100644 --- a/src/core/network/mod.rs +++ b/src/core/network/mod.rs @@ -1,4 +1,3 @@ -use super::requests::Request; use apply::Apply; use futures::compat::Future01CompatExt; use reqwest::r#async::Client; @@ -6,6 +5,8 @@ use reqwest::StatusCode; use serde::de::DeserializeOwned; use serde_json::Value; +use super::requests::Request; + const TELEGRAM_API_URL: &str = "https://api.telegram.org"; fn method_url(base: &str, token: &str, method_name: &str) -> String { @@ -43,7 +44,11 @@ pub async fn request>( request: R, ) -> ResponseResult { 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| { if let Some(params) = request.params() { request_builder.multipart(params) @@ -84,7 +89,7 @@ mod tests { let url = method_url( TELEGRAM_API_URL, "535362388:AAF7-g0gYncWnm5IyfZlpPRqRRv6kNAGlao", - "methodName" + "methodName", ); assert_eq!( @@ -98,7 +103,7 @@ mod tests { let url = file_url( TELEGRAM_API_URL, "535362388:AAF7-g0gYncWnm5IyfZlpPRqRRv6kNAGlao", - "AgADAgADyqoxG2g8aEsu_KjjVsGF4-zetw8ABAEAAwIAA20AA_8QAwABFgQ" + "AgADAgADyqoxG2g8aEsu_KjjVsGF4-zetw8ABAEAAwIAA20AA_8QAwABFgQ", ); assert_eq!( diff --git a/src/core/requests/get_me.rs b/src/core/requests/get_me.rs index e14ed977..d72f5ced 100644 --- a/src/core/requests/get_me.rs +++ b/src/core/requests/get_me.rs @@ -1,8 +1,9 @@ -use super::Request; - use reqwest::r#async::multipart::Form; + use crate::core::types::User; +use super::Request; + #[derive(Debug, Constructor, PartialEq, Eq)] pub struct GetMe { token: String, diff --git a/src/core/requests/send_message.rs b/src/core/requests/send_message.rs index d0855ba9..fd6995ec 100644 --- a/src/core/requests/send_message.rs +++ b/src/core/requests/send_message.rs @@ -1,7 +1,8 @@ -use super::{ChatId, Request}; +use reqwest::r#async::multipart::Form; + use crate::core::types::Message; -use reqwest::r#async::multipart::Form; +use super::{ChatId, Request}; #[derive(Debug, TypedBuilder, PartialEq, Eq)] pub struct SendMessage { @@ -10,7 +11,8 @@ pub struct SendMessage { text: String, #[builder(default)] - parse_mode: Option, // TODO: enum + parse_mode: Option, + // TODO: enum #[builder(default)] disable_web_page_preview: Option, #[builder(default)] diff --git a/src/core/types/answer_pre_checkout_query.rs b/src/core/types/answer_pre_checkout_query.rs index 67e14daa..42a9f680 100644 --- a/src/core/types/answer_pre_checkout_query.rs +++ b/src/core/types/answer_pre_checkout_query.rs @@ -2,7 +2,7 @@ use serde::Deserialize; #[derive(Debug, Deserialize)] pub struct AnswerPreCheckoutQuery { - pre_checkout_query_id: String, - ok: bool, - error_message: Option, + pub pre_checkout_query_id: String, + pub ok: bool, + pub error_message: Option, } diff --git a/src/core/types/answer_shipping_query.rs b/src/core/types/answer_shipping_query.rs index 5feb1859..6d89dfd7 100644 --- a/src/core/types/answer_shipping_query.rs +++ b/src/core/types/answer_shipping_query.rs @@ -1,10 +1,11 @@ use serde::Deserialize; + use crate::core::types::ShippingOption; #[derive(Debug, Deserialize)] pub struct AnswerShippingQuery { - shipping_query_id: String, - ok: bool, - shipping_options: Option>, - error_message: Option, + pub shipping_query_id: String, + pub ok: bool, + pub shipping_options: Option>, + pub error_message: Option, } diff --git a/src/core/types/chat.rs b/src/core/types/chat.rs index d7987291..9b05f39e 100644 --- a/src/core/types/chat.rs +++ b/src/core/types/chat.rs @@ -1,19 +1,20 @@ use serde::Deserialize; -use crate::core::types::{ChatPhoto, ChatPermissions, Message}; + +use crate::core::types::{ChatPermissions, ChatPhoto, Message}; #[derive(Debug, Deserialize)] pub struct Chat { - id: i64, - chat_type: String, - title: Option, - username: Option, - first_name: Option, - last_name: Option, - photo: Option, - description: Option, - invite_link: Option, - pinned_message: Option>, - permissions: Option, - sticker_set_name: Option, - can_set_sticker_set: Option, + pub id: i64, + pub chat_type: String, + pub title: Option, + pub username: Option, + pub first_name: Option, + pub last_name: Option, + pub photo: Option, + pub description: Option, + pub invite_link: Option, + pub pinned_message: Option>, + pub permissions: Option, + pub sticker_set_name: Option, + pub can_set_sticker_set: Option, } diff --git a/src/core/types/chat_permissions.rs b/src/core/types/chat_permissions.rs index 900db0d2..1b1cc56b 100644 --- a/src/core/types/chat_permissions.rs +++ b/src/core/types/chat_permissions.rs @@ -2,12 +2,12 @@ use serde::Deserialize; #[derive(Debug, Deserialize)] pub struct ChatPermissions { - can_send_messages: Option, - can_send_media_messages: Option, - can_send_polls: Option, - can_send_other_messages: Option, - can_add_web_page_previews: Option, - can_change_info: Option, - can_invite_users: Option, - can_pin_messages: Option, + pub can_send_messages: Option, + pub can_send_media_messages: Option, + pub can_send_polls: Option, + pub can_send_other_messages: Option, + pub can_add_web_page_previews: Option, + pub can_change_info: Option, + pub can_invite_users: Option, + pub can_pin_messages: Option, } diff --git a/src/core/types/chat_photo.rs b/src/core/types/chat_photo.rs index c40c34b8..d056e9e4 100644 --- a/src/core/types/chat_photo.rs +++ b/src/core/types/chat_photo.rs @@ -2,6 +2,6 @@ use serde::Deserialize; #[derive(Debug, Deserialize)] pub struct ChatPhoto { - small_file_id: String, - big_file_id: String, + pub small_file_id: String, + pub big_file_id: String, } diff --git a/src/core/types/document.rs b/src/core/types/document.rs index 8f1ceee1..18d9a1f8 100644 --- a/src/core/types/document.rs +++ b/src/core/types/document.rs @@ -2,9 +2,9 @@ use serde::Deserialize; #[derive(Debug, Deserialize)] pub struct Document { - file_id: String, - thumb: Option, - file_name: Option, - mime_type: Option, - file_size: Option, + pub file_id: String, + pub thumb: Option, + pub file_name: Option, + pub mime_type: Option, + pub file_size: Option, } diff --git a/src/core/types/invoice.rs b/src/core/types/invoice.rs index b9ef12f6..6dc29710 100644 --- a/src/core/types/invoice.rs +++ b/src/core/types/invoice.rs @@ -2,9 +2,9 @@ use serde::Deserialize; #[derive(Debug, Deserialize)] pub struct Invoice { - title: String, - description: String, - start_parameter: String, - currency: String, - total_amount: i64, + pub title: String, + pub description: String, + pub start_parameter: String, + pub currency: String, + pub total_amount: i64, } diff --git a/src/core/types/label_price.rs b/src/core/types/label_price.rs index c3961039..b05bedf0 100644 --- a/src/core/types/label_price.rs +++ b/src/core/types/label_price.rs @@ -2,6 +2,6 @@ use serde::Deserialize; #[derive(Debug, Deserialize)] pub struct LabeledPrice { - label: String, - amount: i64, + pub label: String, + pub amount: i64, } diff --git a/src/core/types/message.rs b/src/core/types/message.rs index 30ff2d67..406f0366 100644 --- a/src/core/types/message.rs +++ b/src/core/types/message.rs @@ -1,53 +1,54 @@ use serde::Deserialize; -use crate::core::types::{User, Chat, Document, Invoice, SuccessfulPayment}; + +use crate::core::types::{Chat, Document, Invoice, SuccessfulPayment, User}; #[derive(Debug, Deserialize)] pub struct Message { - message_id: i64, - from: Option>, - date: i64, - chat: Chat, - forward_from: Option, - forward_from_chat: Option, - forward_from_message_id: Option, - forward_signature: Option, - forward_sender_name: Option, - forward_date: Option, - reply_to_message: Option>, - edit_date: Option, - media_group_id: Option, - author_signature: Option, - text: Option, - entities: Option>, - caption_entities: Option>, - audio: Option