8 个版本

0.1.14 2024 年 4 月 28 日
0.1.13 2024 年 4 月 27 日

#1 in #mal

Download history 975/week @ 2024-04-22 69/week @ 2024-04-29 5/week @ 2024-05-20

613 每月下载量

MIT 许可证

105KB
2.5K SLoC

MyAnimeList Rust Api

完全类型化的 Rust MyAnimeList API

目前该库已完全覆盖以下 API

  • 动漫
  • 漫画
  • 用户动漫列表
  • 用户漫画列表
  • 用户
  • 论坛

该 API 完全异步,但为需要同步的用户提供了阻塞 API(使用 *_blocking 函数变体)。

要获取 API 客户端 ID 和密钥 - 这是必需的 - 在 https://myanimelist.net/apiconfig 上注册应用

要了解此 API 和其工作方式,请仔细阅读 https://myanimelist.net/apiconfig/references/api/v2 上的 mal api 文档

mal API 中未指定速率限制,但在实际操作中,您不应超过每秒 1 次查询

let client = ClientBuilder::new().client_id("your-id").client_secret("secret").redirect_url("your-url").build().unwrap();

// if you want to create your token with a scope, add scope before generating a token
// mal should add this by default, so I don't think adding this manually is needed
client.auth.add_scope(Scope::new("write:users"));

// this requires a webserver to receive the oauth code+state for regenerate
// set your own custom callback for production usage
client.auth.set_callback(|url, state| async {
    // the url passed in is the one the client needs to navigate to

    // receive the state on your webserver, compare it to the received state above
    // to ensure it's valid and the right client. if you return wrong state, the
    // regenerate api will fail due to security check

    // get the code / state and return it
    (AuthorizationCode::new("".to_owned()), CsrfToken::new("".to_owned()))
});

// regenerate tokens from scratch
client.auth.regenerate().await;

// if you have a refresh key, you can exchange it for an access token
client.auth.refresh_token().await;

// you can automatically try to refresh it if access token expired
// if no refresh token exists, it will regenerate the whole thing
client.auth.try_refresh().await;

// you can also set the access/refresh token manually if you need to
client.auth.set_refresh_token_unchecked(RefreshToken::new("token"));
client.auth.set_access_token_unchecked(AccessToken::new("token"));
// set the time from Instant::now() after which access token expires
client.auth.set_expires_in_unchecked(Duration::from_secs(3600));
client.auth.set_refresh_expires_in_unchecked(Duration::from_secs(3600));

// use the api
client.anime().get().list().query("foo").send().await;

// for more information on the api, see their api docs:
// https://myanimelist.net/apiconfig/references/api/v2
//
// this api follows a builder pattern, and follows their api
// it should be relatively intuitive to use
//
// view mal docs to see if your token needs a scope or not,
// and for information on what the routes do

警告:此 crate 在 1.0 版本之前可能会更改 API,因为 API 正在完善。

如果您发现任何错误,请报告它们。这些错误可能是 API 中出现“null”的实例,但假设在反序列化类型中始终存在。虽然使用一些数据进行快速测试以获得完整图景,但这并不保证始终正确。除此之外,它应该功能齐全且运行正常。

依赖项

~9–22MB
~343K SLoC