From d8d0c15a1a6f3abd9915eb2ac6807d72aa4f3171 Mon Sep 17 00:00:00 2001 From: uku Date: Fri, 13 Oct 2023 11:10:55 +0200 Subject: use custom reqwest client for guzzle api --- src/api/guzzle.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/api/guzzle.rs b/src/api/guzzle.rs index 0321127..b58f323 100644 --- a/src/api/guzzle.rs +++ b/src/api/guzzle.rs @@ -1,3 +1,4 @@ +use once_cell::sync::Lazy; use reqwest::StatusCode; use serde::{Deserialize, Serialize}; @@ -8,11 +9,22 @@ struct GuzzleResponse { const GUZZLE: &str = "https://api.mydadleft.me"; +pub static REQWEST_CLIENT: Lazy = Lazy::new(|| { + reqwest::Client::builder() + .user_agent("teawieBot/0.1.0") + .build() + .unwrap_or_default() +}); + pub async fn get_random_teawie() -> String { let endpoint = "get_random_teawie"; - let resp = reqwest::get(format!("{GUZZLE}/{endpoint}")).await.unwrap(); // why did i have to own - // this constant? i have - // no idea! + let req = REQWEST_CLIENT + .get(format!("{GUZZLE}/{endpoint}")) + .build() + .unwrap(); + let resp = REQWEST_CLIENT.execute(req).await.unwrap(); // why did i have to own + // this constant? i have + // no idea! let err_msg = "couldn't get a teawie"; match resp.status() { -- cgit v1.2.3