mirror of
https://github.com/kristoferssolo/transmission-rpc.git
synced 2025-10-21 20:10:37 +00:00
implement session-set method
This commit is contained in:
parent
3e927eb03b
commit
65ba721276
64
src/lib.rs
64
src/lib.rs
@ -4,20 +4,20 @@ extern crate log;
|
|||||||
use reqwest::{header::CONTENT_TYPE, Client, StatusCode, Url};
|
use reqwest::{header::CONTENT_TYPE, Client, StatusCode, Url};
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
|
|
||||||
#[cfg(feature = "sync")]
|
|
||||||
mod sync;
|
|
||||||
|
|
||||||
#[cfg(feature = "sync")]
|
#[cfg(feature = "sync")]
|
||||||
pub use sync::SharableTransClient;
|
pub use sync::SharableTransClient;
|
||||||
|
|
||||||
pub mod types;
|
|
||||||
use types::{
|
use types::{
|
||||||
BasicAuth, BlocklistUpdate, FreeSpace, Id, Nothing, PortTest, Result, RpcRequest, RpcResponse,
|
BasicAuth, BlocklistUpdate, FreeSpace, Id, Nothing, PortTest, Result, RpcRequest, RpcResponse,
|
||||||
RpcResponseArgument, SessionClose, SessionGet, SessionStats, Torrent, TorrentAction,
|
RpcResponseArgument, SessionClose, SessionGet, SessionSet, SessionSetArgs, SessionStats,
|
||||||
TorrentAddArgs, TorrentAddedOrDuplicate, TorrentGetField, TorrentRenamePath, TorrentSetArgs,
|
Torrent, TorrentAction, TorrentAddArgs, TorrentAddedOrDuplicate, TorrentGetField,
|
||||||
Torrents,
|
TorrentRenamePath, TorrentSetArgs, Torrents,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "sync")]
|
||||||
|
mod sync;
|
||||||
|
|
||||||
|
pub mod types;
|
||||||
|
|
||||||
const MAX_RETRIES: usize = 5;
|
const MAX_RETRIES: usize = 5;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
@ -93,6 +93,54 @@ impl TransClient {
|
|||||||
.header(CONTENT_TYPE, "application/json")
|
.header(CONTENT_TYPE, "application/json")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Performs a session set call
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// Any IO Error or Deserialization error
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// extern crate transmission_rpc;
|
||||||
|
///
|
||||||
|
/// use std::env;
|
||||||
|
///
|
||||||
|
/// use dotenvy::dotenv;
|
||||||
|
/// use transmission_rpc::{
|
||||||
|
/// types::{BasicAuth, Result, RpcResponse, SessionSet, SessionSetArgs},
|
||||||
|
/// TransClient,
|
||||||
|
/// };
|
||||||
|
///
|
||||||
|
/// #[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.parse()?, basic_auth);
|
||||||
|
/// let args: SessionSetArgs = SessionSetArgs {
|
||||||
|
/// download_dir: Some(
|
||||||
|
/// "/torrent/download".to_string(),
|
||||||
|
/// ),
|
||||||
|
/// ..SessionSetArgs::default()
|
||||||
|
/// };
|
||||||
|
/// let response: Result<RpcResponse<SessionSet>> = client.session_set(args).await;
|
||||||
|
/// match response {
|
||||||
|
/// Ok(_) => println!("Yay!"),
|
||||||
|
/// Err(_) => panic!("Oh no!"),
|
||||||
|
/// }
|
||||||
|
/// println!("Rpc response is ok: {}", response?.is_ok());
|
||||||
|
/// Ok(())
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
pub async fn session_set(&mut self, args: SessionSetArgs) -> Result<RpcResponse<SessionSet>> {
|
||||||
|
self.call(RpcRequest::session_set(args)).await
|
||||||
|
}
|
||||||
|
|
||||||
/// Performs a session get call
|
/// Performs a session get call
|
||||||
///
|
///
|
||||||
/// # Errors
|
/// # Errors
|
||||||
|
|||||||
@ -11,13 +11,13 @@ pub struct BasicAuth {
|
|||||||
|
|
||||||
pub(crate) use self::request::RpcRequest;
|
pub(crate) use self::request::RpcRequest;
|
||||||
pub use self::request::{
|
pub use self::request::{
|
||||||
ArgumentFields, Id, TorrentAction, TorrentAddArgs, TorrentGetField, TorrentRenamePathArgs,
|
ArgumentFields, Id, SessionSetArgs, TorrentAction, TorrentAddArgs, TorrentGetField,
|
||||||
TorrentSetArgs, TrackerList,
|
TorrentRenamePathArgs, TorrentSetArgs, TrackerList,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) use self::response::RpcResponseArgument;
|
pub(crate) use self::response::RpcResponseArgument;
|
||||||
pub use self::response::{
|
pub use self::response::{
|
||||||
BlocklistUpdate, ErrorType, FreeSpace, Nothing, PortTest, RpcResponse, SessionClose,
|
BlocklistUpdate, ErrorType, FreeSpace, Nothing, PortTest, RpcResponse, SessionClose,
|
||||||
SessionGet, SessionStats, Torrent, TorrentAddedOrDuplicate, TorrentRenamePath, TorrentStatus,
|
SessionGet, SessionSet, SessionStats, Torrent, TorrentAddedOrDuplicate, TorrentRenamePath,
|
||||||
Torrents,
|
TorrentStatus, Torrents,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -9,6 +9,13 @@ pub struct RpcRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RpcRequest {
|
impl RpcRequest {
|
||||||
|
pub fn session_set(args: SessionSetArgs) -> RpcRequest {
|
||||||
|
RpcRequest {
|
||||||
|
method: String::from("session-set"),
|
||||||
|
arguments: Some(Args::SessionSet(args)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn session_get() -> RpcRequest {
|
pub fn session_get() -> RpcRequest {
|
||||||
RpcRequest {
|
RpcRequest {
|
||||||
method: String::from("session-get"),
|
method: String::from("session-get"),
|
||||||
@ -131,6 +138,7 @@ impl ArgumentFields for TorrentGetField {}
|
|||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
pub enum Args {
|
pub enum Args {
|
||||||
FreeSpace(FreeSpaceArgs),
|
FreeSpace(FreeSpaceArgs),
|
||||||
|
SessionSet(SessionSetArgs),
|
||||||
TorrentGet(TorrentGetArgs),
|
TorrentGet(TorrentGetArgs),
|
||||||
TorrentAction(TorrentActionArgs),
|
TorrentAction(TorrentActionArgs),
|
||||||
TorrentRemove(TorrentRemoveArgs),
|
TorrentRemove(TorrentRemoveArgs),
|
||||||
@ -145,6 +153,222 @@ pub struct FreeSpaceArgs {
|
|||||||
path: String,
|
path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Debug, Clone, Default)]
|
||||||
|
pub struct SessionSetArgs {
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "alt-speed-down")]
|
||||||
|
pub alt_speed_down: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "alt-speed-enabled")]
|
||||||
|
pub alt_speed_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "alt-speed-time-begin"
|
||||||
|
)]
|
||||||
|
pub alt_speed_time_begin: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "alt-speed-time-day")]
|
||||||
|
pub alt_speed_time_day: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "alt-speed-time-enabled"
|
||||||
|
)]
|
||||||
|
pub alt_speed_time_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "alt-speed-time-end")]
|
||||||
|
pub alt_speed_time_end: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "alt-speed-up")]
|
||||||
|
pub alt_speed_up: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "blocklist-enabled")]
|
||||||
|
pub blocklist_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "blocklist-url")]
|
||||||
|
pub blocklist_url: Option<String>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "cache-size-mb")]
|
||||||
|
pub cache_size_mb: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "default-trackers")]
|
||||||
|
pub default_trackers: Option<String>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "dht-enabled")]
|
||||||
|
pub dht_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "download-dir")]
|
||||||
|
pub download_dir: Option<String>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "download-dir-free-space"
|
||||||
|
)]
|
||||||
|
pub download_dir_free_space: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "download-queue-enabled"
|
||||||
|
)]
|
||||||
|
pub download_queue_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "download-queue-size"
|
||||||
|
)]
|
||||||
|
pub download_queue_size: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub encryption: Option<String>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "idle-seeding-limit-enabled"
|
||||||
|
)]
|
||||||
|
pub idle_seeding_limit_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "idle-seeding-limit")]
|
||||||
|
pub idle_seeding_limit: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "incomplete-dir-enabled"
|
||||||
|
)]
|
||||||
|
pub incomplete_dir_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "incomplete-dir")]
|
||||||
|
pub incomplete_dir: Option<String>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "lpd-enabled")]
|
||||||
|
pub lpd_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "peer-limit-global")]
|
||||||
|
pub peer_limit_global: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "peer-limit-per-torrent"
|
||||||
|
)]
|
||||||
|
pub peer_limit_per_torrent: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "peer-port-random-on-start"
|
||||||
|
)]
|
||||||
|
pub peer_port_random_on_start: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "peer-port")]
|
||||||
|
pub peer_port: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "pex-enabled")]
|
||||||
|
pub pex_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "port-forwarding-enabled"
|
||||||
|
)]
|
||||||
|
pub port_forwarding_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "queue-stalled-enabled"
|
||||||
|
)]
|
||||||
|
pub queue_stalled_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "queue-stalled-minutes"
|
||||||
|
)]
|
||||||
|
pub queue_stalled_minutes: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "rename-partial-files"
|
||||||
|
)]
|
||||||
|
pub rename_partial_files: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "script-torrent-added-enabled"
|
||||||
|
)]
|
||||||
|
pub script_torrent_added_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "script-torrent-added-filename"
|
||||||
|
)]
|
||||||
|
pub script_torrent_added_filename: Option<String>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "script-torrent-done-enabled"
|
||||||
|
)]
|
||||||
|
pub script_torrent_done_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "script-torrent-done-filename"
|
||||||
|
)]
|
||||||
|
pub script_torrent_done_filename: Option<String>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "script-torrent-done-seeding-enabled"
|
||||||
|
)]
|
||||||
|
pub script_torrent_done_seeding_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "script-torrent-done-seeding-filename"
|
||||||
|
)]
|
||||||
|
pub script_torrent_done_seeding_filename: Option<String>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "seed-queue-enabled")]
|
||||||
|
pub seed_queue_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "seed-queue-size")]
|
||||||
|
pub seed_queue_size: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "seedRatioLimit")]
|
||||||
|
pub seed_ratio_limit: Option<f32>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "seedRatioLimited")]
|
||||||
|
pub seed_ratio_limited: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "speed-limit-down-enabled"
|
||||||
|
)]
|
||||||
|
pub speed_limit_down_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "speed-limit-down")]
|
||||||
|
pub speed_limit_down: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "speed-limit-up-enabled"
|
||||||
|
)]
|
||||||
|
pub speed_limit_up_enabled: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "speed-limit-up")]
|
||||||
|
pub speed_limit_up: Option<i32>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "start-added-torrents"
|
||||||
|
)]
|
||||||
|
pub start_added_torrents: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(
|
||||||
|
skip_serializing_if = "Option::is_none",
|
||||||
|
rename = "trash-original-torrent-files"
|
||||||
|
)]
|
||||||
|
pub trash_original_torrent_files: Option<bool>,
|
||||||
|
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none", rename = "utp-enabled")]
|
||||||
|
pub utp_enabled: Option<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Debug, Clone)]
|
#[derive(Serialize, Debug, Clone)]
|
||||||
pub struct TorrentGetArgs {
|
pub struct TorrentGetArgs {
|
||||||
#[serde(skip_serializing_if = "Option::is_none")]
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
|||||||
@ -16,6 +16,10 @@ impl<T: RpcResponseArgument> RpcResponse<T> {
|
|||||||
}
|
}
|
||||||
pub trait RpcResponseArgument {}
|
pub trait RpcResponseArgument {}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
|
pub struct SessionSet {}
|
||||||
|
impl RpcResponseArgument for SessionSet {}
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone)]
|
#[derive(Deserialize, Debug, Clone)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
pub struct SessionGet {
|
pub struct SessionGet {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user