From ed1c228094188d872ceb8407fb6f46ff698937c2 Mon Sep 17 00:00:00 2001 From: Lorenz Leitner Date: Sun, 10 Oct 2021 15:12:41 +0200 Subject: Add test Put WA api response JSON into test resource file Add short url, increase concurrency Move shorten_url to util dir --- src/util/mod.rs | 1 + src/util/web.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 src/util/mod.rs create mode 100644 src/util/web.rs (limited to 'src/util') diff --git a/src/util/mod.rs b/src/util/mod.rs new file mode 100644 index 0000000..fdd4603 --- /dev/null +++ b/src/util/mod.rs @@ -0,0 +1 @@ +pub mod web; 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 { + // 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) +} -- cgit v1.2.3