Struct transmission_rpc::TransClient [−][src]
Implementations
impl TransClient
[src]
pub fn with_auth(url: &str, basic_auth: BasicAuth) -> TransClient
[src]
Returns HTTP(S) client with configured Basic Auth
pub fn new(url: &str) -> TransClient
[src]
Returns HTTP(S) client
pub async fn session_get(&self) -> Result<RpcResponse<SessionGet>>
[src]
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 reqsponse is ok: {}", response?.is_ok()); Ok(()) }
pub async fn torrent_get(
&self,
fields: Option<Vec<TorrentGetField>>,
ids: Option<Vec<Id>>
) -> Result<RpcResponse<Torrents<Torrent>>>
[src]
&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>>
[src]
&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>>
[src]
&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>>
[src]
&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_add(
&self,
add: TorrentAddArgs
) -> Result<RpcResponse<TorrentAdded>>
[src]
&self,
add: TorrentAddArgs
) -> Result<RpcResponse<TorrentAdded>>
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
[src]
impl Send for TransClient
[src]
impl Sync for TransClient
[src]
impl Unpin for TransClient
[src]
impl UnwindSafe for TransClient
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,