mirror of
https://github.com/kristoferssolo/transmission-rpc.git
synced 2025-10-21 20:10:37 +00:00
Add support for the torrent-set-location call
This commit is contained in:
parent
8d07f2be84
commit
6587f19aa7
@ -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
|
||||
|
||||
20
examples/torrent-set-location.rs
Normal file
20
examples/torrent-set-location.rs
Normal 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(())
|
||||
}
|
||||
34
src/lib.rs
34
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<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
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user