#wrapper #async #sdk #graphql #api-wrapper #api-bindings #api-client

shikimori

An unofficial async Rust library that allows you to interact with the Shikimori API

8 releases

new 0.3.2 Apr 24, 2024
0.3.1 Apr 10, 2024
0.3.0 Mar 18, 2024
0.2.1 Jan 9, 2024
0.1.1 Sep 28, 2023

#1628 in Web programming

Download history 13/week @ 2024-01-03 3/week @ 2024-01-10 8/week @ 2024-02-28 1/week @ 2024-03-06 222/week @ 2024-03-13 30/week @ 2024-03-20 5/week @ 2024-03-27 6/week @ 2024-04-03 131/week @ 2024-04-10

200 downloads per month

MIT license

59KB
1.5K SLoC

Rust 1K SLoC // 0.0% comments GraphQL 496 SLoC // 0.3% comments

Shikimori Rust

Crate version Tests License

Shikimori Rust - An efficient Rust library serving as a wrapper for the Shikimori API 🦾

📖 Documentation

Installation

Install shikimori from crates.io. Add the following line to your Cargo.toml file's dependencies section:

shikimori = "0.3"

Or you can add with cargo

cargo add shikimori

Usage

You should also use querygen to simplify your life, it is available at the link. Get the schema at URL https://shikimori.one/api/graphql

use chrono::{DateTime, Utc};

use shikimori::client::ClientBuilder;
use shikimori::cynic::QueryBuilder;

use shikimori::graphql::anime::AnimeKind;
use shikimori::graphql::types::EntityOrder;
use shikimori::graphql::scalars::StatusString;
use shikimori::graphql::schema;

#[derive(cynic::QueryVariables, Debug)]
pub struct AnimesQueryVariables {
    pub page: i32,
    pub status: StatusString,
    pub order: EntityOrder,
}

#[derive(cynic::QueryFragment, Debug)]
#[cynic(graphql_type = "Query", variables = "AnimesQueryVariables")]
pub struct AnimesQuery {
    #[arguments(censored: false, page: $page, status: $status, order: $order)]
    pub animes: Vec<Anime>,
}

#[derive(cynic::QueryFragment, Debug)]
pub struct Anime {
    pub id: cynic::Id,
    pub franchise: Option<String>,
    pub episodes: i32,
    pub kind: Option<AnimeKind>,
    pub next_episode_at: Option<DateTime<Utc>>,
    pub url: String,
}

#[tokio::main]
async fn main() {
    let client = ClientBuilder::new().build();

    let response = client
        .query(AnimesQuery::build(AnimesQueryVariables {
            page: 1,
            status: StatusString::new("ongoing"),
            order: EntityOrder::Popularity,
        }))
        .await;

    dbg!(&response);
}

// Ok(
//     GraphQlResponse {
//         data: Some(
//             AnimesQuery {
//                 animes: [
//                     Anime {
//                         id: Id(
//                             "21",
//                         ),
//                         franchise: Some(
//                             "one_piece",
//                         ),
//                         episodes: 0,
//                         kind: Some(
//                             Tv,
//                         ),
//                         next_episode_at: Some(
//                             2023-09-10T00:30:00Z,
//                         ),
//                         url: "https://shikimori.one/animes/21-one-piece",
//                     },
//                     Anime {
//                         id: Id(
//                             "51009",
//                         ),
//                         franchise: Some(
//                             "jujutsu_kaisen",
//                         ),
//                         episodes: 23,
//                         kind: Some(
//                             Tv,
//                         ),
//                         next_episode_at: Some(
//                             2023-09-07T14:56:00Z,
//                         ),
//                         url: "https://shikimori.one/animes/51009-jujutsu-kaisen-2nd-season",
//                     },
//                 ],
//             },
//         ),
//         errors: None,
//     },
// )

Dependencies

~13–26MB
~366K SLoC