mirror of
https://github.com/kristoferssolo/transmission-rpc.git
synced 2025-10-21 20:10:37 +00:00
Changes client setup in every example so that it checks whether both the TUSER and TPASS environment variables are set and, if not, assumes no basic auth.
27 lines
778 B
Rust
27 lines
778 B
Rust
extern crate transmission_rpc;
|
|
|
|
use dotenv::dotenv;
|
|
use std::env;
|
|
use transmission_rpc::types::{BasicAuth, Result, RpcResponse, SessionGet};
|
|
use transmission_rpc::TransClient;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
dotenv().ok();
|
|
env_logger::init();
|
|
let url = env::var("TURL")?;
|
|
let client;
|
|
if let (Ok(user), Ok(password)) = (env::var("TUSER"), env::var("TPWD")) {
|
|
client = TransClient::with_auth(&url, BasicAuth {user, password});
|
|
} else {
|
|
client = TransClient::new(&url);
|
|
}
|
|
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(())
|
|
}
|