Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ jobs:
- macOS
- Windows

cargo-opts:
- --all-features
- --no-default-features

include:
- name: beta
toolchain: beta
Expand Down Expand Up @@ -52,13 +56,9 @@ jobs:
target
key: ${{ runner.os }}-test-${{ steps.tc.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.toml') }}

- name: Build all features
if: matrix.features == ''
run: cargo build --all-features
- run: cargo build ${{ matrix.cargo-opts }}

- name: Test all features
if: matrix.features == ''
run: cargo test --all-features
- run: cargo test ${{ matrix.cargo-opts }}

clippy:
name: Run clippy
Expand Down
20 changes: 20 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ documentation = "https://docs.rs/urlshortener"
travis-ci = { repository = "vityafx/urlshortener-rs" }

[dependencies]
http = "0.2"
url = "2"

[dependencies.reqwest]
Expand All @@ -24,3 +25,22 @@ optional = true
[features]
default = ["client"]
client = ["reqwest"]

[[example]]
name = "via_all_providers"
required-features = ["client"]

[[example]]
name = "via_auth_provider"
required-features = ["client"]

[[example]]
name = "via_kutt_custom_host_provider"
required-features = ["client"]

[[example]]
name = "via_single_provider"
required-features = ["client"]

[package.metadata.docs.rs]
all-features = true
73 changes: 39 additions & 34 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
#![deny(missing_docs)]
#![deny(warnings)]
//! # urlshortener
//!
//! An easy library for retrieving short urls.
//!
//! ## Usage
//!
//! Creating a short URL via a specified provider is very simple:
//!
//! ```rust,no_run
//! use urlshortener::{providers::Provider, client::UrlShortener};
//!
//! let us = UrlShortener::new().unwrap();
//! let short_url = us.generate("https://my-long-url.com", &Provider::IsGd);
//! assert!(short_url.is_ok());
//! ```
//!
//! Or attempting all URL shorteners until one is successfully generated:
//!
//! ```rust,no_run
//! use urlshortener::client::UrlShortener;
//!
//! let us = UrlShortener::new().unwrap();
//! let short_url = us.try_generate("https://my-long-url.com", None);
//! assert!(short_url.is_ok());
//! ```
//! In order to use service with authentication use the appropriate provider directly:
//!
//! ```rust,no_run
//! use urlshortener::{ client::UrlShortener, providers::Provider };
//!
//! let us = UrlShortener::new().unwrap();
//! let key = "MY_API_KEY";
//! let short_url = us.generate("https://my-long-url.com", &Provider::GooGl { api_key:
//! key.to_owned() });
//! assert!(short_url.is_ok());
//! ```
#![deny(missing_docs)]
#![deny(warnings)]
#[cfg_attr(
feature = "client",
doc = r##"
## Usage

Creating a short URL via a specified provider is very simple:

```rust,no_run
use urlshortener::{providers::Provider, client::UrlShortener};

let us = UrlShortener::new().unwrap();
let short_url = us.generate("https://my-long-url.com", &Provider::IsGd);
assert!(short_url.is_ok());
```

Or attempting all URL shorteners until one is successfully generated:

```rust,no_run
use urlshortener::client::UrlShortener;

let us = UrlShortener::new().unwrap();
let short_url = us.try_generate("https://my-long-url.com", None);
assert!(short_url.is_ok());
```
In order to use service with authentication use the appropriate provider directly:

```rust,no_run
use urlshortener::{ client::UrlShortener, providers::Provider };

let us = UrlShortener::new().unwrap();
let key = "MY_API_KEY";
let short_url = us.generate("https://my-long-url.com", &Provider::GooGl { api_key:
key.to_owned() });
assert!(short_url.is_ok());
```
"##
)]

/// A urlshortener http client for performing requests.
#[cfg(feature = "client")]
Expand Down
2 changes: 1 addition & 1 deletion src/providers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Library service providers implementation.

use crate::request as req;
use reqwest::header::HeaderMap;
use http::header::HeaderMap;
use url::form_urlencoded;

/// A user agent for faking weird services.
Expand Down
10 changes: 5 additions & 5 deletions src/request.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use http::header;
#[cfg(feature = "client")]
use reqwest::{
blocking::{Client, Response},
header::{self, HeaderMap},
};
use reqwest::blocking::{Client, Response};

#[cfg(feature = "client")]
const CONTENT_JSON: &str = "application/json";
#[cfg(feature = "client")]
const CONTENT_FORM_URL_ENCODED: &str = "application/x-www-form-urlencoded";

/// An HTTP method abstraction
Expand Down Expand Up @@ -41,7 +41,7 @@ pub struct Request {
/// The user agent.
pub user_agent: Option<UserAgent>,
/// Request headers.
pub headers: Option<HeaderMap>,
pub headers: Option<header::HeaderMap>,
/// The HTTP method.
pub method: Method,
}
Expand Down