Struct transmission_rpc::TransClient [−][src]
pub struct TransClient { /* fields omitted */ }
Implementations
Returns HTTP(S) client with configured Basic Auth
Returns HTTP(S) client
Performs a session get 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, 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 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 response is ok: {}", response?.is_ok());
Ok(())
}
Performs a session stats 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, SessionStats, 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 client = TransClient::with_auth(&url, 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(())
}
Performs a session close 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, SessionClose};
#[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 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(())
}
Performs a blocklist update 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, BlocklistUpdate, RpcResponse, 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 client = TransClient::with_auth(&url, 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(())
}
Performs a session stats 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, FreeSpace};
#[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 client = TransClient::with_auth(&url, 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(())
}
Performs a port test 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, PortTest};
#[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 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(())
}
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>>>
Performs a torrent get call fileds - 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 dotenv::dotenv;
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 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();
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(())
}
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>>
Performs a torrent action 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::{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 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());
let res2: RpcResponse<Nothing> = client.torrent_action(TorrentAction::Stop, vec![Id::Id(1)]).await?;
println!("Stop result: {:?}", &res2.is_ok());
Ok(())
}
pub async fn torrent_remove(
&self,
ids: Vec<Id>,
delete_local_data: bool
) -> Result<RpcResponse<Nothing>>
pub async fn torrent_remove(
&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 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_remove(vec![Id::Id(1)], false).await?;
println!("Remove result: {:?}", &res.is_ok());
Ok(())
}
pub async fn torrent_set_location(
&self,
ids: Vec<Id>,
location: String,
move_from: Option<bool>
) -> Result<RpcResponse<Nothing>>
pub async fn torrent_set_location(
&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 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_rename_path(
&self,
ids: Vec<Id>,
path: String,
name: String
) -> Result<RpcResponse<TorrentRenamePath>>
pub async fn torrent_rename_path(
&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 dotenv::dotenv;
use transmission_rpc::TransClient;
use transmission_rpc::types::{Result, RpcResponse, BasicAuth};
use transmission_rpc::types::{TorrentRenamePath, 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<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(())
}
Performs a torrent add 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::{TorrentAddArgs, TorrentAdded};
#[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 add: TorrentAddArgs = TorrentAddArgs {
filename: Some("https://releases.ubuntu.com/20.04/ubuntu-20.04-desktop-amd64.iso.torrent".to_string()),
..TorrentAddArgs::default()
};
let res: RpcResponse<TorrentAdded> = client.torrent_add(add).await?;
println!("Add result: {:?}", &res.is_ok());
println!("response: {:?}", &res);
Ok(())
}
Auto Trait Implementations
impl RefUnwindSafe for TransClient
impl Send for TransClient
impl Sync for TransClient
impl Unpin for TransClient
impl UnwindSafe for TransClient
Blanket Implementations
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more