qbit_api_rs/api/
auth.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/auth/login`
9pub struct Login {
10    pub f: types::auth::LoginForm,
11}
12
13#[async_trait]
14impl Endpoint for Login {
15    type Query = ();
16    type Form = types::auth::LoginForm;
17    type Response = String;
18    fn relative_path(&self) -> Cow<str> {
19        "/api/v2/auth/login".into()
20    }
21    fn method(&self) -> reqwest::Method {
22        Method::POST
23    }
24    fn form(&self) -> Option<&Self::Form> {
25        Some(&self.f)
26    }
27    fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
28        match status {
29            StatusCode::OK => None,
30            StatusCode::FORBIDDEN => Some(ClientError::Authentication),
31            _ => Some(ClientError::Unknown),
32        }
33    }
34    async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
35        Ok(res.text().await?)
36    }
37}
38
39/// # `/api/v2/auth/logout`
40pub struct Logout;
41
42#[async_trait]
43impl Endpoint for Logout {
44    type Query = ();
45    type Form = ();
46    type Response = String;
47    fn relative_path(&self) -> Cow<str> {
48        "/api/v2/auth/logout".into()
49    }
50    fn method(&self) -> reqwest::Method {
51        Method::POST
52    }
53    fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
54        match status {
55            StatusCode::OK => None,
56            StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
57            _ => Some(ClientError::Unknown),
58        }
59    }
60    async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
61        Ok(res.text().await?)
62    }
63}