mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
Format the sources
This commit is contained in:
parent
e9ebd62993
commit
3d6479be62
11 changed files with 47 additions and 75 deletions
|
@ -1,16 +1,13 @@
|
||||||
|
use apply::Apply;
|
||||||
use futures::compat::Future01CompatExt;
|
use futures::compat::Future01CompatExt;
|
||||||
|
use reqwest::r#async::{multipart::Form, Client};
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use reqwest::{
|
|
||||||
r#async::{Client, multipart::Form},
|
|
||||||
};
|
|
||||||
use apply::Apply;
|
|
||||||
use crate::core::requests::{RequestError, ResponseResult};
|
use crate::core::requests::{RequestError, ResponseResult};
|
||||||
|
|
||||||
|
|
||||||
const TELEGRAM_API_URL: &str = "https://api.telegram.org";
|
const TELEGRAM_API_URL: &str = "https://api.telegram.org";
|
||||||
|
|
||||||
|
|
||||||
/// Create url for macking requests, see [telegram docs](https://core.telegram.org/bots/api#making-requests)
|
/// Create url for macking requests, see [telegram docs](https://core.telegram.org/bots/api#making-requests)
|
||||||
fn method_url(base: &str, token: &str, method_name: &str) -> String {
|
fn method_url(base: &str, token: &str, method_name: &str) -> String {
|
||||||
format!(
|
format!(
|
||||||
|
@ -31,7 +28,6 @@ fn file_url(base: &str, token: &str, file_path: &str) -> String {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub async fn request<T: DeserializeOwned>(
|
pub async fn request<T: DeserializeOwned>(
|
||||||
client: &Client,
|
client: &Client,
|
||||||
token: &str,
|
token: &str,
|
||||||
|
|
|
@ -38,8 +38,8 @@ impl FormBuilder {
|
||||||
form: self.form.text(
|
form: 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"),
|
||||||
)
|
),
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,26 +1,15 @@
|
||||||
use crate::core::{
|
|
||||||
types::User,
|
|
||||||
network::{
|
|
||||||
request,
|
|
||||||
},
|
|
||||||
requests::{
|
|
||||||
Request, RequestInfo, RequestFuture,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
use crate::core::requests::ResponseResult;
|
use crate::core::requests::ResponseResult;
|
||||||
|
use crate::core::{network::request, network::request, types::User};
|
||||||
|
|
||||||
#[derive(Debug, Constructor)]
|
#[derive(Debug, Constructor)]
|
||||||
pub struct GetMe {
|
pub struct GetMe {
|
||||||
info: RequestInfo
|
info: RequestInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Request for GetMe {
|
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 move {
|
Box::new(async move { request(&self.info.client, &self.info.token, "getMe", None).await })
|
||||||
request(&self.info.client, &self.info.token, "getMe", None).await
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use std::future::Future;
|
use std::future::Future;
|
||||||
|
|
||||||
use serde::de::DeserializeOwned;
|
|
||||||
use reqwest::r#async::Client;
|
use reqwest::r#async::Client;
|
||||||
use reqwest::StatusCode;
|
use reqwest::StatusCode;
|
||||||
|
use serde::de::DeserializeOwned;
|
||||||
|
|
||||||
mod form_builder;
|
mod form_builder;
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,5 @@
|
||||||
use crate::core::{
|
|
||||||
types::Message,
|
|
||||||
network::{
|
|
||||||
request,
|
|
||||||
},
|
|
||||||
requests::{
|
|
||||||
form_builder::FormBuilder,
|
|
||||||
ChatId,
|
|
||||||
Request,
|
|
||||||
RequestInfo,
|
|
||||||
RequestFuture,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
use crate::core::requests::ResponseResult;
|
use crate::core::requests::ResponseResult;
|
||||||
|
use crate::core::{network::request, network::request, types::Message};
|
||||||
|
|
||||||
#[derive(Debug, TypedBuilder)]
|
#[derive(Debug, TypedBuilder)]
|
||||||
pub struct SendMessage {
|
pub struct SendMessage {
|
||||||
|
@ -36,7 +23,6 @@ pub struct SendMessage {
|
||||||
impl Request for SendMessage {
|
impl Request for SendMessage {
|
||||||
type ReturnValue = Message;
|
type ReturnValue = Message;
|
||||||
|
|
||||||
|
|
||||||
fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>> {
|
fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>> {
|
||||||
Box::new(async move {
|
Box::new(async move {
|
||||||
let params = FormBuilder::new()
|
let params = FormBuilder::new()
|
||||||
|
@ -51,7 +37,13 @@ impl Request for SendMessage {
|
||||||
.add_if_some("reply_to_message_id", self.reply_to_message_id.as_ref())
|
.add_if_some("reply_to_message_id", self.reply_to_message_id.as_ref())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
request(&self.info.client, &self.info.token, "sendMessage", Some(params)).await
|
request(
|
||||||
|
&self.info.client,
|
||||||
|
&self.info.token,
|
||||||
|
"sendMessage",
|
||||||
|
Some(params),
|
||||||
|
)
|
||||||
|
.await
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::core::types::user::User;
|
use crate::core::types::user::User;
|
||||||
|
|
||||||
#[derive(Debug, Deserealize)]
|
#[derive(Debug, Deserealize)]
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use crate::core::types::InputFile;
|
use crate::core::types::InputFile;
|
||||||
|
|
||||||
pub enum InputMedia {
|
pub enum InputMedia {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use crate::core::parse_mode::ParseMode;
|
use crate::core::parse_mode::ParseMode;
|
||||||
|
|
||||||
pub enum InputMessageContent {
|
pub enum InputMessageContent {
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
// use serde::Deserialize;
|
// use serde::Deserialize;
|
||||||
|
|
||||||
use crate::core::types::{
|
use crate::core::types::{
|
||||||
Animation, Audio, Chat, Contact,
|
Animation, Audio, Chat, Contact, Document, Game, InlineKeyboardMarkup, Invoice, Location,
|
||||||
Document, Game, Invoice, InlineKeyboardMarkup,
|
MessageEntity, PassportData, PhotoSize, Poll, Sticker, SuccessfulPayment, User, Venue, Video,
|
||||||
PhotoSize, MessageEntity, Location, PassportData, Poll,
|
VideoNote, Voice,
|
||||||
Sticker, SuccessfulPayment,
|
|
||||||
User, Video, VideoNote, Venue, Voice,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
use crate::core::types::User;
|
use crate::core::types::User;
|
||||||
|
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, PartialEq, Hash, Eq)]
|
#[derive(Deserialize, Debug, PartialEq, Hash, Eq)]
|
||||||
pub struct MessageEntity {
|
pub struct MessageEntity {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
|
@ -13,10 +12,19 @@ pub struct MessageEntity {
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
pub enum MessageEntityKind {
|
pub enum MessageEntityKind {
|
||||||
Mention, Hashtag, Cashtag, BotCommand, Url, Email, PhoneNumber,
|
Mention,
|
||||||
Bold, Italic, Code, Pre,
|
Hashtag,
|
||||||
|
Cashtag,
|
||||||
|
BotCommand,
|
||||||
|
Url,
|
||||||
|
Email,
|
||||||
|
PhoneNumber,
|
||||||
|
Bold,
|
||||||
|
Italic,
|
||||||
|
Code,
|
||||||
|
Pre,
|
||||||
TextLink { url: String },
|
TextLink { url: String },
|
||||||
TextMention { user: User }
|
TextMention { user: User },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -25,12 +33,13 @@ fn recursive_kind() {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
MessageEntity {
|
MessageEntity {
|
||||||
kind: MessageEntityKind::TextLink { url: "ya.ru".into() },
|
kind: MessageEntityKind::TextLink {
|
||||||
|
url: "ya.ru".into()
|
||||||
|
},
|
||||||
offset: 1,
|
offset: 1,
|
||||||
length: 2
|
length: 2
|
||||||
},
|
},
|
||||||
from_str::<MessageEntity>(
|
from_str::<MessageEntity>(r#"{"type":"text_link","url":"ya.ru","offset":1,"length":2}"#)
|
||||||
r#"{"type":"text_link","url":"ya.ru","offset":1,"length":2}"#
|
.unwrap()
|
||||||
).unwrap()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,11 @@
|
||||||
mod not_implemented_types;
|
|
||||||
use self::not_implemented_types::*;
|
use self::not_implemented_types::*;
|
||||||
|
|
||||||
|
|
||||||
pub use self::{
|
pub use self::{
|
||||||
answer_pre_checkout_query::AnswerPreCheckoutQuery,
|
answer_pre_checkout_query::AnswerPreCheckoutQuery, answer_shipping_query::AnswerShippingQuery,
|
||||||
answer_shipping_query::AnswerShippingQuery,
|
chat::Chat, chat_permissions::ChatPermissions, chat_photo::ChatPhoto, document::Document,
|
||||||
chat::Chat,
|
invoice::Invoice, label_price::LabeledPrice, message::Message, message_entity::MessageEntity,
|
||||||
chat_permissions::ChatPermissions,
|
order_info::OrderInfo, pre_checkout_query::PreCheckoutQuery, send_invoice::SendInvoice,
|
||||||
chat_photo::ChatPhoto,
|
shipping_address::ShippingAddress, shipping_option::ShippingOption,
|
||||||
document::Document,
|
shipping_query::ShippingQuery, sticker::Sticker, successful_payment::SuccessfulPayment,
|
||||||
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,
|
user::User,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -34,6 +19,7 @@ mod invoice;
|
||||||
mod label_price;
|
mod label_price;
|
||||||
mod message;
|
mod message;
|
||||||
mod message_entity;
|
mod message_entity;
|
||||||
|
mod not_implemented_types;
|
||||||
mod order_info;
|
mod order_info;
|
||||||
mod pre_checkout_query;
|
mod pre_checkout_query;
|
||||||
mod send_invoice;
|
mod send_invoice;
|
||||||
|
|
Loading…
Reference in a new issue