From 981e09f17391074d817a118a9e7aab373e687988 Mon Sep 17 00:00:00 2001 From: Christopher Hasse Date: Sun, 29 Aug 2021 03:29:50 -0500 Subject: [PATCH] Added support for torrent-rename-path Including examples and updated readme to reflect support. --- README.md | 2 +- examples/torrent-rename-path.rs | 20 ++++++++++++++++ src/lib.rs | 42 ++++++++++++++++++++++++++++++++- src/types/mod.rs | 2 ++ src/types/request.rs | 19 +++++++++++++++ src/types/response.rs | 9 +++++++ 6 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 examples/torrent-rename-path.rs diff --git a/README.md b/README.md index 1ad1845..f789ecd 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ spec: https://github.com/transmission/transmission/blob/master/extras/rpc-spec.t - [X] torrent-add - [X] torrent-remove - [X] torrent-set-location -- [ ] torrent-rename-path +- [X] torrent-rename-path - [ ] session-set - [X] session-get - [ ] session-stats diff --git a/examples/torrent-rename-path.rs b/examples/torrent-rename-path.rs new file mode 100644 index 0000000..9e50e46 --- /dev/null +++ b/examples/torrent-rename-path.rs @@ -0,0 +1,20 @@ +extern crate transmission_rpc; + +use std::env; +use dotenv::dotenv; +use transmission_rpc::TransClient; +use transmission_rpc::types::{Result, RpcResponse, BasicAuth}; +use transmission_rpc::types::{TorrentRenamePath, Id}; + +#[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 res: RpcResponse = client.torrent_rename_path(vec![Id::Id(1)], String::from("Folder/OldFile.jpg"), String::from("NewFile.jpg")).await?; + println!("rename-path result: {:#?}", res); + + Ok(()) +} diff --git a/src/lib.rs b/src/lib.rs index f01d56a..68a6944 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,7 @@ use types::BasicAuth; use types::SessionGet; use types::TorrentAction; use types::{Id, Torrent, TorrentGetField, Torrents}; -use types::{Nothing, Result, RpcRequest, RpcResponse, RpcResponseArgument}; +use types::{Nothing, Result, RpcRequest, RpcResponse, RpcResponseArgument, TorrentRenamePath}; use types::{TorrentAddArgs, TorrentAdded}; pub struct TransClient { @@ -288,6 +288,46 @@ impl TransClient { .await } + /// Performs a torrent rename path 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}; + /// use transmission_rpc::types::{TorrentRenamePath, Id}; + /// + /// #[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 res: RpcResponse = client.torrent_rename_path(vec![Id::Id(1)], String::from("Folder/OldFile.jpg"), String::from("NewFile.jpg")).await?; + /// println!("rename-path result: {:#?}", res); + /// + /// Ok(()) + /// } + /// ``` + pub async fn torrent_rename_path( + &self, + ids: Vec, + path: String, + name: String, + ) -> Result> { + self.call(RpcRequest::torrent_rename_path(ids, path, name)) + .await + } + /// Performs a torrent add call /// /// # Errors diff --git a/src/types/mod.rs b/src/types/mod.rs index 5629958..59e6f81 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -15,6 +15,7 @@ pub(crate) use self::request::RpcRequest; pub use self::request::TorrentAction; pub use self::request::TorrentAddArgs; pub use self::request::TorrentGetField; +pub use self::request::TorrentRenamePathArgs; pub use self::response::Nothing; pub use self::response::RpcResponse; @@ -23,3 +24,4 @@ pub use self::response::SessionGet; pub use self::response::Torrent; pub use self::response::TorrentAdded; pub use self::response::Torrents; +pub use self::response::TorrentRenamePath; diff --git a/src/types/request.rs b/src/types/request.rs index 4620d3a..6714d96 100644 --- a/src/types/request.rs +++ b/src/types/request.rs @@ -65,6 +65,17 @@ impl RpcRequest { })), } } + + pub fn torrent_rename_path(ids: Vec, path: String, name: String) -> RpcRequest { + RpcRequest { + method: String::from("torrent-rename-path"), + arguments: Some(Args::TorrentRenamePathArgs(TorrentRenamePathArgs { + ids, + path, + name + })) + } + } } pub trait ArgumentFields {} impl ArgumentFields for TorrentGetField {} @@ -77,6 +88,7 @@ pub enum Args { TorrentRemoveArgs(TorrentRemoveArgs), TorrentAddArgs(TorrentAddArgs), TorrentSetLocationArgs(TorrentSetLocationArgs), + TorrentRenamePathArgs(TorrentRenamePathArgs), } #[derive(Serialize, Debug, RustcEncodable, Clone)] @@ -118,6 +130,13 @@ pub struct TorrentSetLocationArgs { move_from: Option, } +#[derive(Serialize, Debug, RustcEncodable, Clone)] +pub struct TorrentRenamePathArgs { + ids: Vec, + path: String, + name: String, +} + #[derive(Serialize, Debug, RustcEncodable, Clone)] #[serde(untagged)] pub enum Id { diff --git a/src/types/response.rs b/src/types/response.rs index 0dfc5f2..950f7a8 100644 --- a/src/types/response.rs +++ b/src/types/response.rs @@ -123,3 +123,12 @@ pub struct TorrentAdded { pub torrent_added: Option, } impl RpcResponseArgument for TorrentAdded {} + +#[derive(Deserialize, Debug, RustcEncodable)] +pub struct TorrentRenamePath{ + pub path: String, + pub name: String, + pub id: i64 + +} +impl RpcResponseArgument for TorrentRenamePath {}