diff --git a/src/albums.rs b/src/albums.rs index d4a97bf..92fa943 100644 --- a/src/albums.rs +++ b/src/albums.rs @@ -4,7 +4,7 @@ use json::JsonValue; use crate::body_to_str; -pub async fn get_albums(client: &Client>, lychee_session: HeaderValue) -> JsonValue { +pub async fn get_albums(client: &Client>, lychee_session: &HeaderValue) -> JsonValue { let req = Request::builder() .method(Method::POST) .uri(std::env::var("LYCHEE_ENDPOINT").unwrap() + "/api/Albums::get") diff --git a/src/main.rs b/src/main.rs index 7c381c7..4b6d5c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use hyper_tls::HttpsConnector; use hyper::{Body, Client, Response}; -use crate::session::login; +use crate::session::{login, logout}; use crate::albums::get_albums; use dotenv::dotenv; @@ -21,7 +21,8 @@ async fn main() -> Result<(), Box> { let https = HttpsConnector::new(); let client = Client::builder().build::<_, hyper::Body>(https); let lychee_session = login(&client).await; - let albums = get_albums(&client, lychee_session).await; + let albums = get_albums(&client, &lychee_session).await; + logout(&client, &lychee_session).await; println!("{}", albums["albums"].pretty(4)); Ok(()) } diff --git a/src/session.rs b/src/session.rs index 1969610..90688e9 100644 --- a/src/session.rs +++ b/src/session.rs @@ -24,11 +24,11 @@ pub async fn login(client: &Client>) -> HeaderValu return lychee_session; } -pub async fn logout(client: &Client>, cookie: String) { +pub async fn logout(client: &Client>, lychee_session: &HeaderValue) { let req = Request::builder() .method(Method::POST) .uri(std::env::var("LYCHEE_ENDPOINT").unwrap() + "/api/Session::logout") - .header(COOKIE.as_str(), cookie) + .header(COOKIE.as_str(), lychee_session) .header(AUTHORIZATION, std::env::var("LYCHEE_API_KEY").unwrap()) .body(Body::empty()) .expect("error"); @@ -39,7 +39,7 @@ pub async fn logout(client: &Client>, cookie: Stri #[cfg(test)] mod session_tests { use hyper_tls::HttpsConnector; - use hyper::{Client, client::HttpConnector}; + use hyper::{Client, client::HttpConnector, header::HeaderValue}; use json::object; use mockito::mock; use crate::session::{login, logout}; @@ -64,7 +64,7 @@ mod session_tests { .match_header("cookie", "cookie value") .create(); - tokio_test::block_on(logout(&client, "cookie value".to_string())); + tokio_test::block_on(logout(&client, &HeaderValue::from_str("cookie value").unwrap())); m.assert(); } @@ -77,7 +77,7 @@ mod session_tests { .match_header("cookie", "cookie value") .create(); - tokio_test::block_on(logout(&client, "cookie value".to_string())); + tokio_test::block_on(logout(&client, &HeaderValue::from_str("cookie value").unwrap())); m.assert(); }