summaryrefslogtreecommitdiff
path: root/src/http/teawie.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/http/teawie.rs')
-rw-r--r--src/http/teawie.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/http/teawie.rs b/src/http/teawie.rs
new file mode 100644
index 0000000..368fad5
--- /dev/null
+++ b/src/http/teawie.rs
@@ -0,0 +1,28 @@
+use eyre::{bail, OptionExt, Result};
+use serde::{Deserialize, Serialize};
+
+// https://github.com/getchoo/teawieAPI
+#[derive(Deserialize, Serialize)]
+struct RandomTeawieResponse {
+ url: Option<String>,
+ error: Option<String>,
+}
+
+// TODO: read this from an env var
+const TEAWIE: &str = "https://api.getchoo.com";
+const RANDOM: &str = "/random_teawie";
+
+pub async fn random<T>(http: &T) -> Result<String>
+where
+ T: super::Ext,
+{
+ let url = format!("{TEAWIE}{RANDOM}");
+ let json: RandomTeawieResponse = http.get_json(&url).await?;
+
+ if let Some(error) = json.error {
+ bail!("TeawieAPI reported error: {error}");
+ };
+
+ json.url
+ .ok_or_eyre("TeawieAPI didn't return an error or URL???")
+}