aboutsummaryrefslogtreecommitdiff
path: root/src/util/web.rs
diff options
context:
space:
mode:
authorLorenz Leitner <lrnz.ltnr@gmail.com>2021-10-10 15:12:41 +0200
committerLorenz Leitner <lrnz.ltnr@gmail.com>2021-10-12 12:06:57 +0200
commited1c228094188d872ceb8407fb6f46ff698937c2 (patch)
tree7d97b610220ff57cfcbf874b45936a88571de8a7 /src/util/web.rs
parentBasic (re)implementation of gonzobot wolfram alpha (diff)
Add test
Put WA api response JSON into test resource file Add short url, increase concurrency Move shorten_url to util dir
Diffstat (limited to '')
-rw-r--r--src/util/web.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/util/web.rs b/src/util/web.rs
new file mode 100644
index 0000000..77e20a3
--- /dev/null
+++ b/src/util/web.rs
@@ -0,0 +1,20 @@
+use anyhow::{Context, Error, Result};
+use reqwest::{get, Url};
+
+// TODO: Either catinator should have a URL shortening utility module,
+// or we should start our own service
+pub(crate) async fn shorten_url(url: &str) -> Result<String, Error> {
+ // This just uses the first service gonzobot uses too
+ let short_url = get(Url::parse(&format!(
+ "https://is.gd/create.php?format=simple&url={}",
+ url
+ ))
+ .context("Failed to parse url")?)
+ .await
+ .context("Failed to make request")?
+ .text()
+ .await
+ .context("failed to get request response text")?;
+
+ Ok(short_url)
+}
tainer nameMax Audron-1/+1 2021-06-05fix tanka dependency pathMax Audron-8/+8 2021-06-05switch to https url for tanka util libMax Audron-2/+2 2021-06-05bump version to 1.0.2Max Audron-2/+2 2021-06-05add tanka ci configurationMax Audron-1/+1 2021-06-05ready tanka deploy for CIMax Audron-32/+69 2021-06-05remove tanka vendoringMax Audron-27651/+0 2021-05-26Release 1.0.1Max Audron-3/+3 2021-05-26fix log breaking once buffer fullMax Audron-2/+33 2021-05-16add deployment stuffMax Audron-6/+27786 2021-05-15add container buildMax Audron-2/+35