Struct urlshortener::UrlShortener [] [src]

pub struct UrlShortener { /* fields omitted */ }

Url shortener: the way to retrieve a short url.

Methods

impl UrlShortener
[src]

Creates new UrlShortener with default (3 seconds) timeout.

Creates new UrlShortener with custom read timeout.

Try to generate a short URL from each provider, iterating over each provider until a short URL is successfully generated. If you wish to override the list or providers or their priority, provide your own list of providers as second argument.

Examples

use urlshortener::UrlShortener;

let us = UrlShortener::new().unwrap();
let long_url = "https://rust-lang.org";
let _short_url = us.try_generate(long_url, None);
use urlshortener::{UrlShortener, Provider};

let us = UrlShortener::new().unwrap();
let providers = vec![
    Provider::GooGl { api_key: "MY_API_KEY".to_owned() },
    Provider::IsGd,
];
let long_url = "https://rust-lang.org";
let _short_url = us.try_generate(long_url, Some(providers));

Errors

Returns an Error<ErrorKind::Other> if there is an error generating a short URL from all providers.

Attempts to get a short URL using the specified provider.

Examples

use urlshortener::{Provider, UrlShortener};

let us = UrlShortener::new().unwrap();
let long_url = "http://rust-lang.org";
let _short_url = us.generate(long_url, &Provider::IsGd);
use urlshortener::{Provider, UrlShortener};

let us = UrlShortener::new().unwrap();
let api_key = "MY_API_KEY".to_owned();
let long_url = "http://rust-lang.org";
let _short_url = us.generate(long_url, &Provider::GooGl { api_key: api_key });

Errors

Returns an std::io::Error if there is an error generating a short URL from the given provider due to either:

a. a decode error (ErrorKind::Other); b. the service being unavailable (ErrorKind::ConnectionAborted)

Trait Implementations

impl Debug for UrlShortener
[src]

Formats the value using the given formatter.