Add support for the torrent-set-location call

This commit is contained in:
Christiaan Biesterbosch 2020-12-27 17:32:02 +01:00
parent 8d07f2be84
commit 6587f19aa7
No known key found for this signature in database
GPG Key ID: B29731CEDFC77003
4 changed files with 71 additions and 1 deletions

View File

@ -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

View File

@ -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<Nothing> = client.torrent_set_location(vec![Id::Id(1)], String::from("/new/location"), Option::from(false)).await?;
println!("Set-location result: {:?}", &res.is_ok());
Ok(())
}

View File

@ -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<Nothing> = 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<Id>, location: String, move_from: Option<bool>) -> Result<RpcResponse<Nothing>> {
self.call(RpcRequest::torrent_set_location(ids, location, move_from)).await
}
/// Performs a torrent add call
///
/// # Errors

View File

@ -44,6 +44,13 @@ impl RpcRequest {
arguments: Some ( Args::TorrentActionArgs(TorrentActionArgs { ids })),
}
}
pub fn torrent_set_location(ids: Vec<Id>, location: String, move_from: Option<bool>) -> 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<Id>,
location: String,
#[serde(skip_serializing_if="Option::is_none", rename="move")]
move_from: Option<bool>
}
#[derive(Serialize, Debug, RustcEncodable, Clone)]
#[serde(untagged)]
pub enum Id {