mirror of
https://github.com/kristoferssolo/transmission-rpc.git
synced 2025-10-21 20:10:37 +00:00
Add support for no auth to examples
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.
This commit is contained in:
parent
23330680d6
commit
3df01c4389
@ -10,11 +10,12 @@ 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 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!"),
|
||||
|
||||
@ -11,11 +11,12 @@ 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 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 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?;
|
||||
|
||||
@ -11,11 +11,12 @@ 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 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 add: TorrentAddArgs = TorrentAddArgs {
|
||||
filename: Some("https://releases.ubuntu.com/20.04/ubuntu-20.04-desktop-amd64.iso.torrent".to_string()),
|
||||
..TorrentAddArgs::default()
|
||||
|
||||
@ -11,11 +11,12 @@ 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 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 res: RpcResponse<Torrents<Torrent>> = client.torrent_get(None, None).await?;
|
||||
let names: Vec<&String> = res
|
||||
|
||||
@ -11,11 +11,12 @@ 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 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 res: RpcResponse<Nothing> = client.torrent_remove(vec![Id::Id(1)], false).await?;
|
||||
println!("Remove result: {:?}", &res.is_ok());
|
||||
|
||||
|
||||
@ -11,11 +11,12 @@ 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 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 res: RpcResponse<Nothing> = client.torrent_set_location(
|
||||
vec![Id::Id(1)],
|
||||
String::from("/new/location"),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user