qbit_api_rs/api/
log.rs

1use super::Endpoint;
2use crate::error::ClientError;
3use crate::types;
4use async_trait::async_trait;
5use reqwest::{Method, StatusCode};
6use std::borrow::Cow;
7
8/// # `/api/v2/log/main`
9pub struct Main {
10    pub q: types::log::MainQuery,
11}
12
13#[async_trait]
14impl Endpoint for Main {
15    type Query = types::log::MainQuery;
16    type Form = ();
17    type Response = types::log::MainResponse;
18    fn relative_path(&self) -> Cow<str> {
19        "/api/v2/log/main".into()
20    }
21    fn query(&self) -> Option<&Self::Query> {
22        Some(&self.q)
23    }
24    fn method(&self) -> reqwest::Method {
25        Method::GET
26    }
27    fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
28        match status {
29            StatusCode::OK => None,
30            StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
31            _ => Some(ClientError::Unknown),
32        }
33    }
34    async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
35        Ok(res.json::<types::log::MainResponse>().await?)
36    }
37}
38
39/// # `/api/v2/log/peers`
40pub struct Peers {
41    pub q: types::log::PeersQuery,
42}
43
44#[async_trait]
45impl Endpoint for Peers {
46    type Query = types::log::PeersQuery;
47    type Form = ();
48    type Response = types::log::PeersResponse;
49    fn relative_path(&self) -> Cow<str> {
50        "/api/v2/log/peers".into()
51    }
52    fn query(&self) -> Option<&Self::Query> {
53        Some(&self.q)
54    }
55    fn method(&self) -> reqwest::Method {
56        Method::GET
57    }
58    fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
59        match status {
60            StatusCode::OK => None,
61            StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
62            _ => Some(ClientError::Unknown),
63        }
64    }
65    async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
66        Ok(res.json::<types::log::PeersResponse>().await?)
67    }
68}