summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authoruku <[email protected]>2023-10-13 11:10:55 +0200
committerseth <[email protected]>2023-10-13 13:05:37 -0400
commitd8d0c15a1a6f3abd9915eb2ac6807d72aa4f3171 (patch)
treecd5431bea4a960389e6368352ff644f59f00b761 /src/api
parent4fe47f763f3e1ef9ec22129a7bc079ded2c90516 (diff)
use custom reqwest client for guzzle api
Diffstat (limited to 'src/api')
-rw-r--r--src/api/guzzle.rs18
1 files 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<reqwest::Client> = 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() {