Coder Social home page Coder Social logo

kitsu.rs's Introduction

kitsu.rs

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

note: The library supports retrieval from the API, but does not currently support authenticated requests.

Compile features

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

Installation

Add the following to your Cargo.toml file:

[dependencies]
kitsu = "0.2"

To enable both hyper and reqwest support:

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

To enable hyper but not reqwest support:

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

Examples

Using reqwest, search for an anime using a string taken from user input:

extern crate kitsu;
extern crate reqwest;

use kitsu::KitsuReqwestRequester;
use reqwest::Client;
use std::io::{self, Write};

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

    // Read an anime name to search for from the users input.
    let mut input = String::new();
    print!("Enter an anime name to search for:\n>");
    let _ = io::stdout().flush();
    io::stdin().read_line(&mut input).expect("Error reading input");
    let input_trimmed = input.trim();

    // Search for the anime.
    let anime = client.search_anime(|f| f.filter("text", input_trimmed))
        .expect("Error searching for anime");

    // Print out the response of the request.
    if let Some(ref picked) = anime.data.first() {
        let title = &picked.attributes.canonical_title;

        if let Some(ref rating) = picked.attributes.average_rating {
            println!("Found Anime: {} - {}", title, rating);
        } else {
            println!("Found Anime: {} - ??", title);
        }
    } else {
        println!("No Anime Found.");
    }
}

For more examples, refer to the examples folder.

License

ISC. View the full license here.

kitsu.rs's People

Contributors

hsiw avatar pepijn98 avatar rushsteve1 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.