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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use core::time::Duration;
mod resolvers;
mod services;
use services::{which_service, SERVICES};
#[cfg(test)]
mod tests;
pub fn is_shortened(url: &str) -> bool {
SERVICES.iter().any(|x| url.contains(x))
}
pub fn unshorten(url: &str, timeout: Option<Duration>) -> Option<String> {
let service = match which_service(url) {
Some(service) => service,
None => return None,
};
match service {
"tinyurl.com" => resolvers::tinyurl::unshort(url, timeout),
"t.co" => resolvers::twitter::unshort(url, timeout),
_ => resolvers::generic::unshort(url, timeout),
}
}