mirror of
https://github.com/kristoferssolo/transmission-rpc.git
synced 2025-10-21 20:10:37 +00:00
Implement basic torrent-set rpc to set labels and file priorities
This commit is contained in:
parent
d246908d55
commit
88abc70010
47
src/lib.rs
47
src/lib.rs
@ -294,7 +294,7 @@ impl TransClient {
|
||||
}
|
||||
|
||||
/// Performs a torrent get call
|
||||
/// fileds - if None then ALL fields
|
||||
/// fields - if None then ALL fields
|
||||
/// ids - if None then All items
|
||||
///
|
||||
/// # Errors
|
||||
@ -351,6 +351,51 @@ impl TransClient {
|
||||
self.call(RpcRequest::torrent_get(fields, ids)).await
|
||||
}
|
||||
|
||||
/// Performs a torrent set call
|
||||
/// args - the fields to update
|
||||
/// ids - if None then All items
|
||||
///
|
||||
/// # 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::{Torrents, Torrent, TorrentSetArgs, 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 mut client = TransClient::with_auth(&url, basic_auth);
|
||||
///
|
||||
/// let args = TorrentSetArgs {
|
||||
/// labels: Some(vec![String::from("blue")]),
|
||||
/// ..Default::default(),
|
||||
/// };
|
||||
/// assert!(client.torrent_set(args, vec![Id::Id(0)]).await?.is_ok())
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
pub async fn torrent_set(
|
||||
&mut self,
|
||||
args: TorrentSetArgs,
|
||||
ids: Option<Vec<Id>>,
|
||||
) -> Result<RpcResponse<Nothing>> {
|
||||
self.call(RpcRequest::torrent_set(args, ids)).await
|
||||
}
|
||||
|
||||
/// Performs a torrent action call
|
||||
///
|
||||
/// # Errors
|
||||
|
||||
@ -66,6 +66,14 @@ impl RpcRequest {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn torrent_set(mut args: TorrentSetArgs, ids: Option<Vec<Id>>) -> RpcRequest {
|
||||
args.ids = ids;
|
||||
RpcRequest {
|
||||
method: String::from("torrent-set"),
|
||||
arguments: Some(Args::TorrentSetArgs(args)),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn torrent_remove(ids: Vec<Id>, delete_local_data: bool) -> RpcRequest {
|
||||
RpcRequest {
|
||||
method: String::from("torrent-remove"),
|
||||
@ -358,3 +366,17 @@ impl TorrentAction {
|
||||
.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug, Clone, Default)]
|
||||
pub struct TorrentSetArgs {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub labels: Option<Vec<String>>,
|
||||
#[serde(rename = "priority-low", skip_serializing_if = "Option::is_none")]
|
||||
pub priority_low: Option<Vec<u64>>,
|
||||
#[serde(rename = "priority-normal", skip_serializing_if = "Option::is_none")]
|
||||
pub priority_normal: Option<Vec<u64>>,
|
||||
#[serde(rename = "priority-high", skip_serializing_if = "Option::is_none")]
|
||||
pub priority_high: Option<Vec<u64>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub ids: Option<Vec<Id>>,
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user