Skip to content

Commit f21e958

Browse files
committed
Extract login into seperate method
1 parent 02e156b commit f21e958

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

integration/main.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,22 @@ async fn test() -> Result<(), anyhow::Error>{
3838
dotenv::dotenv().map_err(|e|Error::DotenvInitError(e))?;
3939
let username = dotenv::var("USERNAME").map_err(|e|Error::NoUsername(e))?;
4040
let password = dotenv::var("PASSWORD").map_err(|e|Error::NoPassword(e))?;
41+
42+
let mut client = vrchatapi::apis::configuration::Configuration::default();
43+
client.user_agent = Some(format!("vrchatapi-rust@{VERSION} https://github.com/vrchatapi/vrchatapi-rust/issues/new"));
44+
client.basic_auth = Some((username.clone(), Some(password)));
45+
let u = login(&client, &username).await?;
46+
47+
logout(&client).await?;
48+
Ok(())
49+
}
50+
51+
async fn login(client: &vrchatapi::apis::configuration::Configuration, username: &String) -> Result<vrchatapi::models::CurrentUser, anyhow::Error> {
4152
let totp_secret = dotenv::var("TOTP_SECRET").map_err(|e|Error::NoTotpSecret(e))?;
4253
let totp_secret = base32::decode(Alphabet::Rfc4648Lower {padding: false}, totp_secret.as_str()).ok_or(Error::TOTPBase32)?;
4354
let generator = totp_rfc6238::TotpGenerator::new()
4455
.build();
4556

46-
let mut client = vrchatapi::apis::configuration::Configuration::default();
47-
client.user_agent = Some(format!("vrchatapi-rust@{VERSION} https://github.com/vrchatapi/vrchatapi-rust/issues/new"));
48-
client.basic_auth = Some((username.clone(), Some(password)));
4957
let u = match vrchatapi::apis::authentication_api::get_current_user(&client).await.map_err(|e|Error::GetCurrentUser(e))? {
5058
EitherUserOrTwoFactor::CurrentUser(u) => u,
5159
EitherUserOrTwoFactor::RequiresTwoFactorAuth(r2fa) => {
@@ -68,11 +76,8 @@ async fn test() -> Result<(), anyhow::Error>{
6876
}
6977
};
7078
println!("Logged in as: {} (Login Name was {username}", u.username.as_ref().map(String::as_str).unwrap_or("Unknown User"));
71-
72-
logout(&client).await?;
73-
Ok(())
79+
Ok(u)
7480
}
75-
7681
async fn logout(client: &vrchatapi::apis::configuration::Configuration) -> Result<(), anyhow::Error> {
7782
vrchatapi::apis::authentication_api::logout(&client).await.map_err(|e|Error::Logout(e))?;
7883
Ok(())

0 commit comments

Comments
 (0)