From 6587f19aa77f71c54a616025b3ef0c34119e7611 Mon Sep 17 00:00:00 2001 From: Christiaan Biesterbosch Date: Sun, 27 Dec 2020 17:32:02 +0100 Subject: [PATCH] Add support for the torrent-set-location call --- README.md | 2 +- examples/torrent-set-location.rs | 20 +++++++++++++++++++ src/lib.rs | 34 ++++++++++++++++++++++++++++++++ src/types/request.rs | 16 +++++++++++++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 examples/torrent-set-location.rs diff --git a/README.md b/README.md index 959479f..f1fafb7 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ spec: https://github.com/transmission/transmission/blob/master/extras/rpc-spec.t - [X] torrent-get - [X] torrent-add - [X] torrent-remove -- [ ] torrent-set-location +- [X] torrent-set-location - [ ] torrent-rename-path - [ ] session-set - [X] session-get diff --git a/examples/torrent-set-location.rs b/examples/torrent-set-location.rs new file mode 100644 index 0000000..15f7542 --- /dev/null +++ b/examples/torrent-set-location.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::{Nothing, 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_set_location(vec![Id::Id(1)], String::from("/new/location"), Option::from(false)).await?; + println!("Set-location result: {:?}", &res.is_ok()); + + Ok(()) +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index d6a4196..5fd6f5f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -235,6 +235,40 @@ impl TransClient { self.call( RpcRequest::torrent_remove(ids, delete_local_data)).await } + /// Performs a torrent set location 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::{Nothing, 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_set_location(vec![Id::Id(1)], String::from("/new/location"), Option::from(false)).await?; + /// println!("Set-location result: {:?}", &res.is_ok()); + /// + /// Ok(()) + /// } + /// ``` + pub async fn torrent_set_location(&self, ids: Vec, location: String, move_from: Option) -> Result> { + self.call(RpcRequest::torrent_set_location(ids, location, move_from)).await + } + /// Performs a torrent add call /// /// # Errors diff --git a/src/types/request.rs b/src/types/request.rs index 223bd6d..3c0f71a 100644 --- a/src/types/request.rs +++ b/src/types/request.rs @@ -44,6 +44,13 @@ impl RpcRequest { arguments: Some ( Args::TorrentActionArgs(TorrentActionArgs { ids })), } } + + pub fn torrent_set_location(ids: Vec, location: String, move_from: Option) -> RpcRequest { + RpcRequest { + method: String::from("torrent-set-location"), + arguments: Some( Args::TorrentSetLocationArgs(TorrentSetLocationArgs{ids, location, move_from})) + } + } } pub trait ArgumentFields {} impl ArgumentFields for TorrentGetField{} @@ -55,6 +62,7 @@ pub enum Args{ TorrentActionArgs(TorrentActionArgs), TorrentRemoveArgs(TorrentRemoveArgs), TorrentAddArgs(TorrentAddArgs), + TorrentSetLocationArgs(TorrentSetLocationArgs), } #[derive(Serialize, Debug, RustcEncodable, Clone)] @@ -86,6 +94,14 @@ pub struct TorrentRemoveArgs { delete_local_data: bool } +#[derive(Serialize, Debug, RustcEncodable, Clone)] +pub struct TorrentSetLocationArgs { + ids: Vec, + location: String, + #[serde(skip_serializing_if="Option::is_none", rename="move")] + move_from: Option +} + #[derive(Serialize, Debug, RustcEncodable, Clone)] #[serde(untagged)] pub enum Id {