diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d9ca51..e88cd2c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -41,6 +41,13 @@ jobs: args: --release --all-features - name: Cargo Test - uses: actions-rs/cargo@v1 + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - run: cargo test -- --skip session_close + + - name: Cargo Test Session Close + uses: actions-rs/toolchain@v1 with: - command: test + toolchain: stable + - run: cargo test -- session_close diff --git a/README.md b/README.md index e6ddb4f..2a273cc 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ spec: https://github.com/transmission/transmission/blob/master/extras/rpc-spec.t - [X] session-stats - [X] blocklist-update - [X] port-test -- [ ] session-close +- [X] session-close - [X] free-space Support the project: [![Donate button](https://www.paypalobjects.com/en_US/DK/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=H337RKJSC4YG4&source=url) diff --git a/examples/session-close.rs b/examples/session-close.rs new file mode 100644 index 0000000..88f76c2 --- /dev/null +++ b/examples/session-close.rs @@ -0,0 +1,26 @@ +extern crate transmission_rpc; + +use dotenv::dotenv; +use std::env; +use transmission_rpc::types::{BasicAuth, Result, RpcResponse, SessionClose}; +use transmission_rpc::TransClient; + +#[tokio::main] +async fn main() -> Result<()> { + dotenv().ok(); + env_logger::init(); + let url = env::var("TURL")?; + let client; + if let (Ok(user), Ok(password)) = (env::var("TUSER"), env::var("TPWD")) { + client = TransClient::with_auth(&url, BasicAuth {user, password}); + } else { + client = TransClient::new(&url); + } + let response: Result> = client.session_close().await; + match response { + Ok(_) => println!("Yay!"), + Err(_) => panic!("Oh no!") + } + println!("Rpc response is ok: {}", response?.is_ok()); + Ok(()) +} diff --git a/src/lib.rs b/src/lib.rs index b4462b3..608b090 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,7 @@ use types::BasicAuth; use types::BlocklistUpdate; use types::SessionGet; use types::SessionStats; +use types::SessionClose; use types::PortTest; use types::FreeSpace; use types::TorrentAction; @@ -151,6 +152,42 @@ impl TransClient { self.call(RpcRequest::session_stats()).await } + /// Performs a session close call + /// + /// # Errors + /// + /// Any IO Error or Deserialization error + /// + /// # Example + /// + /// ``` + /// extern crate transmission_rpc; + /// + /// use std::env; + /// use dotenv::dotenv; + /// use transmission_rpc::TransClient; + /// use transmission_rpc::types::{Result, RpcResponse, BasicAuth, SessionClose}; + /// + /// #[tokio::main] + /// async fn main() -> Result<()> { + /// dotenv().ok(); + /// env_logger::init(); + /// let url= env::var("TURL")?; + /// let basic_auth = BasicAuth{user: env::var("TUSER")?, password: env::var("TPWD")?}; + /// let client = TransClient::with_auth(&url, basic_auth); + /// let response: Result> = client.session_close().await; + /// match response { + /// Ok(_) => println!("Yay!"), + /// Err(_) => panic!("Oh no!") + /// } + /// println!("Rpc response is ok: {}", response?.is_ok()); + /// Ok(()) + /// } + /// ``` + pub async fn session_close(&self) -> Result> { + self.call(RpcRequest::session_close()).await + } + /// Performs a blocklist update call /// /// # Errors diff --git a/src/types/mod.rs b/src/types/mod.rs index 38540e6..e2a3e32 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -22,6 +22,7 @@ pub use self::response::RpcResponse; pub(crate) use self::response::RpcResponseArgument; pub use self::response::SessionGet; pub use self::response::SessionStats; +pub use self::response::SessionClose; pub use self::response::BlocklistUpdate; pub use self::response::PortTest; pub use self::response::FreeSpace; diff --git a/src/types/request.rs b/src/types/request.rs index 6e7f4d1..ec53f51 100644 --- a/src/types/request.rs +++ b/src/types/request.rs @@ -23,6 +23,13 @@ impl RpcRequest { } } + pub fn session_close() -> RpcRequest { + RpcRequest { + method: String::from("session-close"), + arguments: None, + } + } + pub fn blocklist_update() -> RpcRequest { RpcRequest { method: String::from("blocklist-update"), diff --git a/src/types/response.rs b/src/types/response.rs index 3c07c8a..a001cfe 100644 --- a/src/types/response.rs +++ b/src/types/response.rs @@ -46,6 +46,10 @@ pub struct SessionStats { } impl RpcResponseArgument for SessionStats {} +#[derive(Deserialize, Debug, Clone)] +pub struct SessionClose {} +impl RpcResponseArgument for SessionClose {} + #[derive(Deserialize, Debug, Clone)] pub struct BlocklistUpdate { #[serde(rename = "blocklist-size")]