Prototype hing-level api.

This commit is contained in:
Waffle 2019-09-04 11:07:49 +03:00
parent 42c961b595
commit 8030fe4418
2 changed files with 47 additions and 0 deletions

46
src/bot/mod.rs Normal file
View file

@ -0,0 +1,46 @@
use reqwest::r#async::Client;
use crate::core::requests::{
get_me::GetMe,
send_message::SendMessage,
RequestInfo,
ChatId,
};
pub struct Bot {
token: String,
client: Client,
}
impl Bot {
pub fn new(token: &str) -> Self {
Bot {
token: String::from(token),
client: Client::new(),
}
}
pub fn with_client(token: &str, client: Client) -> Self {
Bot {
token: String::from(token),
client
}
}
}
/// Telegram functions
impl Bot {
pub fn get_me(&self) -> GetMe {
GetMe::new(RequestInfo { token: &self.token, client: &self.client })
}
pub fn send_message<C, T>(&self, chat_id: C, text: T) -> SendMessage
where C: Into<ChatId>, T: Into<String>
{
SendMessage::new(
RequestInfo { token: &self.token, client: &self.client },
chat_id.into(),
text.into(),
)
}
}

View file

@ -4,3 +4,4 @@ extern crate derive_more;
extern crate serde; extern crate serde;
pub mod core; pub mod core;
pub mod bot;