Skip to content

Commit

Permalink
Merge pull request #24 from TimothyYe/master
Browse files Browse the repository at this point in the history
  • Loading branch information
iddm authored Mar 9, 2024
2 parents 01bfe3c + 0e5c2f2 commit 7412d28
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Without authentication:
- `bmeo.org`
- `hmm.rs`
- `url-shortener.io`
- `biturl.top`

The following services are supported, but are discouraged from use, due to
restrictions such as rate limits:
Expand Down
15 changes: 15 additions & 0 deletions src/providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub const PROVIDERS: &[Provider] = &[
Provider::Bmeo,
Provider::UrlShortenerIo,
Provider::HmmRs,
Provider::BitUrl,
// The following list are items that have long response sometimes:
Provider::TnyIm,
// The following list are items that are discouraged from use:
Expand Down Expand Up @@ -245,6 +246,8 @@ pub enum Provider {
UrlShortenerIo,
/// <https://v.gd> provider
VGd,
/// <https://biturl.top> provider
BitUrl
}

impl Provider {
Expand Down Expand Up @@ -275,6 +278,7 @@ impl Provider {
Provider::TnyIm => "tny.im",
Provider::UrlShortenerIo => "url-shortener.io",
Provider::VGd => "v.gd",
Provider::BitUrl => "biturl.top",
}
}
}
Expand Down Expand Up @@ -462,6 +466,15 @@ request!(
"http://v.gd/create.php?format=simple&url={}"
);

parse_json_tag!(biturl_parse, "short", "");
request!(
biturl_req,
req::Method::Post,
"https://api.biturl.top/short",
"url={}",
req::ContentType::FormUrlEncoded
);

/// Parses the response from a successful request to a provider into the
/// URL-shortened string.
pub fn parse(res: &str, provider: &Provider) -> Result<String, ProviderError> {
Expand All @@ -487,6 +500,7 @@ pub fn parse(res: &str, provider: &Provider) -> Result<String, ProviderError> {
Provider::TnyIm => tnyim_parse(res),
Provider::UrlShortenerIo => urlshortenerio_parse(res),
Provider::VGd => vgd_parse(res),
Provider::BitUrl => biturl_parse(res),
}
.ok_or(ProviderError::Deserialize)
}
Expand Down Expand Up @@ -534,5 +548,6 @@ pub fn request(url: &str, provider: &Provider) -> req::Request {
Provider::TnyIm => tnyim_req(url),
Provider::UrlShortenerIo => urlshortenerio_req(url),
Provider::VGd => vgd_req(url),
Provider::BitUrl => biturl_req(url),
}
}

0 comments on commit 7412d28

Please sign in to comment.