1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
extern crate reqwest; use std::io::Read; /// `shorten` returns a `String` representing the shortened URL /// `varys` uses https://is.gd/ to shorten a url /// /// # Arguments /// /// * `url` - URL to shorten /// /// # Panics /// /// `shorten` panics if the request is not successful. /// /// # Example /// /// `let shortened_url: String = varys::shorten("https://www.rust-lang.org/"); /// // => https://is.gd/jK51hw /// ` /// pub fn shorten(url: &'static str) -> String { let url = &format!("https://is.gd/create.php?format=simple&url={}", url)[..]; let mut response = reqwest::get(url).unwrap(); assert!(response.status().is_success()); let mut body = String::new(); response.read_to_string(&mut body); body }