mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +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 reqwest::r#async::{multipart::Form, Client};
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde_json::Value;
|
||||
use reqwest::{
|
||||
r#async::{Client, multipart::Form},
|
||||
};
|
||||
use apply::Apply;
|
||||
|
||||
use crate::core::requests::{RequestError, ResponseResult};
|
||||
|
||||
|
||||
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)
|
||||
fn method_url(base: &str, token: &str, method_name: &str) -> String {
|
||||
format!(
|
||||
|
@ -31,7 +28,6 @@ fn file_url(base: &str, token: &str, file_path: &str) -> String {
|
|||
)
|
||||
}
|
||||
|
||||
|
||||
pub async fn request<T: DeserializeOwned>(
|
||||
client: &Client,
|
||||
token: &str,
|
||||
|
|
|
@ -38,8 +38,8 @@ impl FormBuilder {
|
|||
form: self.form.text(
|
||||
name.to_owned(),
|
||||
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::{network::request, network::request, types::User};
|
||||
|
||||
#[derive(Debug, Constructor)]
|
||||
pub struct GetMe {
|
||||
info: RequestInfo
|
||||
info: RequestInfo,
|
||||
}
|
||||
|
||||
impl Request for GetMe {
|
||||
type ReturnValue = User;
|
||||
|
||||
fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>> {
|
||||
Box::new(async move {
|
||||
request(&self.info.client, &self.info.token, "getMe", None).await
|
||||
})
|
||||
Box::new(async move { request(&self.info.client, &self.info.token, "getMe", None).await })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
use std::future::Future;
|
||||
|
||||
use serde::de::DeserializeOwned;
|
||||
use reqwest::r#async::Client;
|
||||
use reqwest::StatusCode;
|
||||
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
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::{network::request, network::request, types::Message};
|
||||
|
||||
#[derive(Debug, TypedBuilder)]
|
||||
pub struct SendMessage {
|
||||
|
@ -36,7 +23,6 @@ pub struct SendMessage {
|
|||
impl Request for SendMessage {
|
||||
type ReturnValue = Message;
|
||||
|
||||
|
||||
fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>> {
|
||||
Box::new(async move {
|
||||
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())
|
||||
.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 crate::core::types::user::User;
|
||||
|
||||
#[derive(Debug, Deserealize)]
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use serde::Deserialize;
|
||||
|
||||
use crate::core::types::InputFile;
|
||||
|
||||
pub enum InputMedia {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::core::parse_mode::ParseMode;
|
||||
|
||||
pub enum InputMessageContent {
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
// use serde::Deserialize;
|
||||
|
||||
use crate::core::types::{
|
||||
Animation, Audio, Chat, Contact,
|
||||
Document, Game, Invoice, InlineKeyboardMarkup,
|
||||
PhotoSize, MessageEntity, Location, PassportData, Poll,
|
||||
Sticker, SuccessfulPayment,
|
||||
User, Video, VideoNote, Venue, Voice,
|
||||
Animation, Audio, Chat, Contact, Document, Game, InlineKeyboardMarkup, Invoice, Location,
|
||||
MessageEntity, PassportData, PhotoSize, Poll, Sticker, SuccessfulPayment, User, Venue, Video,
|
||||
VideoNote, Voice,
|
||||
};
|
||||
|
||||
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use crate::core::types::User;
|
||||
|
||||
|
||||
#[derive(Deserialize, Debug, PartialEq, Hash, Eq)]
|
||||
pub struct MessageEntity {
|
||||
#[serde(flatten)]
|
||||
|
@ -13,10 +12,19 @@ pub struct MessageEntity {
|
|||
#[serde(rename_all = "snake_case")]
|
||||
#[serde(tag = "type")]
|
||||
pub enum MessageEntityKind {
|
||||
Mention, Hashtag, Cashtag, BotCommand, Url, Email, PhoneNumber,
|
||||
Bold, Italic, Code, Pre,
|
||||
Mention,
|
||||
Hashtag,
|
||||
Cashtag,
|
||||
BotCommand,
|
||||
Url,
|
||||
Email,
|
||||
PhoneNumber,
|
||||
Bold,
|
||||
Italic,
|
||||
Code,
|
||||
Pre,
|
||||
TextLink { url: String },
|
||||
TextMention { user: User }
|
||||
TextMention { user: User },
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -25,12 +33,13 @@ fn recursive_kind() {
|
|||
|
||||
assert_eq!(
|
||||
MessageEntity {
|
||||
kind: MessageEntityKind::TextLink { url: "ya.ru".into() },
|
||||
kind: MessageEntityKind::TextLink {
|
||||
url: "ya.ru".into()
|
||||
},
|
||||
offset: 1,
|
||||
length: 2
|
||||
},
|
||||
from_str::<MessageEntity>(
|
||||
r#"{"type":"text_link","url":"ya.ru","offset":1,"length":2}"#
|
||||
).unwrap()
|
||||
from_str::<MessageEntity>(r#"{"type":"text_link","url":"ya.ru","offset":1,"length":2}"#)
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,26 +1,11 @@
|
|||
mod not_implemented_types;
|
||||
use self::not_implemented_types::*;
|
||||
|
||||
|
||||
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,
|
||||
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,
|
||||
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, 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,
|
||||
};
|
||||
|
||||
|
@ -34,6 +19,7 @@ mod invoice;
|
|||
mod label_price;
|
||||
mod message;
|
||||
mod message_entity;
|
||||
mod not_implemented_types;
|
||||
mod order_info;
|
||||
mod pre_checkout_query;
|
||||
mod send_invoice;
|
||||
|
|
Loading…
Reference in a new issue