qbit_api_rs/api/
mod.rs

1pub mod app;
2pub mod auth;
3pub mod log;
4pub mod search;
5pub mod sync;
6pub mod torrents;
7pub mod transfer;
8
9use crate::error::ClientError;
10use async_trait::async_trait;
11use serde::{de::DeserializeOwned, Serialize};
12use std::borrow::Cow;
13
14#[async_trait]
15pub trait Endpoint {
16    /// define type of query, form and response
17    type Query: Serialize;
18    type Form: Serialize;
19    type Response: DeserializeOwned;
20    /// The endpoint relative path. Must start with a `/`
21    fn relative_path(&self) -> Cow<str>;
22    /// The query to be used when calling this endpoint.
23    fn query(&self) -> Option<&Self::Query> {
24        None
25    }
26    /// The form body to be used when calling this endpoint.
27    fn form(&self) -> Option<&Self::Form> {
28        None
29    }
30    /// The multipart to be used when calling this endpoint.
31    fn multipart(&self) -> Option<reqwest::multipart::Form> {
32        None
33    }
34    /// The request method of this endpoint. either POST or GET.
35    fn method(&self) -> reqwest::Method {
36        reqwest::Method::POST
37    }
38    /// Check the status code
39    fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError>;
40    /// Deserialize the response
41    async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError>;
42}