From 69760035f3d932af2ed51b9b499f80f621e91000 Mon Sep 17 00:00:00 2001 From: George Miao Date: Mon, 31 Oct 2022 10:33:56 -0400 Subject: [PATCH] feat: make sync optional --- Cargo.toml | 3 +++ src/lib.rs | 7 +++++-- src/sync.rs | 28 +++++++++++++++------------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fdf2bcc..739bf89 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,9 @@ keywords = ["transmission", "torrent", "jrpc"] categories = ["api-bindings"] include = ["**/*.rs", "Cargo.toml"] +[features] +sync = [] + [dependencies] reqwest = { version = "0.11.11", features = [ "json", diff --git a/src/lib.rs b/src/lib.rs index fc3e440..609e3e8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,10 +4,13 @@ extern crate log; use reqwest::{header::CONTENT_TYPE, Client, StatusCode, Url}; use serde::de::DeserializeOwned; +#[cfg(feature = "sync")] mod sync; -pub mod types; - +#[cfg(feature = "sync")] pub use sync::SharableTransClient; + + +pub mod types; use types::{ BasicAuth, BlocklistUpdate, FreeSpace, Id, Nothing, PortTest, Result, RpcRequest, RpcResponse, RpcResponseArgument, SessionClose, SessionGet, SessionStats, Torrent, TorrentAction, diff --git a/src/sync.rs b/src/sync.rs index a0b8081..be56035 100644 --- a/src/sync.rs +++ b/src/sync.rs @@ -97,7 +97,7 @@ impl SharableTransClient { /// user: env::var("TUSER")?, /// password: env::var("TPWD")?, /// }; - /// let client = TransClient::with_auth(url.parse()?, basic_auth); + /// let client = SharableTransClient::with_auth(url.parse()?, basic_auth); /// let response: Result> = client.session_get().await; /// match response { /// Ok(_) => println!("Yay!"), @@ -139,7 +139,7 @@ impl SharableTransClient { /// user: env::var("TUSER")?, /// password: env::var("TPWD")?, /// }; - /// let client = TransClient::with_auth(url.parse()?, basic_auth); + /// let client = SharableTransClient::with_auth(url.parse()?, basic_auth); /// let response: Result> = client.session_stats().await; /// match response { /// Ok(_) => println!("Yay!"), @@ -181,7 +181,7 @@ impl SharableTransClient { /// user: env::var("TUSER")?, /// password: env::var("TPWD")?, /// }; - /// let client = TransClient::with_auth(url.parse()?, basic_auth); + /// let client = SharableTransClient::with_auth(url.parse()?, basic_auth); /// let response: Result> = client.session_close().await; /// match response { /// Ok(_) => println!("Yay!"), @@ -223,7 +223,7 @@ impl SharableTransClient { /// user: env::var("TUSER")?, /// password: env::var("TPWD")?, /// }; - /// let client = TransClient::with_auth(url.parse()?, basic_auth); + /// let client = SharableTransClient::with_auth(url.parse()?, basic_auth); /// let response: Result> = client.blocklist_update().await; /// match response { /// Ok(_) => println!("Yay!"), @@ -266,7 +266,7 @@ impl SharableTransClient { /// user: env::var("TUSER")?, /// password: env::var("TPWD")?, /// }; - /// let client = TransClient::with_auth(url.parse()?, basic_auth); + /// let client = SharableTransClient::with_auth(url.parse()?, basic_auth); /// let response: Result> = client.free_space(dir).await; /// match response { /// Ok(_) => println!("Yay!"), @@ -308,7 +308,7 @@ impl SharableTransClient { /// user: env::var("TUSER")?, /// password: env::var("TPWD")?, /// }; - /// let client = TransClient::with_auth(url.parse()?, basic_auth); + /// let client = SharableTransClient::with_auth(url.parse()?, basic_auth); /// let response: Result> = client.port_test().await; /// match response { /// Ok(_) => println!("Yay!"), @@ -352,7 +352,7 @@ impl SharableTransClient { /// user: env::var("TUSER")?, /// password: env::var("TPWD")?, /// }; - /// let client = TransClient::with_auth(url.parse()?, basic_auth); + /// let client = SharableTransClient::with_auth(url.parse()?, basic_auth); /// /// let res: RpcResponse> = client.torrent_get(None, None).await?; /// let names: Vec<&String> = res @@ -452,7 +452,7 @@ impl SharableTransClient { /// user: env::var("TUSER")?, /// password: env::var("TPWD")?, /// }; - /// let client = TransClient::with_auth(url, basic_auth); + /// let client = SharableTransClient::with_auth(url, basic_auth); /// /// let args = TorrentSetArgs { /// labels: Some(vec![String::from("blue")]), @@ -504,7 +504,7 @@ impl SharableTransClient { /// user: env::var("TUSER")?, /// password: env::var("TPWD")?, /// }; - /// let client = TransClient::with_auth(url.parse()?, basic_auth); + /// let client = SharableTransClient::with_auth(url.parse()?, basic_auth); /// let res1: RpcResponse = client /// .torrent_action(TorrentAction::Start, vec![Id::Id(1)]) /// .await?; @@ -553,7 +553,7 @@ impl SharableTransClient { /// user: env::var("TUSER")?, /// password: env::var("TPWD")?, /// }; - /// let client = TransClient::with_auth(url.parse()?, basic_auth); + /// let client = SharableTransClient::with_auth(url.parse()?, basic_auth); /// let res: RpcResponse = client.torrent_remove(vec![Id::Id(1)], false).await?; /// println!("Remove result: {:?}", &res.is_ok()); /// @@ -597,7 +597,7 @@ impl SharableTransClient { /// user: env::var("TUSER")?, /// password: env::var("TPWD")?, /// }; - /// let client = TransClient::with_auth(url.parse()?, basic_auth); + /// let client = SharableTransClient::with_auth(url.parse()?, basic_auth); /// let res: RpcResponse = client /// .torrent_set_location( /// vec![Id::Id(1)], @@ -648,7 +648,7 @@ impl SharableTransClient { /// user: env::var("TUSER")?, /// password: env::var("TPWD")?, /// }; - /// let client = TransClient::with_auth(url.parse()?, basic_auth); + /// let client = SharableTransClient::with_auth(url.parse()?, basic_auth); /// let res: RpcResponse = client /// .torrent_rename_path( /// vec![Id::Id(1)], @@ -699,7 +699,7 @@ impl SharableTransClient { /// user: env::var("TUSER")?, /// password: env::var("TPWD")?, /// }; - /// let client = TransClient::with_auth(url.parse()?, basic_auth); + /// let client = SharableTransClient::with_auth(url.parse()?, basic_auth); /// let add: TorrentAddArgs = TorrentAddArgs { /// filename: Some( /// "https://releases.ubuntu.com/jammy/ubuntu-22.04.1-desktop-amd64.iso.torrent" @@ -758,6 +758,8 @@ impl SharableTransClient { ); let rsp: reqwest::Response = rq.send().await?; + + info!("Response: {:?}", &rsp); if matches!(rsp.status(), StatusCode::CONFLICT) { let session_id = rsp .headers()