aboutsummaryrefslogtreecommitdiff
path: root/src/util/web.rs
diff options
context:
space:
mode:
authorMax Audron <audron@cocaine.farm>2021-10-22 19:08:59 +0200
committerMax Audron <audron@cocaine.farm>2021-10-22 19:09:39 +0200
commit309899168a086de88acf97fd6683387a7af7078c (patch)
tree846075c1e9af0d7139edae5597f1147b851ed2b2 /src/util/web.rs
parentremove wolfram alpha url shortening (diff)
write tons of documentation and reorganize some modules
Diffstat (limited to 'src/util/web.rs')
-rw-r--r--src/util/web.rs60
1 files changed, 0 insertions, 60 deletions
diff --git a/src/util/web.rs b/src/util/web.rs
deleted file mode 100644
index b9f44c1..0000000
--- a/src/util/web.rs
+++ /dev/null
@@ -1,60 +0,0 @@
-use anyhow::{Context, Error, Result};
-use async_trait::async_trait;
-use reqwest::{get, Url};
-use urlparse::quote_plus as urlparse_quote_plus;
-
-#[async_trait]
-pub trait UrlShortener {
- fn new() -> Self;
- async fn shorten(&self, url: &str) -> Result<String, Error>;
-}
-
-pub struct IsgdUrlShortener {}
-
-#[async_trait]
-impl UrlShortener for IsgdUrlShortener {
- fn new() -> Self {
- Self {}
- }
-
- async fn shorten(&self, url: &str) -> Result<String, Error> {
- Ok(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")?)
- }
-}
-
-pub fn quote_plus(text: &str) -> Result<String, Error> {
- Ok(urlparse_quote_plus(text, b"")?)
-}
-
-#[cfg(test)]
-mod tests {
- use super::quote_plus;
- use anyhow::{Error, Result};
-
- #[test]
- fn test_quote_plus_1() -> Result<(), Error> {
- assert_eq!(quote_plus("5/10")?, "5%2F10");
- Ok(())
- }
-
- #[test]
- fn test_quote_plus_2() -> Result<(), Error> {
- assert_eq!(quote_plus("1 * 2")?, "1+%2A+2");
- Ok(())
- }
-
- #[test]
- fn test_quote_plus_3() -> Result<(), Error> {
- assert_eq!(quote_plus(&quote_plus("1 * 2")?)?, "1%2B%252A%2B2");
- Ok(())
- }
-}