pub struct TransClient { /* private fields */ }

Implementations§

source§

impl TransClient

source

pub fn with_auth(url: Url, basic_auth: BasicAuth) -> TransClient

Returns HTTP(S) client with configured Basic Auth

source

pub fn new(url: Url) -> TransClient

Returns HTTP(S) client

source

pub fn new_with_client(url: Url, client: Client) -> TransClient

source

pub fn set_auth(&mut self, basic_auth: BasicAuth)

source

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(())
}
source

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(())
}
source

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(())
}
source

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(())
}
source

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(())
}
source

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(())
}
source

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(())
}
source

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(())
}
source

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(())
}
source

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(())
}
source

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(())
}
source

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(())
}
source

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(())
}
source

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.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more