Struct transmission_rpc::TransClient
source · pub struct TransClient { /* private fields */ }
Implementations§
source§impl TransClient
impl TransClient
sourcepub fn with_auth(url: Url, basic_auth: BasicAuth) -> TransClient
pub fn with_auth(url: Url, basic_auth: BasicAuth) -> TransClient
Returns HTTP(S) client with configured Basic Auth
sourcepub fn new(url: Url) -> TransClient
pub fn new(url: Url) -> TransClient
Returns HTTP(S) client
pub fn new_with_client(url: Url, client: Client) -> TransClient
pub fn set_auth(&mut self, basic_auth: BasicAuth)
sourcepub async fn session_set(
&mut self,
args: SessionSetArgs
) -> Result<RpcResponse<SessionSet>>
pub async fn session_set( &mut self, args: SessionSetArgs ) -> Result<RpcResponse<SessionSet>>
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(())
}
sourcepub async fn session_get(&mut self) -> Result<RpcResponse<SessionGet>>
pub async fn session_get(&mut self) -> Result<RpcResponse<SessionGet>>
Performs a session get 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, SessionGet},
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 response: Result<RpcResponse<SessionGet>> = client.session_get().await;
match response {
Ok(_) => println!("Yay!"),
Err(_) => panic!("Oh no!"),
}
println!("Rpc response is ok: {}", response?.is_ok());
Ok(())
}
sourcepub async fn session_stats(&mut self) -> Result<RpcResponse<SessionStats>>
pub async fn session_stats(&mut self) -> Result<RpcResponse<SessionStats>>
Performs a session stats 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, SessionStats},
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 response: Result<RpcResponse<SessionStats>> = client.session_stats().await;
match response {
Ok(_) => println!("Yay!"),
Err(_) => panic!("Oh no!"),
}
println!("Rpc response is ok: {}", response?.is_ok());
Ok(())
}
sourcepub async fn session_close(&mut self) -> Result<RpcResponse<SessionClose>>
pub async fn session_close(&mut self) -> Result<RpcResponse<SessionClose>>
Performs a session close 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, SessionClose},
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 response: Result<RpcResponse<SessionClose>> = client.session_close().await;
match response {
Ok(_) => println!("Yay!"),
Err(_) => panic!("Oh no!"),
}
println!("Rpc response is ok: {}", response?.is_ok());
Ok(())
}
sourcepub async fn blocklist_update(&mut self) -> Result<RpcResponse<BlocklistUpdate>>
pub async fn blocklist_update(&mut self) -> Result<RpcResponse<BlocklistUpdate>>
Performs a blocklist update call
Errors
Any IO Error or Deserialization error
Example
extern crate transmission_rpc;
use std::env;
use dotenvy::dotenv;
use transmission_rpc::{
types::{BasicAuth, BlocklistUpdate, Result, RpcResponse},
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 response: Result<RpcResponse<BlocklistUpdate>> = client.blocklist_update().await;
match response {
Ok(_) => println!("Yay!"),
Err(_) => panic!("Oh no!"),
}
println!("Rpc response is ok: {}", response?.is_ok());
Ok(())
}
sourcepub async fn free_space(
&mut self,
path: String
) -> Result<RpcResponse<FreeSpace>>
pub async fn free_space( &mut self, path: String ) -> Result<RpcResponse<FreeSpace>>
Performs a session stats call
Errors
Any IO Error or Deserialization error
Example
extern crate transmission_rpc;
use std::env;
use dotenvy::dotenv;
use transmission_rpc::{
types::{BasicAuth, FreeSpace, Result, RpcResponse},
TransClient,
};
#[tokio::main]
async fn main() -> Result<()> {
dotenv().ok();
env_logger::init();
let url = env::var("TURL")?;
let dir = env::var("TDIR")?;
let basic_auth = BasicAuth {
user: env::var("TUSER")?,
password: env::var("TPWD")?,
};
let mut client = TransClient::with_auth(url.parse()?, basic_auth);
let response: Result<RpcResponse<FreeSpace>> = client.free_space(dir).await;
match response {
Ok(_) => println!("Yay!"),
Err(_) => panic!("Oh no!"),
}
println!("Rpc response is ok: {}", response?.is_ok());
Ok(())
}
sourcepub async fn port_test(&mut self) -> Result<RpcResponse<PortTest>>
pub async fn port_test(&mut self) -> Result<RpcResponse<PortTest>>
Performs a port test call
Errors
Any IO Error or Deserialization error
Example
extern crate transmission_rpc;
use std::env;
use dotenvy::dotenv;
use transmission_rpc::{
types::{BasicAuth, PortTest, Result, RpcResponse},
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 response: Result<RpcResponse<PortTest>> = client.port_test().await;
match response {
Ok(_) => println!("Yay!"),
Err(_) => panic!("Oh no!"),
}
println!("Rpc response is ok: {}", response?.is_ok());
Ok(())
}
sourcepub async fn torrent_get(
&mut self,
fields: Option<Vec<TorrentGetField>>,
ids: Option<Vec<Id>>
) -> Result<RpcResponse<Torrents<Torrent>>>
pub async fn torrent_get( &mut self, fields: Option<Vec<TorrentGetField>>, ids: Option<Vec<Id>> ) -> Result<RpcResponse<Torrents<Torrent>>>
Performs a torrent get call fields - if None then ALL fields ids - if None then All items
Errors
Any IO Error or Deserialization error
Example
extern crate transmission_rpc;
use std::env;
use dotenvy::dotenv;
use transmission_rpc::{
types::{BasicAuth, Id, Result, RpcResponse, Torrent, TorrentGetField, Torrents},
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 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();
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();
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();
println!("{:#?}", info);
Ok(())
}
sourcepub async fn torrent_set(
&mut self,
args: TorrentSetArgs,
ids: Option<Vec<Id>>
) -> Result<RpcResponse<Nothing>>
pub async fn torrent_set( &mut self, args: TorrentSetArgs, ids: Option<Vec<Id>> ) -> Result<RpcResponse<Nothing>>
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 dotenvy::dotenv;
use transmission_rpc::{
types::{BasicAuth, Id, Result, RpcResponse, Torrent, TorrentSetArgs, Torrents},
TransClient,
};
#[tokio::main]
async fn main() -> Result<()> {
dotenv().ok();
env_logger::init();
let url = env::var("TURL")?.parse()?;
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, Some(vec![Id::Id(0)]))
.await?
.is_ok()
);
Ok(())
}
sourcepub async fn torrent_action(
&mut self,
action: TorrentAction,
ids: Vec<Id>
) -> Result<RpcResponse<Nothing>>
pub async fn torrent_action( &mut self, action: TorrentAction, ids: Vec<Id> ) -> Result<RpcResponse<Nothing>>
Performs a torrent action call
Errors
Any IO Error or Deserialization error
Example
extern crate transmission_rpc;
use std::env;
use dotenvy::dotenv;
use transmission_rpc::{
types::{BasicAuth, Id, Nothing, Result, RpcResponse, TorrentAction},
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 res1: RpcResponse<Nothing> = client
.torrent_action(TorrentAction::Start, vec![Id::Id(1)])
.await?;
println!("Start result: {:?}", &res1.is_ok());
let res2: RpcResponse<Nothing> = client
.torrent_action(TorrentAction::Stop, vec![Id::Id(1)])
.await?;
println!("Stop result: {:?}", &res2.is_ok());
Ok(())
}
sourcepub async fn torrent_remove(
&mut self,
ids: Vec<Id>,
delete_local_data: bool
) -> Result<RpcResponse<Nothing>>
pub async fn torrent_remove( &mut self, ids: Vec<Id>, delete_local_data: bool ) -> Result<RpcResponse<Nothing>>
Performs a torrent remove call
Errors
Any IO Error or Deserialization error
Example
extern crate transmission_rpc;
use std::env;
use dotenvy::dotenv;
use transmission_rpc::{
types::{BasicAuth, Id, Nothing, Result, RpcResponse},
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 res: RpcResponse<Nothing> = client.torrent_remove(vec![Id::Id(1)], false).await?;
println!("Remove result: {:?}", &res.is_ok());
Ok(())
}
sourcepub async fn torrent_set_location(
&mut self,
ids: Vec<Id>,
location: String,
move_from: Option<bool>
) -> Result<RpcResponse<Nothing>>
pub async fn torrent_set_location( &mut self, ids: Vec<Id>, location: String, move_from: Option<bool> ) -> Result<RpcResponse<Nothing>>
Performs a torrent set location call
Errors
Any IO Error or Deserialization error
Example
extern crate transmission_rpc;
use std::env;
use dotenvy::dotenv;
use transmission_rpc::{
types::{BasicAuth, Id, Nothing, Result, RpcResponse},
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 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(())
}
sourcepub async fn torrent_rename_path(
&mut self,
ids: Vec<Id>,
path: String,
name: String
) -> Result<RpcResponse<TorrentRenamePath>>
pub async fn torrent_rename_path( &mut self, ids: Vec<Id>, path: String, name: String ) -> Result<RpcResponse<TorrentRenamePath>>
Performs a torrent rename path call
Errors
Any IO Error or Deserialization error
Example
extern crate transmission_rpc;
use std::env;
use dotenvy::dotenv;
use transmission_rpc::{
types::{BasicAuth, Id, Result, RpcResponse, TorrentRenamePath},
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 res: RpcResponse<TorrentRenamePath> = client
.torrent_rename_path(
vec![Id::Id(1)],
String::from("Folder/OldFile.jpg"),
String::from("NewFile.jpg"),
)
.await?;
println!("rename-path result: {:#?}", res);
Ok(())
}
sourcepub async fn torrent_add(
&mut self,
add: TorrentAddArgs
) -> Result<RpcResponse<TorrentAddedOrDuplicate>>
pub async fn torrent_add( &mut self, add: TorrentAddArgs ) -> Result<RpcResponse<TorrentAddedOrDuplicate>>
Performs a torrent add 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, TorrentAddArgs, TorrentAddedOrDuplicate},
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 add: TorrentAddArgs = TorrentAddArgs {
filename: Some(
"https://releases.ubuntu.com/22.04/ubuntu-22.04.3-desktop-amd64.iso.torrent"
.to_string(),
),
..TorrentAddArgs::default()
};
let res: RpcResponse<TorrentAddedOrDuplicate> = client.torrent_add(add).await?;
println!("Add result: {:?}", &res.is_ok());
println!("response: {:?}", &res);
Ok(())
}
Panics
Either metainfo or torrent filename must be set or this call will panic.