urlshortener-3.0.2/.cargo_vcs_info.json0000644000000001360000000000100135720ustar { "git": { "sha1": "1f483fe0af432f42b3c62f0ee7d5ca02816c16d1" }, "path_in_vcs": "" }urlshortener-3.0.2/.github/FUNDING.yml000064400000000000000000000000201046102023000155270ustar 00000000000000github: vityafx urlshortener-3.0.2/.github/dependabot.yml000064400000000000000000000002211046102023000165450ustar 00000000000000version: 2 updates: - package-ecosystem: cargo directory: "/" schedule: interval: daily time: "22:00" open-pull-requests-limit: 10 urlshortener-3.0.2/.github/workflows/ci.yml000064400000000000000000000062171046102023000171030ustar 00000000000000name: CI on: [push, pull_request] env: minrust: 1.56.0 jobs: test: name: Test runs-on: ${{ matrix.os || 'ubuntu-latest' }} strategy: fail-fast: false matrix: name: - stable - beta - nightly - macOS - Windows include: - name: beta toolchain: beta - name: nightly toolchain: nightly - name: macOS os: macOS-latest - name: Windows os: windows-latest steps: - name: Checkout sources uses: actions/checkout@v2 - name: Install toolchain id: tc uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.toolchain || 'stable' }} profile: minimal override: true - name: Setup cache if: runner.os != 'macOS' uses: actions/cache@v2 with: path: | ~/.cargo/registry ~/.cargo/git 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 - name: Test all features if: matrix.features == '' run: cargo test --all-features clippy: name: Run clippy runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v2 - name: Install toolchain id: tc uses: actions-rs/toolchain@v1 with: toolchain: stable profile: minimal override: true - name: Setup cache uses: actions/cache@v2 with: path: | ~/.cargo/registry ~/.cargo/git target key: ${{ runner.os }}-clippy-${{ steps.tc.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.toml') }} - run: cargo clippy MSRV: runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v2 - name: Install toolchain (${{ env.minrust }}) id: tc uses: actions-rs/toolchain@v1 with: toolchain: ${{ env.minrust }} profile: minimal override: true - name: Setup cache uses: actions/cache@v2 with: path: | ~/.cargo/registry ~/.cargo/git target key: ${{ runner.os }}-msrv-${{ steps.tc.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.toml') }} - run: cargo check --all-features doc: name: Build docs runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v2 - name: Install toolchain id: tc uses: actions-rs/toolchain@v1 with: toolchain: nightly profile: minimal override: true - name: Setup cache uses: actions/cache@v2 with: path: | ~/.cargo/registry ~/.cargo/git key: ${{ runner.os }}-docs-${{ steps.tc.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.toml') }} - name: Build docs run: | cargo doc urlshortener-3.0.2/.github/workflows/lint.yml000064400000000000000000000025341046102023000174540ustar 00000000000000# Copied from Twilight's Lint workflow. # # https://github.com/twilight-rs/twilight/blob/trunk/.github/workflows/lint.yml name: Lint on: [push, pull_request] jobs: clippy: name: Clippy runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v2 - name: Install stable toolchain id: toolchain uses: actions-rs/toolchain@v1 with: toolchain: nightly components: clippy profile: minimal override: true - name: Setup cache uses: actions/cache@v2 with: path: | ~/.cargo/registry ~/.cargo/git target key: ${{ runner.os }}-clippy-rustc-${{ steps.toolchain.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.lock') }} - name: Run clippy uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} args: --workspace --tests rustfmt: name: Format runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v2 - name: Install stable toolchain uses: actions-rs/toolchain@v1 with: toolchain: nightly components: rustfmt profile: minimal override: true - name: Run cargo fmt run: cargo fmt --all -- --checkurlshortener-3.0.2/.github/workflows/nightly.yml000064400000000000000000000070721046102023000201660ustar 00000000000000name: Nightly Build on: schedule: - cron: '0 2 * * *' env: minrust: 1.56.0 jobs: test: name: Test runs-on: ${{ matrix.os || 'ubuntu-latest' }} strategy: fail-fast: false matrix: name: - stable - beta - nightly - macOS - Windows include: - name: beta toolchain: beta - name: nightly toolchain: nightly - name: macOS os: macOS-latest - name: Windows os: windows-latest steps: - name: Checkout sources uses: actions/checkout@v2 - name: Install toolchain id: tc uses: actions-rs/toolchain@v1 with: toolchain: ${{ matrix.toolchain || 'stable' }} profile: minimal override: true - name: Setup cache if: runner.os != 'macOS' uses: actions/cache@v2 with: path: | ~/.cargo/registry ~/.cargo/git 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 - name: Test all features if: matrix.features == '' run: cargo test --all-features rustfmt: name: Format runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v2 - name: Install stable toolchain uses: actions-rs/toolchain@v1 with: toolchain: nightly components: rustfmt profile: minimal override: true - name: Run cargo fmt run: cargo fmt --all -- --check clippy: name: Clippy runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v2 - name: Install toolchain id: tc uses: actions-rs/toolchain@v1 with: toolchain: stable profile: minimal override: true - name: Setup cache uses: actions/cache@v2 with: path: | ~/.cargo/registry ~/.cargo/git target key: ${{ runner.os }}-clippy-${{ steps.tc.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.toml') }} - run: cargo clippy MSRV: runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v2 - name: Install toolchain (${{ env.minrust }}) id: tc uses: actions-rs/toolchain@v1 with: toolchain: ${{ env.minrust }} profile: minimal override: true - name: Setup cache uses: actions/cache@v2 with: path: | ~/.cargo/registry ~/.cargo/git target key: ${{ runner.os }}-msrv-${{ steps.tc.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.toml') }} - run: cargo check --all-features doc: name: Build docs runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v2 - name: Install toolchain id: tc uses: actions-rs/toolchain@v1 with: toolchain: nightly profile: minimal override: true - name: Setup cache uses: actions/cache@v2 with: path: | ~/.cargo/registry ~/.cargo/git key: ${{ runner.os }}-docs-${{ steps.tc.outputs.rustc_hash }}-${{ hashFiles('**/Cargo.toml') }} - name: Build docs run: | cargo doc urlshortener-3.0.2/.gitignore000064400000000000000000000000361046102023000143510ustar 00000000000000target Cargo.lock *.swo *.swp urlshortener-3.0.2/.travis.yml000064400000000000000000000007131046102023000144740ustar 00000000000000language: rust rust: - stable - beta os: - linux - windows - osx dist: xenial matrix: allow_failures: - nightly before_script: - export PATH="$PATH:$HOME/.cargo/bin" - rustup component add rustfmt - rustup component add clippy script: - cargo check - cargo fmt --verbose --all -- --check - cargo clippy - cargo test --verbose $FEATURES -- --nocapture addons: apt: packages: - libssl-dev notifications: email: false urlshortener-3.0.2/Cargo.lock0000644000000627110000000000100115540ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "base64" version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bumpalo" version = "3.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" [[package]] name = "bytes" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" [[package]] name = "cc" version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f" [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "core-foundation" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" dependencies = [ "core-foundation-sys", "libc", ] [[package]] name = "core-foundation-sys" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "encoding_rs" version = "0.8.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" dependencies = [ "cfg-if", ] [[package]] name = "fastrand" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" dependencies = [ "instant", ] [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "foreign-types" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ "foreign-types-shared", ] [[package]] name = "foreign-types-shared" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" dependencies = [ "percent-encoding", ] [[package]] name = "futures-channel" version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52ba265a92256105f45b719605a571ffe2d1f0fea3807304b522c1d778f79eed" dependencies = [ "futures-core", ] [[package]] name = "futures-core" version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04909a7a7e4633ae6c4a9ab280aeb86da1236243a77b694a49eacd659a4bd3ac" [[package]] name = "futures-io" version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00f5fb52a06bdcadeb54e8d3671f8888a39697dcb0b81b23b55174030427f4eb" [[package]] name = "futures-sink" version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39c15cf1a4aa79df40f1bb462fb39676d0ad9e366c2a33b590d7c66f4f81fcf9" [[package]] name = "futures-task" version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2ffb393ac5d9a6eaa9d3fdf37ae2776656b706e200c8e16b1bdb227f5198e6ea" [[package]] name = "futures-util" version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "197676987abd2f9cadff84926f410af1c183608d36641465df73ae8211dc65d6" dependencies = [ "futures-core", "futures-io", "futures-task", "memchr", "pin-project-lite", "pin-utils", "slab", ] [[package]] name = "h2" version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" dependencies = [ "bytes", "fnv", "futures-core", "futures-sink", "futures-util", "http", "indexmap", "slab", "tokio", "tokio-util", "tracing", ] [[package]] name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hermit-abi" version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] [[package]] name = "http" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" dependencies = [ "bytes", "fnv", "itoa", ] [[package]] name = "http-body" version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" dependencies = [ "bytes", "http", "pin-project-lite", ] [[package]] name = "httparse" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "hyper" version = "0.14.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "034711faac9d2166cb1baf1a2fb0b60b1f277f8492fd72176c17f3515e1abd3c" dependencies = [ "bytes", "futures-channel", "futures-core", "futures-util", "h2", "http", "http-body", "httparse", "httpdate", "itoa", "pin-project-lite", "socket2", "tokio", "tower-service", "tracing", "want", ] [[package]] name = "hyper-tls" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ "bytes", "hyper", "native-tls", "tokio", "tokio-native-tls", ] [[package]] name = "idna" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" dependencies = [ "unicode-bidi", "unicode-normalization", ] [[package]] name = "indexmap" version = "1.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" dependencies = [ "autocfg", "hashbrown", ] [[package]] name = "instant" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ "cfg-if", ] [[package]] name = "ipnet" version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f88c5561171189e69df9d98bcf18fd5f9558300f7ea7b801eb8a0fd748bd8745" [[package]] name = "itoa" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" [[package]] name = "js-sys" version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" version = "0.2.137" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" [[package]] name = "log" version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if", ] [[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mime" version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" [[package]] name = "mio" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" dependencies = [ "libc", "log", "wasi", "windows-sys 0.42.0", ] [[package]] name = "native-tls" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" dependencies = [ "lazy_static", "libc", "log", "openssl", "openssl-probe", "openssl-sys", "schannel", "security-framework", "security-framework-sys", "tempfile", ] [[package]] name = "num_cpus" version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" dependencies = [ "hermit-abi", "libc", ] [[package]] name = "once_cell" version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "openssl" version = "0.10.42" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" dependencies = [ "bitflags", "cfg-if", "foreign-types", "libc", "once_cell", "openssl-macros", "openssl-sys", ] [[package]] name = "openssl-macros" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" version = "0.9.77" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b03b84c3b2d099b81f0953422b4d4ad58761589d0229b5506356afca05a3670a" dependencies = [ "autocfg", "cc", "libc", "pkg-config", "vcpkg", ] [[package]] name = "percent-encoding" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pin-project-lite" version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" [[package]] name = "pin-utils" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "proc-macro2" version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] [[package]] name = "redox_syscall" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] [[package]] name = "remove_dir_all" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ "winapi", ] [[package]] name = "reqwest" version = "0.11.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68cc60575865c7831548863cc02356512e3f1dc2f3f82cb837d7fc4cc8f3c97c" dependencies = [ "base64", "bytes", "encoding_rs", "futures-core", "futures-util", "h2", "http", "http-body", "hyper", "hyper-tls", "ipnet", "js-sys", "log", "mime", "native-tls", "once_cell", "percent-encoding", "pin-project-lite", "serde", "serde_json", "serde_urlencoded", "tokio", "tokio-native-tls", "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", "winreg", ] [[package]] name = "ryu" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "schannel" version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" dependencies = [ "lazy_static", "windows-sys 0.36.1", ] [[package]] name = "security-framework" version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" dependencies = [ "bitflags", "core-foundation", "core-foundation-sys", "libc", "security-framework-sys", ] [[package]] name = "security-framework-sys" version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" dependencies = [ "core-foundation-sys", "libc", ] [[package]] name = "serde" version = "1.0.147" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d193d69bae983fc11a79df82342761dfbf28a99fc8d203dca4c3c1b590948965" [[package]] name = "serde_json" version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e8b3801309262e8184d9687fb697586833e939767aea0dda89f5a8e650e8bd7" dependencies = [ "itoa", "ryu", "serde", ] [[package]] name = "serde_urlencoded" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ "form_urlencoded", "itoa", "ryu", "serde", ] [[package]] name = "slab" version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" dependencies = [ "autocfg", ] [[package]] name = "socket2" version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" dependencies = [ "libc", "winapi", ] [[package]] name = "syn" version = "1.0.103" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a864042229133ada95abf3b54fdc62ef5ccabe9515b64717bcb9a1919e59445d" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "tempfile" version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ "cfg-if", "fastrand", "libc", "redox_syscall", "remove_dir_all", "winapi", ] [[package]] name = "tinyvec" version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" dependencies = [ "tinyvec_macros", ] [[package]] name = "tinyvec_macros" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" version = "1.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d76ce4a75fb488c605c54bf610f221cea8b0dafb53333c1a67e8ee199dcd2ae3" dependencies = [ "autocfg", "bytes", "libc", "memchr", "mio", "num_cpus", "pin-project-lite", "socket2", "winapi", ] [[package]] name = "tokio-native-tls" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" dependencies = [ "native-tls", "tokio", ] [[package]] name = "tokio-util" version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" dependencies = [ "bytes", "futures-core", "futures-sink", "pin-project-lite", "tokio", "tracing", ] [[package]] name = "tower-service" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ "cfg-if", "pin-project-lite", "tracing-core", ] [[package]] name = "tracing-core" version = "0.1.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" dependencies = [ "once_cell", ] [[package]] name = "try-lock" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "unicode-bidi" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" [[package]] name = "unicode-normalization" version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" dependencies = [ "tinyvec", ] [[package]] name = "url" version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" dependencies = [ "form_urlencoded", "idna", "percent-encoding", ] [[package]] name = "urlshortener" version = "3.0.2" dependencies = [ "reqwest", "url", ] [[package]] name = "vcpkg" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "want" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" dependencies = [ "log", "try-lock", ] [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", "syn", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" dependencies = [ "cfg-if", "js-sys", "wasm-bindgen", "web-sys", ] [[package]] name = "wasm-bindgen-macro" version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "web-sys" version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" dependencies = [ "js-sys", "wasm-bindgen", ] [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" dependencies = [ "windows_aarch64_msvc 0.36.1", "windows_i686_gnu 0.36.1", "windows_i686_msvc 0.36.1", "windows_x86_64_gnu 0.36.1", "windows_x86_64_msvc 0.36.1", ] [[package]] name = "windows-sys" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc 0.42.0", "windows_i686_gnu 0.42.0", "windows_i686_msvc 0.42.0", "windows_x86_64_gnu 0.42.0", "windows_x86_64_gnullvm", "windows_x86_64_msvc 0.42.0", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" [[package]] name = "windows_aarch64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" [[package]] name = "windows_aarch64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" [[package]] name = "windows_i686_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" [[package]] name = "windows_i686_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" [[package]] name = "windows_i686_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" [[package]] name = "windows_i686_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" [[package]] name = "windows_x86_64_gnu" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" [[package]] name = "windows_x86_64_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" [[package]] name = "windows_x86_64_gnullvm" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" [[package]] name = "windows_x86_64_msvc" version = "0.36.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" [[package]] name = "windows_x86_64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" [[package]] name = "winreg" version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ "winapi", ] urlshortener-3.0.2/Cargo.toml0000644000000020030000000000100115630ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "urlshortener" version = "3.0.2" authors = ["Victor Polevoy "] description = "A very simple url shortener client library" documentation = "https://docs.rs/urlshortener" readme = "README.md" keywords = [ "url", "short", "shortener", "link", ] license = "MIT" repository = "https://github.com/vityafx/urlshortener-rs" [dependencies.reqwest] version = "0.11" features = ["blocking"] optional = true [dependencies.url] version = "2" [features] client = ["reqwest"] default = ["client"] urlshortener-3.0.2/Cargo.toml.orig000064400000000000000000000010251046102023000152470ustar 00000000000000[package] name = "urlshortener" version = "3.0.2" edition = "2018" authors = ["Victor Polevoy "] description = "A very simple url shortener client library" readme = "README.md" license = "MIT" keywords = ["url", "short", "shortener", "link"] repository = "https://github.com/vityafx/urlshortener-rs" documentation = "https://docs.rs/urlshortener" [dependencies] url = "2" [dependencies.reqwest] version = "0.11" features = ["blocking"] optional = true [features] default = ["client"] client = ["reqwest"] urlshortener-3.0.2/LICENSE000064400000000000000000000020571046102023000133730ustar 00000000000000MIT License Copyright (c) 2016 Victor Polevoy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. urlshortener-3.0.2/README.md000064400000000000000000000062341046102023000136460ustar 00000000000000# urlshortener-rs [![Crates badge](https://img.shields.io/crates/v/urlshortener.svg)](https://crates.io/crates/urlshortener) [![CI](https://github.com/vityafx/urlshortener-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/vityafx/urlshortener-rs/actions/workflows/ci.yml) [![](https://docs.rs/urlshortener/badge.svg)](https://docs.rs/urlshortener) [![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE) A very simple urlshortener for Rust. This library aims to implement as much URL shortener services as possible and to provide an interface as minimal and simple as possible. For easing pain with dependency hell, the library provides request objects since 0.9.0 version which can be used for performing requests via user http-client library. ## MSRV The minimum supported rust version is bumped to 1.56 just because one of the dependencies. The code itself should work fine with Rust version 1.46, and, perhaps, even lower versions. ## Implementations Currently the following URL shorteners are implemented: With authentication: - `goo.gl` - `bit.ly` - `kutt.it` (supports self hosting) Without authentication: - `bn.gy` - `is.gd` - `v.gd` - `bam.bz` - `fifo.cc` - `tiny.ph` - `tny.im` - `s.coop` - `bmeo.org` - `hmm.rs` - `url-shortener.io` The following services are supported, but are discouraged from use, due to restrictions such as rate limits: - `tinyurl.com` - `psbe.co` - `rlu.ru` - `sirbz.com` - `hec.su` - `abv8.me` - `nowlinks.net` ## Usage **without** "client" feature You can make a `Request` object without "client" feature only via provider functions: ```rust extern crate urlshortener; use urlshortener::providers::{Provider, self}; fn main() { let long_url = "https://google.com"; let key = "MY_API_KEY"; let req = providers::request(long_url, &Provider::GooGl { api_key: key.to_owned() }); println!("A request object for shortening URL via GooGl: {:?}", req); } ``` ## Usage with "client" feature Without authentication ```rust extern crate urlshortener; use urlshortener::client::UrlShortener; fn main() { let us = UrlShortener::new().unwrap(); let long_url = "https://google.com"; println!("Short url for google: {:?}", us.try_generate(long_url, None)); } ``` With authentication (**Goo.Gl**) ```rust extern crate urlshortener; use urlshortener::{ client::UrlShortener, providers::Provider }; fn main() { let us = UrlShortener::new().unwrap(); let long_url = "https://google.com"; let key = "MY_API_KEY"; println!("Short url for google: {:?}", us.generate(long_url, Provider::GooGl { api_key: key.to_owned() })); } ``` Combined (**Goo.Gl** + **Is.Gd**) ```rust extern crate urlshortener; use urlshortener::{ client::UrlShortener, providers::Provider }; fn main() { 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"; println!("Short url for google: {:?}", us.try_generate(long_url, Some(providers))); } ``` ## License This project is [licensed under the MIT license](https://github.com/vityafx/urlshortener-rs/blob/master/LICENSE). urlshortener-3.0.2/examples/via_all_providers.rs000064400000000000000000000006441046102023000202560ustar 00000000000000//! Generate a short URL by attempting all providers one by one, until a short //! URL has been successfully generated. extern crate urlshortener; use urlshortener::client::UrlShortener; fn main() { let long_url = "https://doc.rust-lang.org/std/"; let us = UrlShortener::new().unwrap(); let short_url = us.generate(long_url, &urlshortener::providers::Provider::IsGd); println!("{:?}", short_url); } urlshortener-3.0.2/examples/via_auth_provider.rs000064400000000000000000000007351046102023000202650ustar 00000000000000//! Generate a short URL by specifying which provider to use. extern crate urlshortener; use urlshortener::client::UrlShortener; use urlshortener::providers::Provider; fn main() { let long_url = "https://doc.rust-lang.org/std/"; let us = UrlShortener::new().unwrap(); let key = "MY_API_KEY"; let short_url = us.generate( long_url, &Provider::GooGl { api_key: key.to_owned(), }, ); println!("{:?}", short_url); } urlshortener-3.0.2/examples/via_kutt_custom_host_provider.rs000064400000000000000000000010431046102023000227330ustar 00000000000000//! Generate a short URL by specifying which provider to use. extern crate urlshortener; use urlshortener::client::UrlShortener; use urlshortener::providers::Provider; fn main() { let long_url = "https://doc.rust-lang.org/std/"; let us = UrlShortener::new().unwrap(); let key = "MY_API_KEY"; let host = "https://example.com"; let short_url = us.generate( long_url, &Provider::Kutt { api_key: key.into(), host: Some(host.into()), }, ); println!("{:?}", short_url); } urlshortener-3.0.2/examples/via_single_provider.rs000064400000000000000000000005501046102023000206000ustar 00000000000000//! Generate a short URL by specifying which provider to use. extern crate urlshortener; use urlshortener::{client::UrlShortener, providers::Provider}; fn main() { let long_url = "https://doc.rust-lang.org/std/"; let us = UrlShortener::new().unwrap(); let short_url = us.generate(long_url, &Provider::IsGd); println!("{:?}", short_url); } urlshortener-3.0.2/src/client.rs000064400000000000000000000117051046102023000150010ustar 00000000000000use crate::providers::{self, parse, request, ProviderError}; use reqwest::blocking::{Client, ClientBuilder}; use std::time::Duration; /// Url shortener: the way to retrieve a short url. #[derive(Debug)] pub struct UrlShortener { client: Client, } impl UrlShortener { /// Creates new `UrlShortener` with default (3 seconds) timeout. pub fn new() -> Result { UrlShortener::with_timeout(3) } /// Creates new `UrlShortener` with custom read timeout. pub fn with_timeout(seconds: u64) -> Result { let client = ClientBuilder::new() .timeout(Duration::from_secs(seconds)) .build()?; Ok(UrlShortener { client }) } /// 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 /// /// ```rust,no_run /// use urlshortener::client::UrlShortener; /// /// let us = UrlShortener::new().unwrap(); /// let long_url = "https://rust-lang.org"; /// let _short_url = us.try_generate(long_url, None); /// ``` /// /// ```rust,no_run /// use urlshortener::{client::UrlShortener, providers::Provider}; /// /// let us = UrlShortener::new().unwrap(); /// let providers = [ /// 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` if there is an error generating a /// short URL from all providers. /// /// # Notes /// /// This function has been deprecated since it does not bring any UX improvements. /// The body could be easily re-written as: /// /// ```rust,no_run /// use urlshortener::{client::UrlShortener, providers::Provider}; /// /// let us = UrlShortener::new().unwrap(); /// let providers = [ /// Provider::GooGl { api_key: "MY_API_KEY".to_owned() }, /// Provider::IsGd, /// ]; /// let long_url = "https://rust-lang.org"; /// let mut short_url = None; /// for provider in &providers { /// if let Ok(short_url_res) = us.generate(long_url, provider) { /// short_url = Some(short_url_res); /// break; /// } /// } /// /// ``` #[deprecated(since = "1.0.0", note = "Please use `generate` directly instead.")] pub fn try_generate( &self, url: &str, use_providers: Option<&[providers::Provider]>, ) -> Result { let providers = use_providers.unwrap_or(providers::PROVIDERS); for provider in providers { let res = self.generate(url, provider); if res.is_ok() { return res; } } Err(ProviderError::Connection) } /// Attempts to get a short URL using the specified provider. /// /// # Examples /// /// ```rust, no_run /// use urlshortener::{providers::Provider, client::UrlShortener}; /// /// let us = UrlShortener::new().unwrap(); /// let long_url = "http://rust-lang.org"; /// let _short_url = us.generate(long_url, &Provider::IsGd); /// ``` /// /// ```rust,no_run /// use urlshortener::{providers::Provider, client::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 }); /// ``` pub fn generate>( &self, url: S, provider: &providers::Provider, ) -> Result { let req = request(url.as_ref(), provider); if let Ok(response) = req.execute(&self.client) { response .text() .map_err(|_| ProviderError::Connection) .and_then(|t| parse(&t, provider)) } else { Err(ProviderError::Connection) } } } #[cfg(test)] mod tests { use crate::client; use crate::providers; /// This test does not cover services which require authentication for obvious reasons. #[test] fn providers() { let us = client::UrlShortener::with_timeout(5).unwrap(); let url = "http://yandex.com"; let mut valid = 0; for provider in providers::PROVIDERS { if let Err(e) = us.generate(url, provider) { println!("{:?} -> {:?}", provider, e); } else { valid += 1; println!("{:?} -> OK", provider); } } assert!(valid > 0, "There are no valid providers to use."); } } urlshortener-3.0.2/src/lib.rs000064400000000000000000000027671046102023000143010ustar 00000000000000//! # 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)] /// A urlshortener http client for performing requests. #[cfg(feature = "client")] pub mod client; pub mod providers; /// A request builders for sending via http client. pub mod request; /// A prelude module with main useful stuff. pub mod prelude { #[cfg(feature = "client")] pub use crate::client::*; pub use crate::providers::{Provider, PROVIDERS}; } urlshortener-3.0.2/src/providers.rs000064400000000000000000000361741046102023000155470ustar 00000000000000//! Library service providers implementation. use crate::request as req; use reqwest::header::HeaderMap; use url::form_urlencoded; /// A user agent for faking weird services. const FAKE_USER_AGENT: &str = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:58.0) Gecko/20100101 Firefox/58.0"; /// Describes the provider error. #[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)] pub enum ProviderError { /// Means there was a connection error. Usually when making a request. Connection, /// Means we were not able to deserialize the answer. Deserialize, } /// A slice of all `Provider` variants which do not require authentication. /// This list is in order of provider quality. /// /// The providers which are discouraged from use - due to problems such as rate /// limitations - are at the end of the resultant slice. /// /// Note that some providers may not provide a generated short URL because the /// submitted URL may already be short enough and would not benefit from /// shortening via their service. pub const PROVIDERS: &[Provider] = &[ Provider::IsGd, Provider::VGd, Provider::BamBz, Provider::TinyPh, Provider::FifoCc, Provider::SCoop, Provider::Bmeo, Provider::UrlShortenerIo, Provider::HmmRs, // The following list are items that have long response sometimes: Provider::TnyIm, // The following list are items that are discouraged from use: // Reasons: // // * rate limit (250 requests per 15 minutes) // * does not accept short urls (ex: ) Provider::SirBz, // Reason: rate limit (100 requests per hour) Provider::Rlu, // Reason: rate limit (3000 requests per day) Provider::HecSu, // Reason: rate limit (20r/3min; 60r/15min for a UNIQUE urls only) Provider::Abv8, // Reason: does not provide an api Provider::TinyUrl, // Reason: unstable work Provider::PsbeCo, // The following list are items that show previews instead of direct // links. Provider::NowLinks, ]; macro_rules! parse_xml_tag { ($fname:ident, $tag:expr) => { fn $fname(res: &str) -> Option { res.split(&format!("<{}>", $tag)) .nth(1) .unwrap_or("") .split(&format!("", $tag)) .next() .map(String::from) } }; } macro_rules! parse_json_tag { ($fname:ident, $tag:expr, $prefix:expr) => { fn $fname(res: &str) -> Option { res.to_owned() .split(&format!("\"{}\"", $tag)) .nth(1) .unwrap_or("") .split(",") .next() .unwrap_or("") .split("\"") .nth(1) .map(|v| format!("{}{}", $prefix, v.replace("\\", ""))) } }; } macro_rules! parse_noop { ($name:ident) => { fn $name(res: &str) -> Option { Some(res.to_owned()) } }; } macro_rules! request { ($name:ident, $method:expr, $req_url:expr) => { fn $name(url: &str) -> req::Request { let url = form_urlencoded::byte_serialize(url.as_bytes()).collect::(); req::Request { url: format!($req_url, url), body: None, content_type: None, user_agent: None, headers: None, method: $method, } } }; (B, $name:ident, $method:expr, $req_url:expr, $body:expr) => { fn $name(url: &str) -> req::Request { req::Request { url: $req_url.to_owned(), body: Some(format!($body, url)), content_type: None, user_agent: None, headers: None, method: $method, } } }; ($name:ident, $method:expr, $req_url:expr, $body:expr, $content_type:expr) => { fn $name(url: &str) -> req::Request { req::Request { url: $req_url.to_owned(), body: Some(format!($body, url)), content_type: Some($content_type), user_agent: None, headers: None, method: $method, } } }; } /// Used to specify which provider to use to generate a short URL. #[derive(Clone, Debug)] pub enum Provider { /// provider /// /// Notes: /// /// * You may not shorten more than 20 unique URLs within a 3-minute period. /// * You may not shorten more than 60 unique URLs within a 15-minute /// period. Abv8, /// provider BamBz, /// provider BitLy { /// A token string which you may obtain on the provider web service page. token: String, }, /// provider Bmeo, /// provider FifoCc, /// provider of Google GooGl { /// An api key string which you may obtain on the provider web service page. api_key: String, }, /// provider, can be self hosted Kutt { /// An api key string which you may obtain on the provider web service page. api_key: String, /// The api host, defaults to '' host: Option, }, /// provider /// /// Notes: /// /// * Limited to 3000 API requests per day HecSu, /// provider HmmRs, /// provider IsGd, /// provider NowLinks, /// provider /// /// Notes: /// /// * After some time the service will display ads /// * Instead of redirecting, a preview page will be displayed /// * Currently unstable PhxCoIn, /// provider PsbeCo, /// provider SCoop, /// provider /// /// Notes: /// /// * If you send a lot of requests from one IP, it can be /// blocked. If you plan to add more then 100 URLs in one hour, please let /// the technical support know. Otherwise your IP can be blocked /// unexpectedly. Prior added URLs can be deleted. Rlu, /// provider /// /// Notes: /// /// * By default, you are limited to 250 requests per 15 minutes. SirBz, /// provider /// /// Notes: /// /// * This service does not provide any API. /// * The implementation result depends on the service result web page. TinyUrl, /// provider TinyPh, /// provider TnyIm, /// provider UrlShortenerIo, /// provider VGd, } impl Provider { /// Converts the Provider variant into its domain name equivilant pub fn to_name(&self) -> &str { match *self { Provider::Abv8 => "abv8.me", Provider::BamBz => "bam.bz", Provider::BitLy { .. } => "bitly.com", Provider::Bmeo => "bmeo.org", Provider::FifoCc => "fifo.cc", Provider::GooGl { .. } => "goo.gl", Provider::HmmRs => "hmm.rs", Provider::HecSu => "hec.su", Provider::IsGd => "is.gd", Provider::Kutt { ref host, .. } => host .as_ref() .map(|h| h.rsplit("//").next().unwrap()) .unwrap_or("kutt.it"), Provider::NowLinks => "nowlinks.net", Provider::PhxCoIn => "phx.co.in", Provider::PsbeCo => "psbe.co", Provider::SCoop => "s.coop", Provider::SirBz => "sirbz.com", Provider::Rlu => "rlu.ru", Provider::TinyUrl => "tinyurl.com", Provider::TinyPh => "tiny.ph", Provider::TnyIm => "tny.im", Provider::UrlShortenerIo => "url-shortener.io", Provider::VGd => "v.gd", } } } parse_noop!(abv8_parse); request!(abv8_req, req::Method::Get, "http://abv8.me/?url={}"); parse_json_tag!(bambz_parse, "url", ""); request!( bambz_req, req::Method::Post, "https://bam.bz/api/short", "target={}", req::ContentType::FormUrlEncoded ); parse_noop!(bitly_parse); fn bitly_req(url: &str, key: &str) -> req::Request { let encoded_url = form_urlencoded::byte_serialize(url.as_bytes()).collect::(); let address = format!( "https://api-ssl.bitly.com/v3/shorten?access_token={}&longUrl={}&format=txt", key, encoded_url ); req::Request { url: address, body: None, content_type: None, user_agent: None, headers: None, method: req::Method::Get, } } parse_json_tag!(bmeo_parse, "short", ""); request!(bmeo_req, req::Method::Get, "http://bmeo.org/api.php?url={}"); parse_json_tag!(fifocc_parse, "shortner", "http://fifo.cc/"); request!( fifocc_req, req::Method::Get, "https://fifo.cc/api/v2?url={}" ); parse_json_tag!(googl_parse, "id", ""); fn googl_req(url: &str, key: &str) -> req::Request { req::Request { url: format!("https://www.googleapis.com/urlshortener/v1/url?key={}", key), body: Some(format!(r#"{{"longUrl": "{}"}}"#, url)), content_type: Some(req::ContentType::Json), user_agent: None, headers: None, method: req::Method::Post, } } parse_json_tag!(hmmrs_parse, "shortUrl", ""); fn hmmrs_req(url: &str) -> req::Request { req::Request { url: "http:/hmm.rs/x/shorten".to_owned(), body: Some(format!(r#"{{"url": "{}"}}"#, url)), content_type: Some(req::ContentType::Json), user_agent: Some(req::UserAgent(FAKE_USER_AGENT.to_owned())), headers: None, method: req::Method::Post, } } parse_xml_tag!(hecsu_parse, "short"); request!( hecsu_req, req::Method::Get, "https://hec.su/api?url={}&method=xml" ); parse_noop!(isgd_parse); request!( isgd_req, req::Method::Get, "https://is.gd/create.php?format=simple&url={}" ); parse_json_tag!(kutt_parse, "shortUrl", ""); fn kutt_req(url: &str, api_key: &str, host: Option<&str>) -> req::Request { let mut headers = HeaderMap::new(); headers.insert("X-API-Key", api_key.parse().unwrap()); req::Request { url: format!("{}/api/url/submit", host.unwrap_or("https://kutt.it")), body: Some(format!(r#"{{"target": "{}"}}"#, url)), content_type: Some(req::ContentType::Json), user_agent: None, headers: Some(headers), method: req::Method::Post, } } parse_noop!(nowlinks_parse); request!( nowlinks_req, req::Method::Get, "http://nowlinks.net/api?url={}" ); parse_noop!(phxcoin_parse); request!( phxcoin_req, req::Method::Get, "http://phx.co.in/shrink.asp?url={}" ); parse_xml_tag!(psbeco_parse, "ShortUrl"); request!( psbeco_req, req::Method::Get, "http://psbe.co/API.asmx/CreateUrl?real_url={}" ); parse_noop!(scoop_parse); request!( scoop_req, req::Method::Get, "http://s.coop/devapi.php?action=shorturl&url={}&format=RETURN" ); parse_noop!(rlu_parse); request!( rlu_req, req::Method::Get, "http://rlu.ru/index.sema?a=api&link={}" ); parse_json_tag!(sirbz_parse, "short_link", ""); request!( sirbz_req, req::Method::Post, "http://sirbz.com/api/shorten_url", "url={}", req::ContentType::FormUrlEncoded ); fn tinyurl_parse(res: &str) -> Option { res.split("data-clipboard-text=\"") .nth(1) .unwrap_or("") .split("\">") .next() .map(String::from) } request!( tinyurl_req, req::Method::Get, "http://tinyurl.com/create.php?url={}" ); parse_json_tag!(tinyph_parse, "hash", "http://tiny.ph/"); request!( tinyph_req, req::Method::Post, "http://tiny.ph/api/url/create", "url={}", req::ContentType::FormUrlEncoded ); parse_xml_tag!(tnyim_parse, "shorturl"); request!( tnyim_req, req::Method::Get, "http://tny.im/yourls-api.php?action=shorturl&url={}" ); parse_noop!(urlshortenerio_parse); request!( urlshortenerio_req, req::Method::Post, "http://url-shortener.io/shorten", "url_param={}", req::ContentType::FormUrlEncoded ); parse_noop!(vgd_parse); request!( vgd_req, req::Method::Get, "http://v.gd/create.php?format=simple&url={}" ); /// Parses the response from a successful request to a provider into the /// URL-shortened string. pub fn parse(res: &str, provider: &Provider) -> Result { match *provider { Provider::Abv8 => abv8_parse(res), Provider::BamBz => bambz_parse(res), Provider::BitLy { .. } => bitly_parse(res), Provider::Bmeo => bmeo_parse(res), Provider::FifoCc => fifocc_parse(res), Provider::GooGl { .. } => googl_parse(res), Provider::HmmRs => hmmrs_parse(res), Provider::HecSu => hecsu_parse(res), Provider::IsGd => isgd_parse(res), Provider::Kutt { .. } => kutt_parse(res), Provider::NowLinks => nowlinks_parse(res), Provider::PhxCoIn => phxcoin_parse(res), Provider::PsbeCo => psbeco_parse(res), Provider::SCoop => scoop_parse(res), Provider::SirBz => sirbz_parse(res), Provider::Rlu => rlu_parse(res), Provider::TinyUrl => tinyurl_parse(res), Provider::TinyPh => tinyph_parse(res), Provider::TnyIm => tnyim_parse(res), Provider::UrlShortenerIo => urlshortenerio_parse(res), Provider::VGd => vgd_parse(res), } .ok_or(ProviderError::Deserialize) } /// Performs a request to the short link provider. /// Returns the request object which can be used for performing requests. /// /// # Example /// /// ```rust,no_run /// extern crate urlshortener; /// /// use urlshortener::providers::{Provider, self}; /// /// fn main() { /// let long_url = "https://google.com"; /// let key = "MY_API_KEY"; /// let req = providers::request(long_url, &Provider::GooGl { api_key: key.to_owned() }); /// println!("A request object for shortening URL via GooGl: {:?}", req); /// } /// ``` pub fn request(url: &str, provider: &Provider) -> req::Request { match *provider { Provider::Abv8 => abv8_req(url), Provider::BamBz => bambz_req(url), Provider::BitLy { ref token } => bitly_req(url, token), Provider::Bmeo => bmeo_req(url), Provider::FifoCc => fifocc_req(url), Provider::GooGl { ref api_key } => googl_req(url, api_key), Provider::HmmRs => hmmrs_req(url), Provider::HecSu => hecsu_req(url), Provider::IsGd => isgd_req(url), Provider::Kutt { ref api_key, ref host, } => kutt_req(url, api_key, host.as_ref().map(|h| &**h)), Provider::NowLinks => nowlinks_req(url), Provider::PhxCoIn => phxcoin_req(url), Provider::PsbeCo => psbeco_req(url), Provider::SCoop => scoop_req(url), Provider::SirBz => sirbz_req(url), Provider::Rlu => rlu_req(url), Provider::TinyUrl => tinyurl_req(url), Provider::TinyPh => tinyph_req(url), Provider::TnyIm => tnyim_req(url), Provider::UrlShortenerIo => urlshortenerio_req(url), Provider::VGd => vgd_req(url), } } urlshortener-3.0.2/src/request.rs000064400000000000000000000043331046102023000152120ustar 00000000000000#[cfg(feature = "client")] use reqwest::{ blocking::{Client, Response}, header::{self, HeaderMap}, }; const CONTENT_JSON: &str = "application/json"; const CONTENT_FORM_URL_ENCODED: &str = "application/x-www-form-urlencoded"; /// An HTTP method abstraction #[derive(Debug, Copy, Clone)] pub enum Method { /// `Get` HTTP method should be used. Get, /// `POST` HTTP method should be used. Post, } /// An HTTP content type abstraction #[derive(Debug, Copy, Clone)] pub enum ContentType { /// The url encoded form data header should be used. FormUrlEncoded, /// The json header should be used. Json, } /// An HTTP user agent abstraction #[derive(Debug, Clone)] pub struct UserAgent(pub String); /// An abstraction for basic http request. #[derive(Debug, Clone)] pub struct Request { /// The URL the request must be sent to. pub url: String, /// The request body. pub body: Option, /// The content type. pub content_type: Option, /// The user agent. pub user_agent: Option, /// Request headers. pub headers: Option, /// The HTTP method. pub method: Method, } #[cfg(feature = "client")] impl Request { /// Sends the request and returns the response. pub fn execute(&self, client: &Client) -> Result { let mut builder = match self.method { Method::Get => client.get(&self.url), Method::Post => client.post(&self.url), }; if let Some(agent) = self.user_agent.clone() { builder = builder.header(header::USER_AGENT, agent.0); } if let Some(headers) = self.headers.clone() { builder = builder.headers(headers); } if let Some(content_type) = self.content_type { builder = match content_type { ContentType::Json => builder.header(header::CONTENT_TYPE, CONTENT_JSON), ContentType::FormUrlEncoded => { builder.header(header::CONTENT_TYPE, CONTENT_FORM_URL_ENCODED) } }; } if let Some(body) = self.body.clone() { builder = builder.body(body); } builder.send() } }