11use reqwest:: { Error , Response } ;
2- pub struct ApiConnectionInfo {
2+ pub struct ConnectionInfo {
3+ /// The URL of the tracker. Eg: <https://tracker:7070> or <udp://tracker:6969>
34 pub url : String ,
5+ /// The token used to authenticate with the tracker API.
46 pub token : String ,
57}
68
7- impl ApiConnectionInfo {
9+ impl ConnectionInfo {
10+ #[ must_use]
811 pub fn new ( url : String , token : String ) -> Self {
912 Self { url, token }
1013 }
1114}
1215
13- pub struct ApiClient {
14- pub connection_info : ApiConnectionInfo ,
16+ pub struct Client {
17+ pub connection_info : ConnectionInfo ,
1518 base_url : String ,
1619}
1720
18- impl ApiClient {
19- pub fn new ( connection_info : ApiConnectionInfo ) -> Self {
21+ impl Client {
22+ #[ must_use]
23+ pub fn new ( connection_info : ConnectionInfo ) -> Self {
2024 let base_url = format ! ( "{}/api/v1" , connection_info. url) ;
2125 Self {
2226 connection_info,
2327 base_url,
2428 }
2529 }
2630
27- pub async fn whitelist_info_hash ( & self , info_hash : & str ) -> Result < Response , Error > {
31+ /// Add a torrent to the tracker whitelist.
32+ ///
33+ /// # Errors
34+ ///
35+ /// Will return an error if the HTTP request fails.
36+ pub async fn whitelist_torrent ( & self , info_hash : & str ) -> Result < Response , Error > {
2837 let request_url = format ! (
2938 "{}/whitelist/{}?token={}" ,
3039 self . base_url, info_hash, self . connection_info. token
@@ -35,7 +44,12 @@ impl ApiClient {
3544 client. post ( request_url) . send ( ) . await
3645 }
3746
38- pub async fn remove_info_hash_from_whitelist ( & self , info_hash : & str ) -> Result < Response , Error > {
47+ /// Remove a torrent from the tracker whitelist.
48+ ///
49+ /// # Errors
50+ ///
51+ /// Will return an error if the HTTP request fails.
52+ pub async fn remove_torrent_from_whitelist ( & self , info_hash : & str ) -> Result < Response , Error > {
3953 let request_url = format ! (
4054 "{}/whitelist/{}?token={}" ,
4155 self . base_url, info_hash, self . connection_info. token
@@ -46,6 +60,11 @@ impl ApiClient {
4660 client. delete ( request_url) . send ( ) . await
4761 }
4862
63+ /// Retrieve a new tracker key.
64+ ///
65+ /// # Errors
66+ ///
67+ /// Will return an error if the HTTP request fails.
4968 pub async fn retrieve_new_tracker_key ( & self , token_valid_seconds : u64 ) -> Result < Response , Error > {
5069 let request_url = format ! (
5170 "{}/key/{}?token={}" ,
@@ -57,6 +76,11 @@ impl ApiClient {
5776 client. post ( request_url) . send ( ) . await
5877 }
5978
79+ /// Retrieve the info for a torrent.
80+ ///
81+ /// # Errors
82+ ///
83+ /// Will return an error if the HTTP request fails.
6084 pub async fn get_torrent_info ( & self , info_hash : & str ) -> Result < Response , Error > {
6185 let request_url = format ! ( "{}/torrent/{}?token={}" , self . base_url, info_hash, self . connection_info. token) ;
6286
0 commit comments