6个版本 (稳定版)
2.0.2 | 2024年5月10日 |
---|---|
2.0.1 | 2024年5月9日 |
2.0.0 | 2024年3月4日 |
1.0.0 | 2024年1月2日 |
0.1.0 | 2023年7月21日 |
#344 in 异步
每月46次下载
185KB
4.5K SLoC
mal-api
为Rust提供的异步MyAnimeList (MAL) API库。
特性
- 类型安全的查询构建器
- 类型安全的响应
- 通过响应进行分页
- 支持访问所有MAL端点(动画、漫画、论坛和用户)
- 要访问论坛和用户端点,请启用
forum
和user
特性
- 要访问论坛和用户端点,请启用
- OAuth2访问令牌检索和管理
示例
use dotenvy;
use mal_api::anime_common_fields;
use mal_api::oauth::MalClientId;
use mal_api::prelude::*;
#[tokio::main]
async fn main() {
// See the .env.example for which
// environment variables you are expected to define
dotenvy::dotenv().ok();
let client_id = MalClientId::try_from_env().unwrap();
let api_client = AnimeApiClient::from(&client_id);
let fields = anime_common_fields!(
AnimeField::id,
AnimeField::num_episodes,
AnimeField::title,
);
// Example using the builder pattern.
// The `builder(args...)` method will only take
// the required arguments for the specific API endpoint, while the
// other builder instance methods will build up the optional arguments
let query = GetAnimeList::builder("One")
.fields(&fields)
.limit(5)
.build()
.unwrap();
let result = api_client.get_anime_list(&query).await.unwrap();
println!("Received response: {}", result);
for entry in result.data.iter() {
println!("Anime Title: {} Anime ID: {}", entry.node.title, entry.node.id);
}
// Example iterating through pages
let result = api_client.next(&result).await.unwrap();
println!("Next result: {}", &result);
let result = api_client.prev(&result).await.unwrap();
println!("Prev result: {}", &result);
// Manga API example
let api_client = MangaApiClient::from(&client_id);
let fields = mal_api::manga::all_common_fields();
// Example using `new` pattern. Not recommended, but available
let nsfw = false;
let limit = Some(5);
let query = GetMangaList::new("one", nsfw, Some(&fields), limit, None).unwrap();
let result = api_client.get_manga_list(&query).await.unwrap();
println!("Result: {}", result);
}
您可以在示例目录中查看更多使用示例。
注意
在MAL API规范中,并未对所有特定字段的变体进行文档记录。这是预期的,因为MAL v2 API仍在测试版中。如果由于意外变体而请求失败,请创建一个问题并描述您提交的查询,该查询揭示了新变体。
许可证
本项目遵循MIT许可证
依赖项
~6–21MB
~284K SLoC