diff options
| author | Lorenz Leitner <lrnz.ltnr@gmail.com> | 2021-10-10 15:12:41 +0200 |
|---|---|---|
| committer | Lorenz Leitner <lrnz.ltnr@gmail.com> | 2021-10-12 12:06:57 +0200 |
| commit | ed1c228094188d872ceb8407fb6f46ff698937c2 (patch) | |
| tree | 7d97b610220ff57cfcbf874b45936a88571de8a7 /src/util | |
| parent | Basic (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 'src/util')
| -rw-r--r-- | src/util/mod.rs | 1 | ||||
| -rw-r--r-- | src/util/web.rs | 20 |
2 files changed, 21 insertions, 0 deletions
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<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) +} |
