weeb_api

Crates.ioweeb_api
lib.rsweeb_api
version0.2.0
sourcesrc
created_at2017-11-28 00:39:59.873183
updated_at2018-01-18 00:32:59.251631
descriptionA Rust library for the Weeb.sh API.
homepagehttps://github.com/shinonome-cafe/weeb-api.rs
repositoryhttps://github.com/shinonome-cafe/weeb-api.rs.git
max_upload_size
id40794
size53,361
Zeyla Hellyer (zeyla)

documentation

https://docs.rs/weeb_api

README

weeb-api.rs

An unofficial Rust library acting as a wrapper around the Weeb.sh API, offering implementations for both asynchronous hyper(v0.11) and synchronous reqwest(0.8.0).

note: Thie library requires the use of a Weeb.sh token.

Compile features

  • hyper-support: Compiles with hyper support
  • reqwest-support: Compiles with reqwest support (*default)

Installation

Add the following to your Cargo.toml file.

[dependencies]
weeb_api = "0.2"

To enable both hyper and reqwest support:

[dependencies.weeb_api]
version = "0.2"
features = ["hyper-support", "reqwest support"]

To enable hyper but not reqwest support:

[dependencies.weeb_api]
version = "0.2"
default-features = false
features = ["hyper-support"]

Examples

Using reqwest, search for a random image using the token and type provided by user input:

extern crate weeb_api;
extern crate reqwest;

use weeb_api::{ImageParams, WeebApiReqwestRequester};
use reqwest::Client;
use std::io::{self, Write};

fn main() {
    // Create the reqwest Client.
    let client = Client::new();

    // Read the token from the users input.
    let token = ask("Input your API token:");
    let token_trimmed = token.trim();

    if token_trimmed.is_empty() {
        println!("No token give. Shutting down.");

        return;
    }

    // Get a type to get a random image for from the users input.
    let input = ask("Input a type to get a random image URL for:");
    let input_trimmed = input.trim();

    if input_trimmed.is_empty() {
        println!("No type given. Shutting down.");

        return;
    }

    let params = ImageParams::kind(input_trimmed);
    let response = client.get_image_random(token_trimmed, params)
        .expect("Error getting random image");

    println!("Response URL: {}", response.url);
}

fn ask(question: &str) -> String {
    print!("{}\n>", question);
    let _ = io::stdout().flush();

    let mut input = String::new();
    io::stdin().read_line(&mut input).expect("Error processing input");

    input
}

For more examples, refer to the examples folder.

License

ISC. View the full license here.

Commit count: 0

cargo fmt