Skip to content

Commit

Permalink
Return a client instead of the builder
Browse files Browse the repository at this point in the history
  • Loading branch information
thoiberg committed Jul 4, 2023
1 parent 279f5a7 commit 6be5aa0
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions backend/src/api/satori/request.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::env;

use axum::Json;
use reqwest::{Client, ClientBuilder, StatusCode};
use reqwest::{Client, StatusCode};

use crate::api::{internal_error, ErrorResponse};

Expand All @@ -17,7 +17,7 @@ pub async fn satori_handler() -> Result<Json<SatoriData>, (StatusCode, Json<Erro
}

async fn get_current_cards() -> anyhow::Result<SatoriCurrentCardsResponse> {
let client = satori_client()?.build()?;
let client = satori_client()?;

client
.get("https://www.satorireader.com/api/studylist/due/count")
Expand All @@ -38,7 +38,6 @@ async fn get_new_cards() -> anyhow::Result<SatoriNewCardsResponse> {
let client = satori_client()?;

client
.build()?
.get("https://www.satorireader.com/api/studylist/pending-auto-importable/count")
.send()
.await?
Expand All @@ -53,15 +52,16 @@ fn serialize_new_cards_response(body: &str) -> anyhow::Result<SatoriNewCardsResp
Ok(json_data)
}

fn satori_client() -> anyhow::Result<ClientBuilder> {
fn satori_client() -> anyhow::Result<Client> {
let satori_cookie = env::var("SATORI_COOKIE")?;

let mut headers = reqwest::header::HeaderMap::new();
headers.insert(
"Cookie",
format!("SessionToken={}", satori_cookie).parse().unwrap(),
);
Ok(Client::builder().default_headers(headers))

Ok(Client::builder().default_headers(headers).build()?)
}

#[cfg(test)]
Expand Down

0 comments on commit 6be5aa0

Please sign in to comment.