diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8f990c41..561cc939 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,10 @@ jobs: - macOS - Windows + cargo-opts: + - --all-features + - --no-default-features + include: - name: beta toolchain: beta @@ -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 diff --git a/Cargo.toml b/Cargo.toml index 2d6732fc..5b7f6a5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ documentation = "https://docs.rs/urlshortener" travis-ci = { repository = "vityafx/urlshortener-rs" } [dependencies] +http = "0.2" url = "2" [dependencies.reqwest] @@ -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 diff --git a/src/lib.rs b/src/lib.rs index 4b04ba5e..1cd91fa4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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")] diff --git a/src/providers.rs b/src/providers.rs index 672fbaa5..f8e56ab8 100644 --- a/src/providers.rs +++ b/src/providers.rs @@ -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. diff --git a/src/request.rs b/src/request.rs index 803d70a8..c158ded0 100644 --- a/src/request.rs +++ b/src/request.rs @@ -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 @@ -41,7 +41,7 @@ pub struct Request { /// The user agent. pub user_agent: Option, /// Request headers. - pub headers: Option, + pub headers: Option, /// The HTTP method. pub method: Method, }