lychee_session => &lychee_session in logout
Signed-off-by: Louis Vallat <louis@louis-vallat.xyz>
This commit is contained in:
parent
14d801d907
commit
8e8dcece2d
@ -4,7 +4,7 @@ use json::JsonValue;
|
||||
use crate::body_to_str;
|
||||
|
||||
|
||||
pub async fn get_albums(client: &Client<HttpsConnector<HttpConnector>>, lychee_session: HeaderValue) -> JsonValue {
|
||||
pub async fn get_albums(client: &Client<HttpsConnector<HttpConnector>>, lychee_session: &HeaderValue) -> JsonValue {
|
||||
let req = Request::builder()
|
||||
.method(Method::POST)
|
||||
.uri(std::env::var("LYCHEE_ENDPOINT").unwrap() + "/api/Albums::get")
|
||||
|
@ -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<dyn std::error::Error + Send + Sync>> {
|
||||
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(())
|
||||
}
|
||||
|
@ -24,11 +24,11 @@ pub async fn login(client: &Client<HttpsConnector<HttpConnector>>) -> HeaderValu
|
||||
return lychee_session;
|
||||
}
|
||||
|
||||
pub async fn logout(client: &Client<HttpsConnector<HttpConnector>>, cookie: String) {
|
||||
pub async fn logout(client: &Client<HttpsConnector<HttpConnector>>, 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<HttpsConnector<HttpConnector>>, 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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user