diff options
| author | seth <[email protected]> | 2023-04-04 23:23:28 -0400 |
|---|---|---|
| committer | seth <[email protected]> | 2023-04-05 20:34:12 -0400 |
| commit | 65d0b7a553f718b1ba34799e604ceb07c062af61 (patch) | |
| tree | 9a6b1c78aa6e79c2201ba124b536a05231b0ae20 /src/api | |
| parent | ed076bbd6fc22b32ea353ae6bd3cac79d039719a (diff) | |
rewrite in rust :)
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/guzzle.rs | 25 | ||||
| -rw-r--r-- | src/api/mod.rs | 1 |
2 files changed, 26 insertions, 0 deletions
diff --git a/src/api/guzzle.rs b/src/api/guzzle.rs new file mode 100644 index 0000000..88944ef --- /dev/null +++ b/src/api/guzzle.rs @@ -0,0 +1,25 @@ +use reqwest::StatusCode; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize)] +struct GuzzleResponse { + pub url: String, +} + +const GUZZLE: &str = "http://198.199.68.30"; + +pub async fn get_random_teawie() -> String { + let endpoint = "/get_random_teawie"; + let resp = reqwest::get(GUZZLE.to_owned() + endpoint).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() { + StatusCode::OK => match resp.json::<GuzzleResponse>().await { + Ok(data) => data.url, + Err(why) => format!("{} ({:?})", err_msg, why), + }, + other => format!("{} ({:?})", err_msg, other), + } +} diff --git a/src/api/mod.rs b/src/api/mod.rs new file mode 100644 index 0000000..c2ad56f --- /dev/null +++ b/src/api/mod.rs @@ -0,0 +1 @@ +pub mod guzzle; |
