1use super::Endpoint;
2use crate::error::ClientError;
3use crate::types;
4use async_trait::async_trait;
5use reqwest::{Method, StatusCode};
6use std::borrow::Cow;
7
8pub struct Maindata {
10 pub q: types::sync::MaindataQuery,
11}
12
13#[async_trait]
14impl Endpoint for Maindata {
15 type Query = types::sync::MaindataQuery;
16 type Form = ();
17 type Response = types::sync::MaindataResponse;
18 fn relative_path(&self) -> Cow<str> {
19 "/api/v2/sync/maindata".into()
20 }
21 fn query(&self) -> Option<&Self::Query> {
22 Some(&self.q)
23 }
24 fn method(&self) -> reqwest::Method {
25 Method::POST
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::sync::MaindataResponse>().await?)
36 }
37}
38
39pub struct TorrentPeers {
41 pub q: types::sync::TorrentPeersQuery,
42}
43
44#[async_trait]
45impl Endpoint for TorrentPeers {
46 type Query = types::sync::TorrentPeersQuery;
47 type Form = ();
48 type Response = types::sync::TorrentPeersResponse;
49 fn relative_path(&self) -> Cow<str> {
50 "/api/v2/sync/torrentPeers".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 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
63 hash: self.q.hash.clone(),
64 }),
65 _ => Some(ClientError::Unknown),
66 }
67 }
68 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
69 Ok(res.json::<types::sync::TorrentPeersResponse>().await?)
70 }
71}