telegram_bot_async_raw/requests/_base/
http.rs

1use crate::url::TELEGRAM_URL;
2
3#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
4pub enum RequestUrl {
5    Method(&'static str),
6}
7
8impl RequestUrl {
9    pub fn method(method: &'static str) -> Self {
10        RequestUrl::Method(method)
11    }
12
13    pub fn url(&self, url: Option<&str>, token: &str) -> String {
14        match *self {
15            RequestUrl::Method(method) => {
16                format!("{}bot{}/{}", url.unwrap_or(TELEGRAM_URL), token, method)
17            }
18        }
19    }
20}
21
22#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
23pub enum Method {
24    Get,
25    Post,
26}
27
28#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
29pub enum Body {
30    Empty,
31    Json(Vec<u8>),
32}
33
34#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
35pub struct HttpRequest {
36    pub url: RequestUrl,
37    pub method: Method,
38    pub body: Body,
39}
40
41#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
42pub struct HttpResponse {
43    pub body: Option<Vec<u8>>,
44}