qbit_api_rs/api/
transfer.rs1use 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 Info;
10
11#[async_trait]
12impl Endpoint for Info {
13 type Query = ();
14 type Form = ();
15 type Response = types::transfer::InfoResponse;
16 fn relative_path(&self) -> Cow<str> {
17 "/api/v2/transfer/info".into()
18 }
19 fn method(&self) -> reqwest::Method {
20 Method::GET
21 }
22 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
23 match status {
24 StatusCode::OK => None,
25 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
26 _ => Some(ClientError::Unknown),
27 }
28 }
29 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
30 Ok(res.json::<types::transfer::InfoResponse>().await?)
31 }
32}
33
34pub struct SpeedLimitsMode;
36
37#[async_trait]
38impl Endpoint for SpeedLimitsMode {
39 type Query = ();
40 type Form = ();
41 type Response = types::transfer::SpeedLimitsModeResponse;
42 fn relative_path(&self) -> Cow<str> {
43 "/api/v2/transfer/speedLimitsMode".into()
44 }
45 fn method(&self) -> reqwest::Method {
46 Method::GET
47 }
48 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
49 match status {
50 StatusCode::OK => None,
51 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
52 _ => Some(ClientError::Unknown),
53 }
54 }
55 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
56 Ok(res
57 .json::<types::transfer::SpeedLimitsModeResponse>()
58 .await?)
59 }
60}
61
62pub struct ToggleSpeedLimitsMode;
64
65#[async_trait]
66impl Endpoint for ToggleSpeedLimitsMode {
67 type Query = ();
68 type Form = ();
69 type Response = String;
70 fn relative_path(&self) -> Cow<str> {
71 "/api/v2/transfer/toggleSpeedLimitsMode".into()
72 }
73 fn method(&self) -> reqwest::Method {
74 Method::POST
75 }
76 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
77 match status {
78 StatusCode::OK => None,
79 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
80 _ => Some(ClientError::Unknown),
81 }
82 }
83 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
84 Ok(res.text().await?)
85 }
86}
87
88pub struct DownloadLimit;
90
91#[async_trait]
92impl Endpoint for DownloadLimit {
93 type Query = ();
94 type Form = ();
95 type Response = String;
96 fn relative_path(&self) -> Cow<str> {
97 "/api/v2/transfer/downloadLimit".into()
98 }
99 fn method(&self) -> reqwest::Method {
100 Method::GET
101 }
102 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
103 match status {
104 StatusCode::OK => None,
105 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
106 _ => Some(ClientError::Unknown),
107 }
108 }
109 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
110 Ok(res.text().await?)
111 }
112}
113
114pub struct SetDownloadLimit {
116 pub f: types::transfer::SetDownloadLimitForm,
117}
118
119#[async_trait]
120impl Endpoint for SetDownloadLimit {
121 type Query = ();
122 type Form = types::transfer::SetDownloadLimitForm;
123 type Response = String;
124 fn relative_path(&self) -> Cow<str> {
125 "/api/v2/transfer/setDownloadLimit".into()
126 }
127 fn form(&self) -> Option<&Self::Form> {
128 Some(&self.f)
129 }
130 fn method(&self) -> reqwest::Method {
131 Method::POST
132 }
133 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
134 match status {
135 StatusCode::OK => None,
136 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
137 _ => Some(ClientError::Unknown),
138 }
139 }
140 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
141 Ok(res.text().await?)
142 }
143}
144
145pub struct UploadLimit;
147
148#[async_trait]
149impl Endpoint for UploadLimit {
150 type Query = ();
151 type Form = ();
152 type Response = String;
153 fn relative_path(&self) -> Cow<str> {
154 "/api/v2/transfer/uploadLimit".into()
155 }
156 fn method(&self) -> reqwest::Method {
157 Method::GET
158 }
159 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
160 match status {
161 StatusCode::OK => None,
162 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
163 _ => Some(ClientError::Unknown),
164 }
165 }
166 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
167 Ok(res.text().await?)
168 }
169}
170
171pub struct SetUploadLimit {
173 pub f: types::transfer::SetUploadLimitForm,
174}
175
176#[async_trait]
177impl Endpoint for SetUploadLimit {
178 type Query = ();
179 type Form = types::transfer::SetUploadLimitForm;
180 type Response = String;
181 fn relative_path(&self) -> Cow<str> {
182 "/api/v2/transfer/setUploadLimit".into()
183 }
184 fn form(&self) -> Option<&Self::Form> {
185 Some(&self.f)
186 }
187 fn method(&self) -> reqwest::Method {
188 Method::POST
189 }
190 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
191 match status {
192 StatusCode::OK => None,
193 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
194 _ => Some(ClientError::Unknown),
195 }
196 }
197 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
198 Ok(res.text().await?)
199 }
200}
201
202pub struct BanPeers {
204 pub f: types::transfer::BanPeersForm,
205}
206
207#[async_trait]
208impl Endpoint for BanPeers {
209 type Query = ();
210 type Form = types::transfer::BanPeersForm;
211 type Response = String;
212 fn relative_path(&self) -> Cow<str> {
213 "/api/v2/transfer/banPeers".into()
214 }
215 fn form(&self) -> Option<&Self::Form> {
216 Some(&self.f)
217 }
218 fn method(&self) -> reqwest::Method {
219 Method::POST
220 }
221 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
222 match status {
223 StatusCode::OK => None,
224 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
225 _ => Some(ClientError::Unknown),
226 }
227 }
228 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
229 Ok(res.text().await?)
230 }
231}