mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +01:00
Make all fields of all the types public
This commit is contained in:
parent
8ca3e95193
commit
65f153734d
22 changed files with 184 additions and 168 deletions
|
@ -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<T: DeserializeOwned, R: Request<ReturnValue = T>>(
|
|||
request: R,
|
||||
) -> ResponseResult<T> {
|
||||
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!(
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<String>, // TODO: enum
|
||||
parse_mode: Option<String>,
|
||||
// TODO: enum
|
||||
#[builder(default)]
|
||||
disable_web_page_preview: Option<bool>,
|
||||
#[builder(default)]
|
||||
|
|
|
@ -2,7 +2,7 @@ use serde::Deserialize;
|
|||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct AnswerPreCheckoutQuery {
|
||||
pre_checkout_query_id: String,
|
||||
ok: bool,
|
||||
error_message: Option<String>,
|
||||
pub pre_checkout_query_id: String,
|
||||
pub ok: bool,
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
|
|
@ -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<Vec<ShippingOption>>,
|
||||
error_message: Option<String>,
|
||||
pub shipping_query_id: String,
|
||||
pub ok: bool,
|
||||
pub shipping_options: Option<Vec<ShippingOption>>,
|
||||
pub error_message: Option<String>,
|
||||
}
|
||||
|
|
|
@ -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<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>,
|
||||
pub id: i64,
|
||||
pub chat_type: String,
|
||||
pub title: Option<String>,
|
||||
pub username: Option<String>,
|
||||
pub first_name: Option<String>,
|
||||
pub last_name: Option<String>,
|
||||
pub photo: Option<ChatPhoto>,
|
||||
pub description: Option<String>,
|
||||
pub invite_link: Option<String>,
|
||||
pub pinned_message: Option<Box<Message>>,
|
||||
pub permissions: Option<ChatPermissions>,
|
||||
pub sticker_set_name: Option<String>,
|
||||
pub can_set_sticker_set: Option<bool>,
|
||||
}
|
||||
|
|
|
@ -2,12 +2,12 @@ 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>,
|
||||
pub can_send_messages: Option<bool>,
|
||||
pub can_send_media_messages: Option<bool>,
|
||||
pub can_send_polls: Option<bool>,
|
||||
pub can_send_other_messages: Option<bool>,
|
||||
pub can_add_web_page_previews: Option<bool>,
|
||||
pub can_change_info: Option<bool>,
|
||||
pub can_invite_users: Option<bool>,
|
||||
pub can_pin_messages: Option<bool>,
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ 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>,
|
||||
pub file_id: String,
|
||||
pub thumb: Option<PhotoSize>,
|
||||
pub file_name: Option<String>,
|
||||
pub mime_type: Option<String>,
|
||||
pub file_size: Option<i64>,
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -2,6 +2,6 @@ use serde::Deserialize;
|
|||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct LabeledPrice {
|
||||
label: String,
|
||||
amount: i64,
|
||||
pub label: String,
|
||||
pub amount: i64,
|
||||
}
|
||||
|
|
|
@ -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<Box<User>>,
|
||||
date: i64,
|
||||
chat: Chat,
|
||||
forward_from: Option<User>,
|
||||
forward_from_chat: Option<Chat>,
|
||||
forward_from_message_id: Option<i64>,
|
||||
forward_signature: Option<String>,
|
||||
forward_sender_name: Option<String>,
|
||||
forward_date: Option<i64>,
|
||||
reply_to_message: Option<Box<Message>>,
|
||||
edit_date: Option<i64>,
|
||||
media_group_id: Option<String>,
|
||||
author_signature: Option<String>,
|
||||
text: Option<String>,
|
||||
entities: Option<Vec<MessageEntity>>,
|
||||
caption_entities: Option<Vec<MessageEntity>>,
|
||||
audio: Option<Audio>,
|
||||
document: Option<Document>,
|
||||
animation: Option<Animation>,
|
||||
game: Option<Game>,
|
||||
photo: Option<Vec<PhotoSize>>,
|
||||
sticker: Option<Stickers>,
|
||||
video: Option<Video>,
|
||||
voice: Option<Voice>,
|
||||
video_note: Option<VideoNote>,
|
||||
caption: Option<String>,
|
||||
contact: Option<Contact>,
|
||||
location: Option<Location>,
|
||||
venue: Option<Venue>,
|
||||
poll: Option<Poll>,
|
||||
new_chat_members: Option<Vec<User>>,
|
||||
left_chat_member: Option<User>,
|
||||
new_chat_title: Option<String>,
|
||||
new_chat_photo: Option<Vec<PhotoSize>>,
|
||||
delete_chat_photo: Option<bool>,
|
||||
group_chat_created: Option<bool>,
|
||||
supergroup_chat_created: Option<bool>,
|
||||
channel_chat_created: Option<bool>,
|
||||
migrate_to_chat_id: Option<i64>,
|
||||
migrate_from_chat_id: Option<i64>,
|
||||
pinned_message: Option<Box<Message>>,
|
||||
invoice: Option<Invoice>,
|
||||
successful_payment: Option<SuccessfulPayment>,
|
||||
connected_website: Option<String>,
|
||||
passport_data: Option<PassportData>,
|
||||
reply_markup: Option<InlineKeyboardMarkup>,
|
||||
pub message_id: i64,
|
||||
pub from: Option<Box<User>>,
|
||||
pub date: i64,
|
||||
pub chat: Chat,
|
||||
pub forward_from: Option<User>,
|
||||
pub forward_from_chat: Option<Chat>,
|
||||
pub forward_from_message_id: Option<i64>,
|
||||
pub forward_signature: Option<String>,
|
||||
pub forward_sender_name: Option<String>,
|
||||
pub forward_date: Option<i64>,
|
||||
pub reply_to_message: Option<Box<Message>>,
|
||||
pub edit_date: Option<i64>,
|
||||
pub media_group_id: Option<String>,
|
||||
pub author_signature: Option<String>,
|
||||
pub text: Option<String>,
|
||||
pub entities: Option<Vec<MessageEntity>>,
|
||||
pub caption_entities: Option<Vec<MessageEntity>>,
|
||||
pub audio: Option<Audio>,
|
||||
pub document: Option<Document>,
|
||||
pub animation: Option<Animation>,
|
||||
pub game: Option<Game>,
|
||||
pub photo: Option<Vec<PhotoSize>>,
|
||||
pub sticker: Option<Stickers>,
|
||||
pub video: Option<Video>,
|
||||
pub voice: Option<Voice>,
|
||||
pub video_note: Option<VideoNote>,
|
||||
pub caption: Option<String>,
|
||||
pub contact: Option<Contact>,
|
||||
pub location: Option<Location>,
|
||||
pub venue: Option<Venue>,
|
||||
pub poll: Option<Poll>,
|
||||
pub new_chat_members: Option<Vec<User>>,
|
||||
pub left_chat_member: Option<User>,
|
||||
pub new_chat_title: Option<String>,
|
||||
pub new_chat_photo: Option<Vec<PhotoSize>>,
|
||||
pub delete_chat_photo: Option<bool>,
|
||||
pub group_chat_created: Option<bool>,
|
||||
pub supergroup_chat_created: Option<bool>,
|
||||
pub channel_chat_created: Option<bool>,
|
||||
pub migrate_to_chat_id: Option<i64>,
|
||||
pub migrate_from_chat_id: Option<i64>,
|
||||
pub pinned_message: Option<Box<Message>>,
|
||||
pub invoice: Option<Invoice>,
|
||||
pub successful_payment: Option<SuccessfulPayment>,
|
||||
pub connected_website: Option<String>,
|
||||
pub passport_data: Option<PassportData>,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
|
|
@ -2,8 +2,9 @@ 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,
|
||||
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;
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::core::types::ShippingAddress;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct OrderInfo {
|
||||
name: String,
|
||||
phone_number: String,
|
||||
email: String,
|
||||
shipping_address: ShippingAddress,
|
||||
pub name: String,
|
||||
pub phone_number: String,
|
||||
pub email: String,
|
||||
pub shipping_address: ShippingAddress,
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
use serde::Deserialize;
|
||||
use crate::core::types::{User, OrderInfo};
|
||||
|
||||
use crate::core::types::{OrderInfo, User};
|
||||
|
||||
#[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>,
|
||||
pub id: String,
|
||||
pub from: User,
|
||||
pub currency: String,
|
||||
pub total_amount: i64,
|
||||
pub invoice_payload: String,
|
||||
pub shipping_option_id: Option<String>,
|
||||
pub order_info: Option<OrderInfo>,
|
||||
}
|
||||
|
|
|
@ -1,29 +1,30 @@
|
|||
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>,
|
||||
pub chat_id: i64,
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub payload: String,
|
||||
pub provider_token: String,
|
||||
pub start_parameter: String,
|
||||
pub currency: String,
|
||||
pub prices: Vec<LabeledPrice>,
|
||||
pub provider_data: Option<String>,
|
||||
pub photo_url: Option<String>,
|
||||
pub photo_size: Option<i64>,
|
||||
pub photo_width: Option<i64>,
|
||||
pub photo_height: Option<i64>,
|
||||
pub need_name: Option<bool>,
|
||||
pub need_phone_number: Option<bool>,
|
||||
pub need_email: Option<bool>,
|
||||
pub need_shipping_address: Option<bool>,
|
||||
pub send_phone_number_to_provider: Option<bool>,
|
||||
pub send_email_to_provider: Option<bool>,
|
||||
pub is_flexible: Option<bool>,
|
||||
pub disable_notification: Option<bool>,
|
||||
pub reply_to_message_id: Option<i64>,
|
||||
pub reply_markup: Option<InlineKeyboardMarkup>,
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@ 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,
|
||||
pub country_code: String,
|
||||
pub state: String,
|
||||
pub city: String,
|
||||
pub street_line1: String,
|
||||
pub street_line2: String,
|
||||
pub post_code: String,
|
||||
}
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::core::types::LabeledPrice;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ShippingOption {
|
||||
id: i64,
|
||||
title: String,
|
||||
prices: Vec<LabeledPrice>,
|
||||
pub id: i64,
|
||||
pub title: String,
|
||||
pub prices: Vec<LabeledPrice>,
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
use serde::Deserialize;
|
||||
use crate::core::types::{User, ShippingAddress};
|
||||
|
||||
use crate::core::types::{ShippingAddress, User};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ShippingQuery {
|
||||
id: String,
|
||||
from: User,
|
||||
invoice_payload: String,
|
||||
shipping_address: ShippingAddress,
|
||||
pub id: String,
|
||||
pub from: User,
|
||||
pub invoice_payload: String,
|
||||
pub shipping_address: ShippingAddress,
|
||||
}
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
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,
|
||||
pub currency: String,
|
||||
pub total_amount: i64,
|
||||
pub invoice_payload: String,
|
||||
pub shipping_option_id: Option<String>,
|
||||
pub order_info: Option<OrderInfo>,
|
||||
pub telegram_payment_charge_id: String,
|
||||
pub provider_payment_charge_id: String,
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@ 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>,
|
||||
pub id: i64,
|
||||
pub is_bot: bool,
|
||||
pub first_name: String,
|
||||
pub last_name: Option<String>,
|
||||
pub username: Option<String>,
|
||||
pub language_code: Option<String>,
|
||||
}
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
#![feature(async_await)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate typed_builder;
|
||||
|
||||
#[macro_use]
|
||||
extern crate derive_more;
|
||||
|
||||
#[macro_use]
|
||||
extern crate serde;
|
||||
#[macro_use]
|
||||
extern crate typed_builder;
|
||||
|
||||
mod core;
|
||||
|
|
Loading…
Reference in a new issue