mirror of
https://github.com/kristoferssolo/transmission-rpc.git
synced 2025-10-21 20:10:37 +00:00
Merge pull request #16 from nickzana/fix-tests-no-auth
Fix Examples to support configuration with no authentication
This commit is contained in:
commit
7a50ac33ab
@ -10,11 +10,12 @@ async fn main() -> Result<()> {
|
|||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let url = env::var("TURL")?;
|
let url = env::var("TURL")?;
|
||||||
let basic_auth = BasicAuth {
|
let client;
|
||||||
user: env::var("TUSER")?,
|
if let (Ok(user), Ok(password)) = (env::var("TUSER"), env::var("TPWD")) {
|
||||||
password: env::var("TPWD")?,
|
client = TransClient::with_auth(&url, BasicAuth {user, password});
|
||||||
};
|
} else {
|
||||||
let client = TransClient::with_auth(&url, basic_auth);
|
client = TransClient::new(&url);
|
||||||
|
}
|
||||||
let response: Result<RpcResponse<SessionGet>> = client.session_get().await;
|
let response: Result<RpcResponse<SessionGet>> = client.session_get().await;
|
||||||
match response {
|
match response {
|
||||||
Ok(_) => println!("Yay!"),
|
Ok(_) => println!("Yay!"),
|
||||||
|
|||||||
@ -11,11 +11,12 @@ async fn main() -> Result<()> {
|
|||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let url = env::var("TURL")?;
|
let url = env::var("TURL")?;
|
||||||
let basic_auth = BasicAuth {
|
let client;
|
||||||
user: env::var("TUSER")?,
|
if let (Ok(user), Ok(password)) = (env::var("TUSER"), env::var("TPWD")) {
|
||||||
password: env::var("TPWD")?,
|
client = TransClient::with_auth(&url, BasicAuth {user, password});
|
||||||
};
|
} else {
|
||||||
let client = TransClient::with_auth(&url, basic_auth);
|
client = TransClient::new(&url);
|
||||||
|
}
|
||||||
let res1: RpcResponse<Nothing> = client.torrent_action(TorrentAction::Start, vec![Id::Id(1)]).await?;
|
let res1: RpcResponse<Nothing> = client.torrent_action(TorrentAction::Start, vec![Id::Id(1)]).await?;
|
||||||
println!("Start result: {:?}", &res1.is_ok());
|
println!("Start result: {:?}", &res1.is_ok());
|
||||||
let res2: RpcResponse<Nothing> = client.torrent_action(TorrentAction::Stop, vec![Id::Id(1)]).await?;
|
let res2: RpcResponse<Nothing> = client.torrent_action(TorrentAction::Stop, vec![Id::Id(1)]).await?;
|
||||||
|
|||||||
@ -11,11 +11,12 @@ async fn main() -> Result<()> {
|
|||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let url = env::var("TURL")?;
|
let url = env::var("TURL")?;
|
||||||
let basic_auth = BasicAuth {
|
let client;
|
||||||
user: env::var("TUSER")?,
|
if let (Ok(user), Ok(password)) = (env::var("TUSER"), env::var("TPWD")) {
|
||||||
password: env::var("TPWD")?,
|
client = TransClient::with_auth(&url, BasicAuth {user, password});
|
||||||
};
|
} else {
|
||||||
let client = TransClient::with_auth(&url, basic_auth);
|
client = TransClient::new(&url);
|
||||||
|
}
|
||||||
let add: TorrentAddArgs = TorrentAddArgs {
|
let add: TorrentAddArgs = TorrentAddArgs {
|
||||||
filename: Some("https://releases.ubuntu.com/20.04/ubuntu-20.04-desktop-amd64.iso.torrent".to_string()),
|
filename: Some("https://releases.ubuntu.com/20.04/ubuntu-20.04-desktop-amd64.iso.torrent".to_string()),
|
||||||
..TorrentAddArgs::default()
|
..TorrentAddArgs::default()
|
||||||
|
|||||||
@ -11,11 +11,12 @@ async fn main() -> Result<()> {
|
|||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let url = env::var("TURL")?;
|
let url = env::var("TURL")?;
|
||||||
let basic_auth = BasicAuth {
|
let client;
|
||||||
user: env::var("TUSER")?,
|
if let (Ok(user), Ok(password)) = (env::var("TUSER"), env::var("TPWD")) {
|
||||||
password: env::var("TPWD")?,
|
client = TransClient::with_auth(&url, BasicAuth {user, password});
|
||||||
};
|
} else {
|
||||||
let client = TransClient::with_auth(&url, basic_auth);
|
client = TransClient::new(&url);
|
||||||
|
}
|
||||||
|
|
||||||
let res: RpcResponse<Torrents<Torrent>> = client.torrent_get(None, None).await?;
|
let res: RpcResponse<Torrents<Torrent>> = client.torrent_get(None, None).await?;
|
||||||
let names: Vec<&String> = res
|
let names: Vec<&String> = res
|
||||||
|
|||||||
@ -11,11 +11,12 @@ async fn main() -> Result<()> {
|
|||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let url = env::var("TURL")?;
|
let url = env::var("TURL")?;
|
||||||
let basic_auth = BasicAuth {
|
let client;
|
||||||
user: env::var("TUSER")?,
|
if let (Ok(user), Ok(password)) = (env::var("TUSER"), env::var("TPWD")) {
|
||||||
password: env::var("TPWD")?,
|
client = TransClient::with_auth(&url, BasicAuth {user, password});
|
||||||
};
|
} else {
|
||||||
let client = TransClient::with_auth(&url, basic_auth);
|
client = TransClient::new(&url);
|
||||||
|
}
|
||||||
let res: RpcResponse<Nothing> = client.torrent_remove(vec![Id::Id(1)], false).await?;
|
let res: RpcResponse<Nothing> = client.torrent_remove(vec![Id::Id(1)], false).await?;
|
||||||
println!("Remove result: {:?}", &res.is_ok());
|
println!("Remove result: {:?}", &res.is_ok());
|
||||||
|
|
||||||
|
|||||||
@ -11,11 +11,12 @@ async fn main() -> Result<()> {
|
|||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let url = env::var("TURL")?;
|
let url = env::var("TURL")?;
|
||||||
let basic_auth = BasicAuth {
|
let client;
|
||||||
user: env::var("TUSER")?,
|
if let (Ok(user), Ok(password)) = (env::var("TUSER"), env::var("TPWD")) {
|
||||||
password: env::var("TPWD")?,
|
client = TransClient::with_auth(&url, BasicAuth {user, password});
|
||||||
};
|
} else {
|
||||||
let client = TransClient::with_auth(&url, basic_auth);
|
client = TransClient::new(&url);
|
||||||
|
}
|
||||||
let res: RpcResponse<Nothing> = client.torrent_set_location(
|
let res: RpcResponse<Nothing> = client.torrent_set_location(
|
||||||
vec![Id::Id(1)],
|
vec![Id::Id(1)],
|
||||||
String::from("/new/location"),
|
String::from("/new/location"),
|
||||||
|
|||||||
19
src/lib.rs
19
src/lib.rs
@ -157,7 +157,7 @@ impl TransClient {
|
|||||||
/// &it.name.as_ref().unwrap())
|
/// &it.name.as_ref().unwrap())
|
||||||
/// ).collect();
|
/// ).collect();
|
||||||
/// println!("{:#?}", info);
|
/// println!("{:#?}", info);
|
||||||
///
|
///
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
@ -197,7 +197,7 @@ impl TransClient {
|
|||||||
/// println!("Start result: {:?}", &res1.is_ok());
|
/// println!("Start result: {:?}", &res1.is_ok());
|
||||||
/// let res2: RpcResponse<Nothing> = client.torrent_action(TorrentAction::Stop, vec![Id::Id(1)]).await?;
|
/// let res2: RpcResponse<Nothing> = client.torrent_action(TorrentAction::Stop, vec![Id::Id(1)]).await?;
|
||||||
/// println!("Stop result: {:?}", &res2.is_ok());
|
/// println!("Stop result: {:?}", &res2.is_ok());
|
||||||
///
|
///
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
@ -235,7 +235,7 @@ impl TransClient {
|
|||||||
/// let client = TransClient::with_auth(&url, basic_auth);
|
/// let client = TransClient::with_auth(&url, basic_auth);
|
||||||
/// let res: RpcResponse<Nothing> = client.torrent_remove(vec![Id::Id(1)], false).await?;
|
/// let res: RpcResponse<Nothing> = client.torrent_remove(vec![Id::Id(1)], false).await?;
|
||||||
/// println!("Remove result: {:?}", &res.is_ok());
|
/// println!("Remove result: {:?}", &res.is_ok());
|
||||||
///
|
///
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
@ -319,7 +319,7 @@ impl TransClient {
|
|||||||
/// let res: RpcResponse<TorrentAdded> = client.torrent_add(add).await?;
|
/// let res: RpcResponse<TorrentAdded> = client.torrent_add(add).await?;
|
||||||
/// println!("Add result: {:?}", &res.is_ok());
|
/// println!("Add result: {:?}", &res.is_ok());
|
||||||
/// println!("response: {:?}", &res);
|
/// println!("response: {:?}", &res);
|
||||||
///
|
///
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
@ -380,11 +380,12 @@ mod tests {
|
|||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let url = env::var("TURL")?;
|
let url = env::var("TURL")?;
|
||||||
let basic_auth = BasicAuth {
|
let client;
|
||||||
user: env::var("TUSER")?,
|
if let (Ok(user), Ok(password)) = (env::var("TUSER"), env::var("TPWD")) {
|
||||||
password: env::var("TPWD")?,
|
client = TransClient::with_auth(&url, BasicAuth {user, password});
|
||||||
};
|
} else {
|
||||||
let client = TransClient::with_auth(&url, basic_auth);
|
client = TransClient::new(&url);
|
||||||
|
}
|
||||||
info!("Client is ready!");
|
info!("Client is ready!");
|
||||||
let add: TorrentAddArgs = TorrentAddArgs {
|
let add: TorrentAddArgs = TorrentAddArgs {
|
||||||
filename: Some(
|
filename: Some(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user