7 个版本
0.1.13 | 2024 年 4 月 28 日 |
---|---|
0.1.12 | 2024 年 4 月 27 日 |
#498 in 网页编程
129 每月下载量
89KB
2K SLoC
动漫时间表 Api
使用 Rust 实现的完整动漫时间表 Api v3 客户端
要获取您的 API 密钥,请访问 https://animeschedule.net/users/<your_username>/settings/api
您可以在没有 animelist 范围的情况下制作应用程序,但这样做会导致 animelists api 失败,因为令牌没有权限。
有关其 API 的深入审查以及哪些端点需要 oauth2 的信息,请参阅 https://animeschedule.net/api/v3/documentation
在使用 oauth2 端点时,您必须为用户创建一个 oauth2 令牌。您可以使用包含的令牌 API 来这样做
let client = AnimeScheduleClientBuilder::new().client_id("your-id").client_secret("secret").access_token("your-token").redirect_url("your-url").build().unwrap();
// if you want to create your token with the full scope, add scope before generating a token
client.auth.add_scope(Scope::new("animelist"));
// 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()))
});
// When dealing with access/refresh tokens, please be aware
// that the site api sets both to 3600
// if you pass this threshold, you are required to regenerate the tokens
// 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(RefreshToke::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));
// use the api
client.anime().get().q("query").genres(&["action"]).send().await;
// if using an oauth protected endpoint, make sure you have set your token
// with correct oauth tokens and scope first!
client.animelists().get().await;
client.animelists().put().route("foo").etag("etag").episodes_seen(5).note("I love anime").send().await;
// for more information on the api, see their api docs:
// https://animeschedule.net/api/v3/documentation
//
// this api follows a builder pattern, and follows their api
// it should be relatively intuitive to use
警告:此 crate 在 1.0 版本之前可能会更改 API,因为 API 正在完善。
如果您看到任何错误,请报告它们。大多数这些可能是“null”出现在 API 中,但假设在反序列化类型中始终存在。虽然这已经使用一些数据快速测试,以希望获得完整的画面,但这并不保证总是正确的。除此之外,它应该功能完整且工作正常。
使用此 crate 受 api tos 的约束
依赖项
~10–23MB
~345K SLoC