1use crate::error::ClientError;
2use crate::types;
3use async_trait::async_trait;
4use reqwest::{Method, StatusCode};
5use std::borrow::Cow;
6use super::Endpoint;
7
8pub struct Info {
10 pub q: types::torrents::InfoQuery,
11}
12
13#[async_trait]
14impl Endpoint for Info {
15 type Query = types::torrents::InfoQuery;
16 type Form = ();
17 type Response = types::torrents::InfoResponse;
18 fn relative_path(&self) -> Cow<str> {
19 "/api/v2/torrents/info".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::torrents::InfoResponse>().await?)
36 }
37}
38
39pub struct Properties {
41 pub q: types::torrents::PropertiesQuery,
42}
43
44#[async_trait]
45impl Endpoint for Properties {
46 type Query = types::torrents::PropertiesQuery;
47 type Form = ();
48 type Response = types::torrents::PropertiesResponse;
49 fn relative_path(&self) -> Cow<str> {
50 "/api/v2/torrents/properties".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::torrents::PropertiesResponse>().await?)
70 }
71}
72
73pub struct Trackers {
75 pub q: types::torrents::TrackersQuery,
76}
77
78#[async_trait]
79impl Endpoint for Trackers {
80 type Query = types::torrents::TrackersQuery;
81 type Form = ();
82 type Response = types::torrents::TrackersResponse;
83 fn relative_path(&self) -> Cow<str> {
84 "/api/v2/torrents/trackers".into()
85 }
86 fn query(&self) -> Option<&Self::Query> {
87 Some(&self.q)
88 }
89 fn method(&self) -> reqwest::Method {
90 Method::GET
91 }
92 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
93 match status {
94 StatusCode::OK => None,
95 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
96 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
97 hash: self.q.hash.clone(),
98 }),
99 _ => Some(ClientError::Unknown),
100 }
101 }
102 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
103 Ok(res.json::<types::torrents::TrackersResponse>().await?)
104 }
105}
106
107pub struct Webseeds {
109 pub q: types::torrents::WebseedsQuery,
110}
111
112#[async_trait]
113impl Endpoint for Webseeds {
114 type Query = types::torrents::WebseedsQuery;
115 type Form = ();
116 type Response = types::torrents::WebseedsResponse;
117 fn relative_path(&self) -> Cow<str> {
118 "/api/v2/torrents/webseeds".into()
119 }
120 fn query(&self) -> Option<&Self::Query> {
121 Some(&self.q)
122 }
123 fn method(&self) -> reqwest::Method {
124 Method::GET
125 }
126 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
127 match status {
128 StatusCode::OK => None,
129 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
130 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
131 hash: self.q.hash.clone(),
132 }),
133 _ => Some(ClientError::Unknown),
134 }
135 }
136 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
137 Ok(res.json::<types::torrents::WebseedsResponse>().await?)
138 }
139}
140
141pub struct Files {
143 pub q: types::torrents::FilesQuery,
144}
145
146#[async_trait]
147impl Endpoint for Files {
148 type Query = types::torrents::FilesQuery;
149 type Form = ();
150 type Response = types::torrents::FilesResponse;
151 fn relative_path(&self) -> Cow<str> {
152 "/api/v2/torrents/files".into()
153 }
154 fn query(&self) -> Option<&Self::Query> {
155 Some(&self.q)
156 }
157 fn method(&self) -> reqwest::Method {
158 Method::GET
159 }
160 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
161 match status {
162 StatusCode::OK => None,
163 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
164 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
165 hash: self.q.hash.clone(),
166 }),
167 _ => Some(ClientError::Unknown),
168 }
169 }
170 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
171 Ok(res.json::<types::torrents::FilesResponse>().await?)
172 }
173}
174
175pub struct PieceStates {
177 pub q: types::torrents::PieceStatesQuery,
178}
179
180#[async_trait]
181impl Endpoint for PieceStates {
182 type Query = types::torrents::PieceStatesQuery;
183 type Form = ();
184 type Response = types::torrents::PieceStatesResponse;
185 fn relative_path(&self) -> Cow<str> {
186 "/api/v2/torrents/pieceStates".into()
187 }
188 fn query(&self) -> Option<&Self::Query> {
189 Some(&self.q)
190 }
191 fn method(&self) -> reqwest::Method {
192 Method::GET
193 }
194 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
195 match status {
196 StatusCode::OK => None,
197 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
198 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
199 hash: self.q.hash.clone(),
200 }),
201 _ => Some(ClientError::Unknown),
202 }
203 }
204 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
205 Ok(res.json::<types::torrents::PieceStatesResponse>().await?)
206 }
207}
208
209pub struct PieceHashes {
211 pub q: types::torrents::PieceHashesQuery,
212}
213
214#[async_trait]
215impl Endpoint for PieceHashes {
216 type Query = types::torrents::PieceHashesQuery;
217 type Form = ();
218 type Response = types::torrents::PieceHashesResponse;
219 fn relative_path(&self) -> Cow<str> {
220 "/api/v2/torrents/pieceHashes".into()
221 }
222 fn query(&self) -> Option<&Self::Query> {
223 Some(&self.q)
224 }
225 fn method(&self) -> reqwest::Method {
226 Method::GET
227 }
228 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
229 match status {
230 StatusCode::OK => None,
231 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
232 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
233 hash: self.q.hash.clone(),
234 }),
235 _ => Some(ClientError::Unknown),
236 }
237 }
238 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
239 Ok(res.json::<types::torrents::PieceHashesResponse>().await?)
240 }
241}
242
243pub struct Pause {
245 pub f: types::torrents::PauseForm,
246}
247
248#[async_trait]
249impl Endpoint for Pause {
250 type Query = ();
251 type Form = types::torrents::PauseForm;
252 type Response = String;
253 fn relative_path(&self) -> Cow<str> {
254 "/api/v2/torrents/pause".into()
255 }
256 fn method(&self) -> reqwest::Method {
257 Method::POST
258 }
259 fn form(&self) -> Option<&Self::Form> {
260 Some(&self.f)
261 }
262 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
263 match status {
264 StatusCode::OK => None,
265 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
266 _ => Some(ClientError::Unknown),
267 }
268 }
269 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
270 Ok(res.text().await?)
271 }
272}
273
274pub struct Resume {
276 pub f: types::torrents::ResumeForm,
277}
278
279#[async_trait]
280impl Endpoint for Resume {
281 type Query = ();
282 type Form = types::torrents::ResumeForm;
283 type Response = String;
284 fn relative_path(&self) -> Cow<str> {
285 "/api/v2/torrents/resume".into()
286 }
287 fn method(&self) -> reqwest::Method {
288 Method::POST
289 }
290 fn form(&self) -> Option<&Self::Form> {
291 Some(&self.f)
292 }
293 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
294 match status {
295 StatusCode::OK => None,
296 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
297 _ => Some(ClientError::Unknown),
298 }
299 }
300 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
301 Ok(res.text().await?)
302 }
303}
304
305pub struct Delete {
307 pub f: types::torrents::DeleteForm,
308}
309
310#[async_trait]
311impl Endpoint for Delete {
312 type Query = ();
313 type Form = types::torrents::DeleteForm;
314 type Response = String;
315 fn relative_path(&self) -> Cow<str> {
316 "/api/v2/torrents/delete".into()
317 }
318 fn method(&self) -> reqwest::Method {
319 Method::POST
320 }
321 fn form(&self) -> Option<&Self::Form> {
322 Some(&self.f)
323 }
324 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
325 match status {
326 StatusCode::OK => None,
327 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
328 _ => Some(ClientError::Unknown),
329 }
330 }
331 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
332 Ok(res.text().await?)
333 }
334}
335
336pub struct Recheck {
338 pub f: types::torrents::RecheckForm,
339}
340
341#[async_trait]
342impl Endpoint for Recheck {
343 type Query = ();
344 type Form = types::torrents::RecheckForm;
345 type Response = String;
346 fn relative_path(&self) -> Cow<str> {
347 "/api/v2/torrents/recheck".into()
348 }
349 fn method(&self) -> reqwest::Method {
350 Method::POST
351 }
352 fn form(&self) -> Option<&Self::Form> {
353 Some(&self.f)
354 }
355 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
356 match status {
357 StatusCode::OK => None,
358 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
359 _ => Some(ClientError::Unknown),
360 }
361 }
362 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
363 Ok(res.text().await?)
364 }
365}
366
367pub struct Reannounce {
369 pub f: types::torrents::ReannounceForm,
370}
371
372#[async_trait]
373impl Endpoint for Reannounce {
374 type Query = ();
375 type Form = types::torrents::ReannounceForm;
376 type Response = String;
377 fn relative_path(&self) -> Cow<str> {
378 "/api/v2/torrents/reannounce".into()
379 }
380 fn method(&self) -> reqwest::Method {
381 Method::POST
382 }
383 fn form(&self) -> Option<&Self::Form> {
384 Some(&self.f)
385 }
386 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
387 match status {
388 StatusCode::OK => None,
389 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
390 _ => Some(ClientError::Unknown),
391 }
392 }
393 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
394 Ok(res.text().await?)
395 }
396}
397
398pub struct Add {
400 pub mp: types::torrents::AddMultipart,
401}
402
403#[async_trait]
404impl Endpoint for Add {
405 type Query = ();
406 type Form = ();
407 type Response = String;
408 fn relative_path(&self) -> Cow<str> {
409 "/api/v2/torrents/add".into()
410 }
411 fn method(&self) -> reqwest::Method {
412 Method::POST
413 }
414 fn multipart(&self) -> Option<reqwest::multipart::Form> {
415 self.mp.to_multipart_form().ok()
416 }
417 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
418 match status {
419 StatusCode::OK => None,
420 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
421 StatusCode::UNSUPPORTED_MEDIA_TYPE => Some(ClientError::TorrentFileInvalid {
422 path: {
423 let paths: Vec<String> = self.mp.torrents.iter().map(|x| x.0.clone()).collect();
424 paths.join(", ")
425 },
426 }),
427 _ => Some(ClientError::Unknown),
428 }
429 }
430 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
431 Ok(res.text().await?)
432 }
433}
434
435pub struct AddTrackers {
437 pub f: types::torrents::AddTrackersForm,
438}
439
440#[async_trait]
441impl Endpoint for AddTrackers {
442 type Query = ();
443 type Form = types::torrents::AddTrackersForm;
444 type Response = String;
445 fn relative_path(&self) -> Cow<str> {
446 "/api/v2/torrents/addTrackers".into()
447 }
448 fn method(&self) -> reqwest::Method {
449 Method::POST
450 }
451 fn form(&self) -> Option<&Self::Form> {
452 Some(&self.f)
453 }
454 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
455 match status {
456 StatusCode::OK => None,
457 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
458 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
459 hash: self.f.hash.clone(),
460 }),
461 _ => Some(ClientError::Unknown),
462 }
463 }
464 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
465 Ok(res.text().await?)
466 }
467}
468
469pub struct EditTracker {
471 pub f: types::torrents::EditTrackerForm,
472}
473
474#[async_trait]
475impl Endpoint for EditTracker {
476 type Query = ();
477 type Form = types::torrents::EditTrackerForm;
478 type Response = String;
479 fn relative_path(&self) -> Cow<str> {
480 "/api/v2/torrents/editTracker".into()
481 }
482 fn method(&self) -> reqwest::Method {
483 Method::POST
484 }
485 fn form(&self) -> Option<&Self::Form> {
486 Some(&self.f)
487 }
488 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
489 match status {
490 StatusCode::OK => None,
491 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
492 StatusCode::BAD_REQUEST => Some(ClientError::BadRequest(format!(
493 "{} is not a valid URL",
494 self.f.new_url
495 ))),
496 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
497 hash: self.f.hash.clone(),
498 }),
499 StatusCode::CONFLICT => Some(ClientError::Conflict(format!(
500 "{} not found or {} already exists.",
501 self.f.orig_url, self.f.new_url
502 ))),
503 _ => Some(ClientError::Unknown),
504 }
505 }
506 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
507 Ok(res.text().await?)
508 }
509}
510
511pub struct RemoveTrackers {
513 pub f: types::torrents::RemoveTrackersForm,
514}
515
516#[async_trait]
517impl Endpoint for RemoveTrackers {
518 type Query = ();
519 type Form = types::torrents::RemoveTrackersForm;
520 type Response = String;
521 fn relative_path(&self) -> Cow<str> {
522 "/api/v2/torrents/removeTrackers".into()
523 }
524 fn method(&self) -> reqwest::Method {
525 Method::POST
526 }
527 fn form(&self) -> Option<&Self::Form> {
528 Some(&self.f)
529 }
530 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
531 match status {
532 StatusCode::OK => None,
533 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
534 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
535 hash: self.f.hash.clone(),
536 }),
537 StatusCode::CONFLICT => Some(ClientError::Conflict(format!(
538 "all URL ({}) not found.",
539 self.f.urls.join(", ")
540 ))),
541 _ => Some(ClientError::Unknown),
542 }
543 }
544 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
545 Ok(res.text().await?)
546 }
547}
548
549pub struct AddPeers {
551 pub f: types::torrents::AddPeersForm,
552}
553
554#[async_trait]
555impl Endpoint for AddPeers {
556 type Query = ();
557 type Form = types::torrents::AddPeersForm;
558 type Response = String;
559 fn relative_path(&self) -> Cow<str> {
560 "/api/v2/torrents/addPeers".into()
561 }
562 fn method(&self) -> reqwest::Method {
563 Method::POST
564 }
565 fn form(&self) -> Option<&Self::Form> {
566 Some(&self.f)
567 }
568 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
569 match status {
570 StatusCode::OK => None,
571 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
572 StatusCode::BAD_REQUEST => Some(ClientError::BadRequest(format!(
573 "All peers ({}) are not valid",
574 self.f.peers.join(", ")
575 ))),
576 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
577 hash: self.f.hashes.join(", "),
578 }),
579
580 _ => Some(ClientError::Unknown),
581 }
582 }
583 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
584 Ok(res.text().await?)
585 }
586}
587
588pub struct IncreasePrio {
590 pub f: types::torrents::IncreasePrioForm,
591}
592
593#[async_trait]
594impl Endpoint for IncreasePrio {
595 type Query = ();
596 type Form = types::torrents::IncreasePrioForm;
597 type Response = String;
598 fn relative_path(&self) -> Cow<str> {
599 "/api/v2/torrents/increasePrio".into()
600 }
601 fn method(&self) -> reqwest::Method {
602 Method::POST
603 }
604 fn form(&self) -> Option<&Self::Form> {
605 Some(&self.f)
606 }
607 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
608 match status {
609 StatusCode::OK => None,
610 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
611 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
612 hash: self.f.hashes.join(", "),
613 }),
614 StatusCode::CONFLICT => Some(ClientError::Conflict(
615 "Torrent queueing is not enabled.".to_string(),
616 )),
617 _ => Some(ClientError::Unknown),
618 }
619 }
620 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
621 Ok(res.text().await?)
622 }
623}
624
625pub struct DecreasePrio {
627 pub f: types::torrents::DecreasePrioForm,
628}
629
630#[async_trait]
631impl Endpoint for DecreasePrio {
632 type Query = ();
633 type Form = types::torrents::DecreasePrioForm;
634 type Response = String;
635 fn relative_path(&self) -> Cow<str> {
636 "/api/v2/torrents/decreasePrio".into()
637 }
638 fn method(&self) -> reqwest::Method {
639 Method::POST
640 }
641 fn form(&self) -> Option<&Self::Form> {
642 Some(&self.f)
643 }
644 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
645 match status {
646 StatusCode::OK => None,
647 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
648 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
649 hash: self.f.hashes.join(", "),
650 }),
651 StatusCode::CONFLICT => Some(ClientError::Conflict(
652 "Torrent queueing is not enabled.".to_string(),
653 )),
654 _ => Some(ClientError::Unknown),
655 }
656 }
657 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
658 Ok(res.text().await?)
659 }
660}
661
662pub struct TopPrio {
664 pub f: types::torrents::TopPrioForm,
665}
666
667#[async_trait]
668impl Endpoint for TopPrio {
669 type Query = ();
670 type Form = types::torrents::TopPrioForm;
671 type Response = String;
672 fn relative_path(&self) -> Cow<str> {
673 "/api/v2/torrents/topPrio".into()
674 }
675 fn method(&self) -> reqwest::Method {
676 Method::POST
677 }
678 fn form(&self) -> Option<&Self::Form> {
679 Some(&self.f)
680 }
681 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
682 match status {
683 StatusCode::OK => None,
684 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
685 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
686 hash: self.f.hashes.join(", "),
687 }),
688 StatusCode::CONFLICT => Some(ClientError::Conflict(
689 "Torrent queueing is not enabled.".to_string(),
690 )),
691 _ => Some(ClientError::Unknown),
692 }
693 }
694 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
695 Ok(res.text().await?)
696 }
697}
698
699pub struct BottomPrio {
701 pub f: types::torrents::BottomPrioForm,
702}
703
704#[async_trait]
705impl Endpoint for BottomPrio {
706 type Query = ();
707 type Form = types::torrents::BottomPrioForm;
708 type Response = String;
709 fn relative_path(&self) -> Cow<str> {
710 "/api/v2/torrents/bottomPrio".into()
711 }
712 fn method(&self) -> reqwest::Method {
713 Method::POST
714 }
715 fn form(&self) -> Option<&Self::Form> {
716 Some(&self.f)
717 }
718 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
719 match status {
720 StatusCode::OK => None,
721 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
722 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
723 hash: self.f.hashes.join(", "),
724 }),
725 StatusCode::CONFLICT => Some(ClientError::Conflict(
726 "Torrent queueing is not enabled.".to_string(),
727 )),
728 _ => Some(ClientError::Unknown),
729 }
730 }
731 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
732 Ok(res.text().await?)
733 }
734}
735
736pub struct DownloadLimit {
741 pub f: types::torrents::DownloadLimitForm,
742}
743
744#[async_trait]
745impl Endpoint for DownloadLimit {
746 type Query = ();
747 type Form = types::torrents::DownloadLimitForm;
748 type Response = types::torrents::DownloadLimitResponse;
749 fn relative_path(&self) -> Cow<str> {
750 "/api/v2/torrents/downloadLimit".into()
751 }
752 fn method(&self) -> reqwest::Method {
753 Method::POST
754 }
755 fn form(&self) -> Option<&Self::Form> {
756 Some(&self.f)
757 }
758 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
759 match status {
760 StatusCode::OK => None,
761 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
762 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
763 hash: self.f.hashes.join(", "),
764 }),
765 _ => Some(ClientError::Unknown),
766 }
767 }
768 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
769 Ok(res.json::<types::torrents::DownloadLimitResponse>().await?)
770 }
771}
772
773pub struct SetDownloadLimit {
775 pub f: types::torrents::SetDownloadLimitForm,
776}
777
778#[async_trait]
779impl Endpoint for SetDownloadLimit {
780 type Query = ();
781 type Form = types::torrents::SetDownloadLimitForm;
782 type Response = String;
783 fn relative_path(&self) -> Cow<str> {
784 "/api/v2/torrents/setDownloadLimit".into()
785 }
786 fn method(&self) -> reqwest::Method {
787 Method::POST
788 }
789 fn form(&self) -> Option<&Self::Form> {
790 Some(&self.f)
791 }
792 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
793 match status {
794 StatusCode::OK => None,
795 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
796 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
797 hash: self.f.hashes.join(", "),
798 }),
799 _ => Some(ClientError::Unknown),
800 }
801 }
802 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
803 Ok(res.text().await?)
804 }
805}
806
807pub struct SetShareLimits {
809 pub f: types::torrents::SetShareLimitsForm,
810}
811
812#[async_trait]
813impl Endpoint for SetShareLimits {
814 type Query = ();
815 type Form = types::torrents::SetShareLimitsForm;
816 type Response = String;
817 fn relative_path(&self) -> Cow<str> {
818 "/api/v2/torrents/setShareLimits".into()
819 }
820 fn method(&self) -> reqwest::Method {
821 Method::POST
822 }
823 fn form(&self) -> Option<&Self::Form> {
824 Some(&self.f)
825 }
826 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
827 match status {
828 StatusCode::OK => None,
829 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
830 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
831 hash: self.f.hashes.join(", "),
832 }),
833 _ => Some(ClientError::Unknown),
834 }
835 }
836 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
837 Ok(res.text().await?)
838 }
839}
840
841pub struct UploadLimit {
843 pub f: types::torrents::UploadLimitForm,
844}
845
846#[async_trait]
847impl Endpoint for UploadLimit {
848 type Query = ();
849 type Form = types::torrents::UploadLimitForm;
850 type Response = types::torrents::UploadLimitResponse;
851 fn relative_path(&self) -> Cow<str> {
852 "/api/v2/torrents/uploadLimit".into()
853 }
854 fn method(&self) -> reqwest::Method {
855 Method::POST
856 }
857 fn form(&self) -> Option<&Self::Form> {
858 Some(&self.f)
859 }
860 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
861 match status {
862 StatusCode::OK => None,
863 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
864 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
865 hash: self.f.hashes.join(", "),
866 }),
867 _ => Some(ClientError::Unknown),
868 }
869 }
870 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
871 Ok(res.json::<types::torrents::UploadLimitResponse>().await?)
872 }
873}
874
875pub struct SetUploadLimit {
877 pub f: types::torrents::SetUploadLimitForm,
878}
879
880#[async_trait]
881impl Endpoint for SetUploadLimit {
882 type Query = ();
883 type Form = types::torrents::SetUploadLimitForm;
884 type Response = String;
885 fn relative_path(&self) -> Cow<str> {
886 "/api/v2/torrents/setUploadLimit".into()
887 }
888 fn method(&self) -> reqwest::Method {
889 Method::POST
890 }
891 fn form(&self) -> Option<&Self::Form> {
892 Some(&self.f)
893 }
894 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
895 match status {
896 StatusCode::OK => None,
897 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
898 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
899 hash: self.f.hashes.join(", "),
900 }),
901 _ => Some(ClientError::Unknown),
902 }
903 }
904 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
905 Ok(res.text().await?)
906 }
907}
908
909pub struct SetLocation {
911 pub f: types::torrents::SetLocationForm,
912}
913
914#[async_trait]
915impl Endpoint for SetLocation {
916 type Query = ();
917 type Form = types::torrents::SetLocationForm;
918 type Response = String;
919 fn relative_path(&self) -> Cow<str> {
920 "/api/v2/torrents/setLocation".into()
921 }
922 fn method(&self) -> reqwest::Method {
923 Method::POST
924 }
925 fn form(&self) -> Option<&Self::Form> {
926 Some(&self.f)
927 }
928 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
929 match status {
930 StatusCode::OK => None,
931 StatusCode::BAD_REQUEST => Some(ClientError::BadRequest("Save path is empty".into())),
932 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
933 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
934 hash: self.f.hashes.join(", "),
935 }),
936 StatusCode::CONFLICT => Some(ClientError::Conflict(
937 "Unable to create save path directory".into(),
938 )),
939 _ => Some(ClientError::Unknown),
940 }
941 }
942 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
943 Ok(res.text().await?)
944 }
945}
946
947pub struct Rename {
949 pub f: types::torrents::RenameForm,
950}
951
952#[async_trait]
953impl Endpoint for Rename {
954 type Query = ();
955 type Form = types::torrents::RenameForm;
956 type Response = String;
957 fn relative_path(&self) -> Cow<str> {
958 "/api/v2/torrents/rename".into()
959 }
960 fn method(&self) -> reqwest::Method {
961 Method::POST
962 }
963 fn form(&self) -> Option<&Self::Form> {
964 Some(&self.f)
965 }
966 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
967 match status {
968 StatusCode::OK => None,
969 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
970 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
971 hash: self.f.hash.clone(),
972 }),
973 StatusCode::CONFLICT => Some(ClientError::Conflict("Torrent name is empty".into())),
974 _ => Some(ClientError::Unknown),
975 }
976 }
977 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
978 Ok(res.text().await?)
979 }
980}
981
982pub struct SetCategory {
984 pub f: types::torrents::SetCategoryForm,
985}
986
987#[async_trait]
988impl Endpoint for SetCategory {
989 type Query = ();
990 type Form = types::torrents::SetCategoryForm;
991 type Response = String;
992 fn relative_path(&self) -> Cow<str> {
993 "/api/v2/torrents/setCategory".into()
994 }
995 fn method(&self) -> reqwest::Method {
996 Method::POST
997 }
998 fn form(&self) -> Option<&Self::Form> {
999 Some(&self.f)
1000 }
1001 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1002 match status {
1003 StatusCode::OK => None,
1004 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1005 StatusCode::NOT_FOUND => Some(ClientError::TorrentNotFound {
1006 hash: self.f.hashes.join(", "),
1007 }),
1008 StatusCode::CONFLICT => {
1009 Some(ClientError::Conflict("Category name does not exist".into()))
1010 }
1011 _ => Some(ClientError::Unknown),
1012 }
1013 }
1014 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1015 Ok(res.text().await?)
1016 }
1017}
1018
1019pub struct Categories;
1021
1022#[async_trait]
1023impl Endpoint for Categories {
1024 type Query = ();
1025 type Form = ();
1026 type Response = types::torrents::CategoriesResponse;
1027 fn relative_path(&self) -> Cow<str> {
1028 "/api/v2/torrents/categories".into()
1029 }
1030 fn method(&self) -> reqwest::Method {
1031 Method::POST
1032 }
1033 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1034 match status {
1035 StatusCode::OK => None,
1036 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1037 _ => Some(ClientError::Unknown),
1038 }
1039 }
1040 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1041 Ok(res.json::<types::torrents::CategoriesResponse>().await?)
1042 }
1043}
1044
1045pub struct CreateCategory {
1047 pub f: types::torrents::CreateCategoryForm,
1048}
1049
1050#[async_trait]
1051impl Endpoint for CreateCategory {
1052 type Query = ();
1053 type Form = types::torrents::CreateCategoryForm;
1054 type Response = String;
1055 fn relative_path(&self) -> Cow<str> {
1056 "/api/v2/torrents/createCategory".into()
1057 }
1058 fn method(&self) -> reqwest::Method {
1059 Method::POST
1060 }
1061 fn form(&self) -> Option<&Self::Form> {
1062 Some(&self.f)
1063 }
1064 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1065 match status {
1066 StatusCode::OK => None,
1067 StatusCode::BAD_REQUEST => {
1068 Some(ClientError::BadRequest("Category name is empty".into()))
1069 }
1070 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1071 StatusCode::CONFLICT => Some(ClientError::Conflict("Category name is invalid".into())),
1072 _ => Some(ClientError::Unknown),
1073 }
1074 }
1075 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1076 Ok(res.text().await?)
1077 }
1078}
1079
1080pub struct EditCategory {
1082 pub f: types::torrents::EditCategoryForm,
1083}
1084
1085#[async_trait]
1086impl Endpoint for EditCategory {
1087 type Query = ();
1088 type Form = types::torrents::EditCategoryForm;
1089 type Response = String;
1090 fn relative_path(&self) -> Cow<str> {
1091 "/api/v2/torrents/editCategory".into()
1092 }
1093 fn method(&self) -> reqwest::Method {
1094 Method::POST
1095 }
1096 fn form(&self) -> Option<&Self::Form> {
1097 Some(&self.f)
1098 }
1099 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1100 match status {
1101 StatusCode::OK => None,
1102 StatusCode::BAD_REQUEST => {
1103 Some(ClientError::BadRequest("Category name is empty".into()))
1104 }
1105 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1106 StatusCode::CONFLICT => Some(ClientError::Conflict("Category name is invalid".into())),
1107 _ => Some(ClientError::Unknown),
1108 }
1109 }
1110 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1111 Ok(res.text().await?)
1112 }
1113}
1114
1115pub struct RemoveCategories {
1117 pub f: types::torrents::RemoveCategoriesForm,
1118}
1119
1120#[async_trait]
1121impl Endpoint for RemoveCategories {
1122 type Query = ();
1123 type Form = types::torrents::RemoveCategoriesForm;
1124 type Response = String;
1125 fn relative_path(&self) -> Cow<str> {
1126 "/api/v2/torrents/removeCategories".into()
1127 }
1128 fn method(&self) -> reqwest::Method {
1129 Method::POST
1130 }
1131 fn form(&self) -> Option<&Self::Form> {
1132 Some(&self.f)
1133 }
1134 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1135 match status {
1136 StatusCode::OK => None,
1137 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1138 _ => Some(ClientError::Unknown),
1139 }
1140 }
1141 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1142 Ok(res.text().await?)
1143 }
1144}
1145
1146pub struct AddTags {
1148 pub f: types::torrents::AddTagsForm,
1149}
1150
1151#[async_trait]
1152impl Endpoint for AddTags {
1153 type Query = ();
1154 type Form = types::torrents::AddTagsForm;
1155 type Response = String;
1156 fn relative_path(&self) -> Cow<str> {
1157 "/api/v2/torrents/addTags".into()
1158 }
1159 fn method(&self) -> reqwest::Method {
1160 Method::POST
1161 }
1162 fn form(&self) -> Option<&Self::Form> {
1163 Some(&self.f)
1164 }
1165 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1166 match status {
1167 StatusCode::OK => None,
1168 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1169 _ => Some(ClientError::Unknown),
1170 }
1171 }
1172 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1173 Ok(res.text().await?)
1174 }
1175}
1176
1177pub struct RemoveTags {
1179 pub f: types::torrents::RemoveTagsForm,
1180}
1181
1182#[async_trait]
1183impl Endpoint for RemoveTags {
1184 type Query = ();
1185 type Form = types::torrents::RemoveTagsForm;
1186 type Response = String;
1187 fn relative_path(&self) -> Cow<str> {
1188 "/api/v2/torrents/removeTags".into()
1189 }
1190 fn method(&self) -> reqwest::Method {
1191 Method::POST
1192 }
1193 fn form(&self) -> Option<&Self::Form> {
1194 Some(&self.f)
1195 }
1196 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1197 match status {
1198 StatusCode::OK => None,
1199 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1200 _ => Some(ClientError::Unknown),
1201 }
1202 }
1203 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1204 Ok(res.text().await?)
1205 }
1206}
1207
1208pub struct Tags;
1210
1211#[async_trait]
1212impl Endpoint for Tags {
1213 type Query = ();
1214 type Form = ();
1215 type Response = types::torrents::TagsResponse;
1216 fn relative_path(&self) -> Cow<str> {
1217 "/api/v2/torrents/tags".into()
1218 }
1219 fn method(&self) -> reqwest::Method {
1220 Method::POST
1221 }
1222 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1223 match status {
1224 StatusCode::OK => None,
1225 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1226 _ => Some(ClientError::Unknown),
1227 }
1228 }
1229 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1230 Ok(res.json::<types::torrents::TagsResponse>().await?)
1231 }
1232}
1233
1234pub struct CreateTags {
1236 pub f: types::torrents::CreateTagsForm,
1237}
1238
1239#[async_trait]
1240impl Endpoint for CreateTags {
1241 type Query = ();
1242 type Form = types::torrents::CreateTagsForm;
1243 type Response = String;
1244 fn relative_path(&self) -> Cow<str> {
1245 "/api/v2/torrents/createTags".into()
1246 }
1247 fn method(&self) -> reqwest::Method {
1248 Method::POST
1249 }
1250 fn form(&self) -> Option<&Self::Form> {
1251 Some(&self.f)
1252 }
1253 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1254 match status {
1255 StatusCode::OK => None,
1256 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1257 _ => Some(ClientError::Unknown),
1258 }
1259 }
1260 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1261 Ok(res.text().await?)
1262 }
1263}
1264
1265pub struct DeleteTags {
1267 pub f: types::torrents::DeleteTagsForm,
1268}
1269
1270#[async_trait]
1271impl Endpoint for DeleteTags {
1272 type Query = ();
1273 type Form = types::torrents::DeleteTagsForm;
1274 type Response = String;
1275 fn relative_path(&self) -> Cow<str> {
1276 "/api/v2/torrents/deleteTags".into()
1277 }
1278 fn method(&self) -> reqwest::Method {
1279 Method::POST
1280 }
1281 fn form(&self) -> Option<&Self::Form> {
1282 Some(&self.f)
1283 }
1284 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1285 match status {
1286 StatusCode::OK => None,
1287 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1288 _ => Some(ClientError::Unknown),
1289 }
1290 }
1291 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1292 Ok(res.text().await?)
1293 }
1294}
1295
1296pub struct SetAutoManagement {
1298 pub f: types::torrents::SetAutoManagementForm,
1299}
1300
1301#[async_trait]
1302impl Endpoint for SetAutoManagement {
1303 type Query = ();
1304 type Form = types::torrents::SetAutoManagementForm;
1305 type Response = String;
1306 fn relative_path(&self) -> Cow<str> {
1307 "/api/v2/torrents/setAutoManagement".into()
1308 }
1309 fn method(&self) -> reqwest::Method {
1310 Method::POST
1311 }
1312 fn form(&self) -> Option<&Self::Form> {
1313 Some(&self.f)
1314 }
1315 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1316 match status {
1317 StatusCode::OK => None,
1318 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1319 _ => Some(ClientError::Unknown),
1320 }
1321 }
1322 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1323 Ok(res.text().await?)
1324 }
1325}
1326
1327pub struct ToggleSequentialDownload {
1329 pub f: types::torrents::ToggleSequentialDownloadForm,
1330}
1331
1332#[async_trait]
1333impl Endpoint for ToggleSequentialDownload {
1334 type Query = ();
1335 type Form = types::torrents::ToggleSequentialDownloadForm;
1336 type Response = String;
1337 fn relative_path(&self) -> Cow<str> {
1338 "/api/v2/torrents/toggleSequentialDownload".into()
1339 }
1340 fn method(&self) -> reqwest::Method {
1341 Method::POST
1342 }
1343 fn form(&self) -> Option<&Self::Form> {
1344 Some(&self.f)
1345 }
1346 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1347 match status {
1348 StatusCode::OK => None,
1349 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1350 _ => Some(ClientError::Unknown),
1351 }
1352 }
1353 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1354 Ok(res.text().await?)
1355 }
1356}
1357
1358pub struct ToggleFirstLastPiecePrio {
1360 pub f: types::torrents::ToggleFirstLastPiecePrioForm,
1361}
1362
1363#[async_trait]
1364impl Endpoint for ToggleFirstLastPiecePrio {
1365 type Query = ();
1366 type Form = types::torrents::ToggleFirstLastPiecePrioForm;
1367 type Response = String;
1368 fn relative_path(&self) -> Cow<str> {
1369 "/api/v2/torrents/toggleFirstLastPiecePrio".into()
1370 }
1371 fn method(&self) -> reqwest::Method {
1372 Method::POST
1373 }
1374 fn form(&self) -> Option<&Self::Form> {
1375 Some(&self.f)
1376 }
1377 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1378 match status {
1379 StatusCode::OK => None,
1380 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1381 _ => Some(ClientError::Unknown),
1382 }
1383 }
1384 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1385 Ok(res.text().await?)
1386 }
1387}
1388
1389pub struct SetForceStart {
1391 pub f: types::torrents::SetForceStartForm,
1392}
1393
1394#[async_trait]
1395impl Endpoint for SetForceStart {
1396 type Query = ();
1397 type Form = types::torrents::SetForceStartForm;
1398 type Response = String;
1399 fn relative_path(&self) -> Cow<str> {
1400 "/api/v2/torrents/setForceStart".into()
1401 }
1402 fn method(&self) -> reqwest::Method {
1403 Method::POST
1404 }
1405 fn form(&self) -> Option<&Self::Form> {
1406 Some(&self.f)
1407 }
1408 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1409 match status {
1410 StatusCode::OK => None,
1411 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1412 _ => Some(ClientError::Unknown),
1413 }
1414 }
1415 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1416 Ok(res.text().await?)
1417 }
1418}
1419
1420pub struct SetSuperSeeding {
1422 pub f: types::torrents::SetSuperSeedingForm,
1423}
1424
1425#[async_trait]
1426impl Endpoint for SetSuperSeeding {
1427 type Query = ();
1428 type Form = types::torrents::SetSuperSeedingForm;
1429 type Response = String;
1430 fn relative_path(&self) -> Cow<str> {
1431 "/api/v2/torrents/setSuperSeeding".into()
1432 }
1433 fn method(&self) -> reqwest::Method {
1434 Method::POST
1435 }
1436 fn form(&self) -> Option<&Self::Form> {
1437 Some(&self.f)
1438 }
1439 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1440 match status {
1441 StatusCode::OK => None,
1442 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1443 _ => Some(ClientError::Unknown),
1444 }
1445 }
1446 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1447 Ok(res.text().await?)
1448 }
1449}
1450
1451pub struct RenameFile {
1453 pub f: types::torrents::RenameFileForm,
1454}
1455
1456#[async_trait]
1457impl Endpoint for RenameFile {
1458 type Query = ();
1459 type Form = types::torrents::RenameFileForm;
1460 type Response = String;
1461 fn relative_path(&self) -> Cow<str> {
1462 "/api/v2/torrents/renameFile".into()
1463 }
1464 fn method(&self) -> reqwest::Method {
1465 Method::POST
1466 }
1467 fn form(&self) -> Option<&Self::Form> {
1468 Some(&self.f)
1469 }
1470 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1471 match status {
1472 StatusCode::OK => None,
1473 StatusCode::BAD_REQUEST => {
1474 Some(ClientError::BadRequest("Missing new_path parameter".into()))
1475 }
1476 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1477 StatusCode::CONFLICT => Some(ClientError::Conflict(
1478 "Invalid new_path or old_path, or new_path already in use".into(),
1479 )),
1480 _ => Some(ClientError::Unknown),
1481 }
1482 }
1483 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1484 Ok(res.text().await?)
1485 }
1486}
1487
1488pub struct RenameFolder {
1490 pub f: types::torrents::RenameFolderForm,
1491}
1492
1493#[async_trait]
1494impl Endpoint for RenameFolder {
1495 type Query = ();
1496 type Form = types::torrents::RenameFolderForm;
1497 type Response = String;
1498 fn relative_path(&self) -> Cow<str> {
1499 "/api/v2/torrents/renameFolder".into()
1500 }
1501 fn method(&self) -> reqwest::Method {
1502 Method::POST
1503 }
1504 fn form(&self) -> Option<&Self::Form> {
1505 Some(&self.f)
1506 }
1507 fn check_status(&self, status: reqwest::StatusCode) -> Option<ClientError> {
1508 match status {
1509 StatusCode::OK => None,
1510 StatusCode::BAD_REQUEST => {
1511 Some(ClientError::BadRequest("Missing new_path parameter".into()))
1512 }
1513 StatusCode::FORBIDDEN => Some(ClientError::NeedAuthentication),
1514 StatusCode::CONFLICT => Some(ClientError::Conflict(
1515 "Invalid new_path or old_path, or new_path already in use".into(),
1516 )),
1517 _ => Some(ClientError::Unknown),
1518 }
1519 }
1520 async fn de_response(&self, res: reqwest::Response) -> Result<Self::Response, ClientError> {
1521 Ok(res.text().await?)
1522 }
1523}