mirror of
https://github.com/kristoferssolo/transmission-rpc.git
synced 2025-10-21 20:10:37 +00:00
Format the code with rustfmt
This commit is contained in:
parent
510b79e57e
commit
2ca1444f18
@ -1,22 +1,25 @@
|
||||
extern crate transmission_rpc;
|
||||
|
||||
use std::env;
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
use transmission_rpc::types::{BasicAuth, Result, RpcResponse, SessionGet};
|
||||
use transmission_rpc::TransClient;
|
||||
use transmission_rpc::types::{Result, RpcResponse, SessionGet, BasicAuth};
|
||||
|
||||
#[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 basic_auth = BasicAuth {
|
||||
user: env::var("TUSER")?,
|
||||
password: env::var("TPWD")?,
|
||||
};
|
||||
let client = TransClient::with_auth(&url, basic_auth);
|
||||
let response: Result<RpcResponse<SessionGet>> = client.session_get().await;
|
||||
match response {
|
||||
Ok(_) => println!("Yay!"),
|
||||
Err(_) => panic!("Oh no!")
|
||||
}
|
||||
println!("Rpc reqsponse is ok: {}", response?.is_ok());
|
||||
println!("Rpc response is ok: {}", response?.is_ok());
|
||||
Ok(())
|
||||
}
|
||||
@ -1,17 +1,20 @@
|
||||
extern crate transmission_rpc;
|
||||
|
||||
use std::env;
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
use transmission_rpc::types::{BasicAuth, Result, RpcResponse};
|
||||
use transmission_rpc::types::{Id, Nothing, TorrentAction};
|
||||
use transmission_rpc::TransClient;
|
||||
use transmission_rpc::types::{Result, RpcResponse, BasicAuth};
|
||||
use transmission_rpc::types::{TorrentAction, 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 basic_auth = BasicAuth {
|
||||
user: env::var("TUSER")?,
|
||||
password: env::var("TPWD")?,
|
||||
};
|
||||
let client = TransClient::with_auth(&url, basic_auth);
|
||||
let res1: RpcResponse<Nothing> = client.torrent_action(TorrentAction::Start, vec![Id::Id(1)]).await?;
|
||||
println!("Start result: {:?}", &res1.is_ok());
|
||||
|
||||
@ -1,17 +1,20 @@
|
||||
extern crate transmission_rpc;
|
||||
|
||||
use std::env;
|
||||
use dotenv::dotenv;
|
||||
use transmission_rpc::TransClient;
|
||||
use transmission_rpc::types::{Result, RpcResponse, BasicAuth};
|
||||
use std::env;
|
||||
use transmission_rpc::types::{BasicAuth, Result, RpcResponse};
|
||||
use transmission_rpc::types::{TorrentAddArgs, TorrentAdded};
|
||||
use transmission_rpc::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 basic_auth = BasicAuth {
|
||||
user: env::var("TUSER")?,
|
||||
password: env::var("TPWD")?,
|
||||
};
|
||||
let client = TransClient::with_auth(&url, basic_auth);
|
||||
let add: TorrentAddArgs = TorrentAddArgs {
|
||||
filename: Some("https://releases.ubuntu.com/20.04/ubuntu-20.04-desktop-amd64.iso.torrent".to_string()),
|
||||
|
||||
@ -1,37 +1,58 @@
|
||||
extern crate transmission_rpc;
|
||||
|
||||
use std::env;
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
use transmission_rpc::types::{BasicAuth, Result, RpcResponse};
|
||||
use transmission_rpc::types::{Id, Torrent, TorrentGetField, Torrents};
|
||||
use transmission_rpc::TransClient;
|
||||
use transmission_rpc::types::{Result, RpcResponse, BasicAuth};
|
||||
use transmission_rpc::types::{Torrents, Torrent, TorrentGetField, 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 basic_auth = BasicAuth {
|
||||
user: env::var("TUSER")?,
|
||||
password: env::var("TPWD")?,
|
||||
};
|
||||
let client = TransClient::with_auth(&url, basic_auth);
|
||||
|
||||
let res: RpcResponse<Torrents<Torrent>> = client.torrent_get(None, None).await?;
|
||||
let names: Vec<&String> = res.arguments.torrents.iter().map(|it| it.name.as_ref().unwrap()).collect();
|
||||
let names: Vec<&String> = res
|
||||
.arguments
|
||||
.torrents
|
||||
.iter()
|
||||
.map(|it| it.name.as_ref().unwrap())
|
||||
.collect();
|
||||
println!("{:#?}", names);
|
||||
|
||||
let res1: RpcResponse<Torrents<Torrent>> = client.torrent_get(Some(vec![TorrentGetField::Id, TorrentGetField::Name]), Some(vec![Id::Id(1), Id::Id(2), Id::Id(3)])).await?;
|
||||
let first_three: Vec<String> = res1.arguments.torrents.iter().map(|it|
|
||||
format!("{}. {}",&it.id.as_ref().unwrap(), &it.name.as_ref().unwrap())
|
||||
).collect();
|
||||
let res1: RpcResponse<Torrents<Torrent>> = client.torrent_get(
|
||||
Some(vec![TorrentGetField::Id, TorrentGetField::Name]),
|
||||
Some(vec![Id::Id(1), Id::Id(2), Id::Id(3)]),
|
||||
).await?;
|
||||
let first_three: Vec<String> = res1
|
||||
.arguments
|
||||
.torrents
|
||||
.iter()
|
||||
.map(|it| {format!("{}. {}", &it.id.as_ref().unwrap(), &it.name.as_ref().unwrap())})
|
||||
.collect();
|
||||
println!("{:#?}", first_three);
|
||||
|
||||
|
||||
let res2: RpcResponse<Torrents<Torrent>> = client.torrent_get(Some(vec![TorrentGetField::Id, TorrentGetField::HashString, TorrentGetField::Name]), Some(vec![Id::Hash(String::from("64b0d9a53ac9cd1002dad1e15522feddb00152fe"))])).await?;
|
||||
let info: Vec<String> = res2.arguments.torrents.iter().map(|it|
|
||||
format!("{:5}. {:^45} {}",
|
||||
&it.id.as_ref().unwrap(),
|
||||
&it.hash_string.as_ref().unwrap(),
|
||||
&it.name.as_ref().unwrap())
|
||||
).collect();
|
||||
let res2: RpcResponse<Torrents<Torrent>> = client
|
||||
.torrent_get(
|
||||
Some(vec![
|
||||
TorrentGetField::Id,
|
||||
TorrentGetField::HashString,
|
||||
TorrentGetField::Name,
|
||||
]),
|
||||
Some(vec![Id::Hash(String::from("64b0d9a53ac9cd1002dad1e15522feddb00152fe",))]),
|
||||
).await?;
|
||||
let info: Vec<String> = res2
|
||||
.arguments
|
||||
.torrents
|
||||
.iter()
|
||||
.map(|it| {format!("{:5}. {:^45} {}", &it.id.as_ref().unwrap(), &it.hash_string.as_ref().unwrap(), &it.name.as_ref().unwrap())})
|
||||
.collect();
|
||||
println!("{:#?}", info);
|
||||
|
||||
Ok(())
|
||||
|
||||
@ -1,17 +1,20 @@
|
||||
extern crate transmission_rpc;
|
||||
|
||||
use std::env;
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
use transmission_rpc::types::{BasicAuth, Result, RpcResponse};
|
||||
use transmission_rpc::types::{Id, Nothing};
|
||||
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 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_remove(vec![Id::Id(1)], false).await?;
|
||||
println!("Remove result: {:?}", &res.is_ok());
|
||||
|
||||
@ -1,19 +1,26 @@
|
||||
extern crate transmission_rpc;
|
||||
|
||||
use std::env;
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
use transmission_rpc::types::{BasicAuth, Result, RpcResponse};
|
||||
use transmission_rpc::types::{Id, Nothing};
|
||||
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 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?;
|
||||
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(())
|
||||
|
||||
84
src/lib.rs
84
src/lib.rs
@ -6,20 +6,20 @@ extern crate env_logger;
|
||||
extern crate log;
|
||||
extern crate reqwest;
|
||||
|
||||
use serde::de::DeserializeOwned;
|
||||
use reqwest::header::CONTENT_TYPE;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
pub mod types;
|
||||
use types::BasicAuth;
|
||||
use types::{Result, RpcResponse, RpcResponseArgument, RpcRequest, Nothing};
|
||||
use types::SessionGet;
|
||||
use types::{TorrentGetField, Torrents, Torrent, Id};
|
||||
use types::TorrentAction;
|
||||
use types::{Id, Torrent, TorrentGetField, Torrents};
|
||||
use types::{Nothing, Result, RpcRequest, RpcResponse, RpcResponseArgument};
|
||||
use types::{TorrentAddArgs, TorrentAdded};
|
||||
|
||||
pub struct TransClient {
|
||||
url: String,
|
||||
auth: Option<BasicAuth>
|
||||
auth: Option<BasicAuth>,
|
||||
}
|
||||
|
||||
impl TransClient {
|
||||
@ -27,7 +27,7 @@ impl TransClient {
|
||||
pub fn with_auth(url: &str, basic_auth: BasicAuth) -> TransClient {
|
||||
TransClient {
|
||||
url: url.to_string(),
|
||||
auth: Some(basic_auth)
|
||||
auth: Some(basic_auth),
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ impl TransClient {
|
||||
pub fn new(url: &str) -> TransClient {
|
||||
TransClient {
|
||||
url: url.to_string(),
|
||||
auth: None
|
||||
auth: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +43,8 @@ impl TransClient {
|
||||
fn rpc_request(&self) -> reqwest::RequestBuilder {
|
||||
let client = reqwest::Client::new();
|
||||
if let Some(auth) = &self.auth {
|
||||
client.post(&self.url)
|
||||
client
|
||||
.post(&self.url)
|
||||
.basic_auth(&auth.user, Some(&auth.password))
|
||||
} else {
|
||||
client.post(&self.url)
|
||||
@ -59,18 +60,19 @@ impl TransClient {
|
||||
/// If response is impossible to unwrap then it will return an empty session_id
|
||||
async fn get_session_id(&self) -> String {
|
||||
info!("Requesting session id info");
|
||||
let response: reqwest::Result<reqwest::Response> = self.rpc_request()
|
||||
let response: reqwest::Result<reqwest::Response> = self
|
||||
.rpc_request()
|
||||
.json(&RpcRequest::session_get())
|
||||
.send()
|
||||
.await;
|
||||
let session_id = match response {
|
||||
Ok(ref resp) =>
|
||||
match resp.headers().get("x-transmission-session-id") {
|
||||
Ok(ref resp) => match resp.headers().get("x-transmission-session-id") {
|
||||
Some(res) => res.to_str().expect("header value should be a string"),
|
||||
_ => ""
|
||||
_ => "",
|
||||
},
|
||||
_ => "",
|
||||
}
|
||||
_ => ""
|
||||
}.to_owned();
|
||||
.to_owned();
|
||||
info!("Received session id: {}", session_id);
|
||||
session_id
|
||||
}
|
||||
@ -161,7 +163,11 @@ impl TransClient {
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
pub async fn torrent_get(&self, fields: Option<Vec<TorrentGetField>>, ids: Option<Vec<Id>>) -> Result<RpcResponse<Torrents<Torrent>>> {
|
||||
pub async fn torrent_get(
|
||||
&self,
|
||||
fields: Option<Vec<TorrentGetField>>,
|
||||
ids: Option<Vec<Id>>,
|
||||
) -> Result<RpcResponse<Torrents<Torrent>>> {
|
||||
self.call(RpcRequest::torrent_get(fields, ids)).await
|
||||
}
|
||||
|
||||
@ -197,7 +203,11 @@ impl TransClient {
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
pub async fn torrent_action(&self, action: TorrentAction, ids: Vec<Id>) -> Result<RpcResponse<Nothing>> {
|
||||
pub async fn torrent_action(
|
||||
&self,
|
||||
action: TorrentAction,
|
||||
ids: Vec<Id>,
|
||||
) -> Result<RpcResponse<Nothing>> {
|
||||
self.call(RpcRequest::torrent_action(action, ids)).await
|
||||
}
|
||||
|
||||
@ -231,8 +241,13 @@ impl TransClient {
|
||||
/// Ok(())
|
||||
/// }
|
||||
/// ```
|
||||
pub async fn torrent_remove(&self, ids: Vec<Id>, delete_local_data: bool) -> Result<RpcResponse<Nothing>> {
|
||||
self.call( RpcRequest::torrent_remove(ids, delete_local_data)).await
|
||||
pub async fn torrent_remove(
|
||||
&self,
|
||||
ids: Vec<Id>,
|
||||
delete_local_data: bool,
|
||||
) -> Result<RpcResponse<Nothing>> {
|
||||
self.call(RpcRequest::torrent_remove(ids, delete_local_data))
|
||||
.await
|
||||
}
|
||||
|
||||
/// Performs a torrent set location call
|
||||
@ -265,8 +280,14 @@ impl TransClient {
|
||||
/// 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
|
||||
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
|
||||
@ -317,15 +338,20 @@ impl TransClient {
|
||||
///
|
||||
/// Any IO Error or Deserialization error
|
||||
async fn call<RS>(&self, request: RpcRequest) -> Result<RpcResponse<RS>>
|
||||
where RS : RpcResponseArgument + DeserializeOwned + std::fmt::Debug
|
||||
where
|
||||
RS: RpcResponseArgument + DeserializeOwned + std::fmt::Debug,
|
||||
{
|
||||
info!("Loaded auth: {:?}", &self.auth);
|
||||
let rq: reqwest::RequestBuilder = self.rpc_request()
|
||||
let rq: reqwest::RequestBuilder = self
|
||||
.rpc_request()
|
||||
.header("X-Transmission-Session-Id", self.get_session_id().await)
|
||||
.json(&request);
|
||||
info!("Request body: {:?}", rq.try_clone()
|
||||
info!(
|
||||
"Request body: {:?}",
|
||||
rq.try_clone()
|
||||
.expect("Unable to get the request body")
|
||||
.body_string()?);
|
||||
.body_string()?
|
||||
);
|
||||
let resp: reqwest::Response = rq.send().await?;
|
||||
let rpc_response: RpcResponse<RS> = resp.json().await?;
|
||||
info!("Response body: {:#?}", rpc_response);
|
||||
@ -349,19 +375,25 @@ impl BodyString for reqwest::RequestBuilder {
|
||||
mod tests {
|
||||
|
||||
use super::*;
|
||||
use std::env;
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
|
||||
#[tokio::test]
|
||||
pub async fn test_malformed_url() -> Result<()> {
|
||||
dotenv().ok();
|
||||
env_logger::init();
|
||||
let url = env::var("TURL")?;
|
||||
let basic_auth = BasicAuth{user: env::var("TUSER")?, password: env::var("TPWD")?};
|
||||
let basic_auth = BasicAuth {
|
||||
user: env::var("TUSER")?,
|
||||
password: env::var("TPWD")?,
|
||||
};
|
||||
let client = TransClient::with_auth(&url, basic_auth);
|
||||
info!("Client is ready!");
|
||||
let add: TorrentAddArgs = TorrentAddArgs {
|
||||
filename: Some("https://releases.ubuntu.com/20.04/ubuntu-20.04-desktop-amd64.iso.torrentt".to_string()),
|
||||
filename: Some(
|
||||
"https://releases.ubuntu.com/20.04/ubuntu-20.04-desktop-amd64.iso.torrentt"
|
||||
.to_string(),
|
||||
),
|
||||
..TorrentAddArgs::default()
|
||||
};
|
||||
match client.torrent_add(add).await {
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
|
||||
mod request;
|
||||
mod response;
|
||||
|
||||
@ -10,18 +9,18 @@ pub struct BasicAuth {
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
pub(crate) use self::request::RpcRequest;
|
||||
pub use self::request::ArgumentFields;
|
||||
pub use self::request::TorrentGetField;
|
||||
pub use self::request::TorrentAction;
|
||||
pub use self::request::TorrentAddArgs;
|
||||
pub use self::request::File;
|
||||
pub use self::request::Id;
|
||||
pub(crate) use self::request::RpcRequest;
|
||||
pub use self::request::TorrentAction;
|
||||
pub use self::request::TorrentAddArgs;
|
||||
pub use self::request::TorrentGetField;
|
||||
|
||||
pub use self::response::Nothing;
|
||||
pub use self::response::RpcResponse;
|
||||
pub(crate) use self::response::RpcResponseArgument;
|
||||
pub use self::response::SessionGet;
|
||||
pub use self::response::Torrents;
|
||||
pub use self::response::Torrent;
|
||||
pub use self::response::TorrentAdded;
|
||||
pub use self::response::Nothing;
|
||||
pub use self::response::Torrents;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use serde::Serialize;
|
||||
use enum_iterator::IntoEnumIterator;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize, Debug, RustcEncodable)]
|
||||
pub struct RpcRequest {
|
||||
@ -17,24 +17,34 @@ impl RpcRequest {
|
||||
}
|
||||
|
||||
pub fn torrent_get(fields: Option<Vec<TorrentGetField>>, ids: Option<Vec<Id>>) -> RpcRequest {
|
||||
let string_fields = fields.unwrap_or(TorrentGetField::all()).iter().map(|f| f.to_str()).collect();
|
||||
let string_fields = fields
|
||||
.unwrap_or(TorrentGetField::all())
|
||||
.iter()
|
||||
.map(|f| f.to_str())
|
||||
.collect();
|
||||
RpcRequest {
|
||||
method: String::from("torrent-get"),
|
||||
arguments: Some ( Args::TorrentGetArgs(TorrentGetArgs { fields: Some(string_fields), ids } )),
|
||||
arguments: Some(Args::TorrentGetArgs(TorrentGetArgs {
|
||||
fields: Some(string_fields),
|
||||
ids,
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn torrent_remove(ids: Vec<Id>, delete_local_data: bool) -> RpcRequest {
|
||||
RpcRequest {
|
||||
method: String::from("torrent-remove"),
|
||||
arguments: Some ( Args::TorrentRemoveArgs(TorrentRemoveArgs {ids, delete_local_data} ) )
|
||||
arguments: Some(Args::TorrentRemoveArgs(TorrentRemoveArgs {
|
||||
ids,
|
||||
delete_local_data,
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn torrent_add(add: TorrentAddArgs) -> RpcRequest {
|
||||
RpcRequest {
|
||||
method: String::from("torrent-add"),
|
||||
arguments: Some ( Args::TorrentAddArgs(add) )
|
||||
arguments: Some(Args::TorrentAddArgs(add)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,10 +55,14 @@ impl RpcRequest {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn torrent_set_location(ids: Vec<Id>, location: String, move_from: Option<bool>) -> RpcRequest {
|
||||
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}))
|
||||
arguments: Some(Args::TorrentSetLocationArgs(TorrentSetLocationArgs {
|
||||
ids,
|
||||
location,
|
||||
move_from,
|
||||
})),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -75,10 +89,12 @@ pub struct TorrentGetArgs {
|
||||
|
||||
impl Default for TorrentGetArgs {
|
||||
fn default() -> Self {
|
||||
let all_fields = TorrentGetField::into_enum_iter().map (|it| it.to_str()).collect();
|
||||
let all_fields = TorrentGetField::into_enum_iter()
|
||||
.map(|it| it.to_str())
|
||||
.collect();
|
||||
TorrentGetArgs {
|
||||
fields: Some(all_fields),
|
||||
ids: None
|
||||
ids: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -91,7 +107,7 @@ pub struct TorrentActionArgs {
|
||||
pub struct TorrentRemoveArgs {
|
||||
ids: Vec<Id>,
|
||||
#[serde(rename = "delete-local-data")]
|
||||
delete_local_data: bool
|
||||
delete_local_data: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug, RustcEncodable, Clone)]
|
||||
@ -99,14 +115,14 @@ pub struct TorrentSetLocationArgs {
|
||||
ids: Vec<Id>,
|
||||
location: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none", rename = "move")]
|
||||
move_from: Option<bool>
|
||||
move_from: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug, RustcEncodable, Clone)]
|
||||
#[serde(untagged)]
|
||||
pub enum Id {
|
||||
Id(i64),
|
||||
Hash(String)
|
||||
Hash(String),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug, RustcEncodable, Clone)]
|
||||
@ -156,7 +172,7 @@ impl Default for TorrentAddArgs {
|
||||
files_unwanted: None,
|
||||
priority_high: None,
|
||||
priority_low: None,
|
||||
priority_normal: None
|
||||
priority_normal: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ use serde::Deserialize;
|
||||
#[derive(Deserialize, Debug)]
|
||||
pub struct RpcResponse<T: RpcResponseArgument> {
|
||||
pub arguments: T,
|
||||
pub result: String
|
||||
pub result: String,
|
||||
}
|
||||
|
||||
impl<T: RpcResponseArgument> RpcResponse<T> {
|
||||
@ -79,7 +79,7 @@ pub struct Torrent {
|
||||
|
||||
#[derive(Deserialize, Debug, RustcEncodable)]
|
||||
pub struct Torrents<T> {
|
||||
pub torrents: Vec<T>
|
||||
pub torrents: Vec<T>,
|
||||
}
|
||||
impl RpcResponseArgument for Torrents<Torrent> {}
|
||||
|
||||
@ -96,6 +96,6 @@ impl RpcResponseArgument for Nothing {}
|
||||
#[derive(Deserialize, Debug, RustcEncodable)]
|
||||
pub struct TorrentAdded {
|
||||
#[serde(rename = "torrent-added")]
|
||||
pub torrent_added: Option<Torrent>
|
||||
pub torrent_added: Option<Torrent>,
|
||||
}
|
||||
impl RpcResponseArgument for TorrentAdded {}
|
||||
Loading…
Reference in New Issue
Block a user