Struct lib_mal::MALClient [−][src]
pub struct MALClient {
pub need_auth: bool,
// some fields omitted
}Expand description
Exposes all of the API functions for the MyAnimeList API
With the exception of all the manga-related functions which haven’t been implemented yet
Example
use lib_mal::ClientBuilder;
let client = ClientBuilder::new().secret("[YOUR_SECRET_HERE]".to_string()).build_no_refresh();
//--do authorization stuff before accessing the functions--//
//Gets the details with all fields for Mobile Suit Gundam
let anime = client.get_anime_details(80, None).await?;
//You should actually handle the potential error
println!("Title: {} | Started airing: {} | Finished airing: {}",
anime.show.title,
anime.start_date.unwrap(),
anime.end_date.unwrap());Fields
need_auth: boolImplementations
pub fn new(
client_secret: String,
dirs: PathBuf,
access_token: String,
client: Client,
caching: bool,
need_auth: bool
) -> Self
Creates a client using provided token. Caching is disable by default.
A client created this way can’t authenticate the user if needed because it lacks a
client_secret
Sets the directory the client will use for the token cache
Sets wether the client will cache or not
Returns the auth URL and code challenge which will be needed to authorize the user.
Example
use lib_mal::ClientBuilder;
let redirect_uri = "http://localhost:2525";//<-- example uri
let mut client =
ClientBuilder::new().secret("[YOUR_SECRET_HERE]".to_string()).build_no_refresh();
let (url, challenge, state) = client.get_auth_parts();
println!("Go here to log in: {}", url);
client.auth(&redirect_uri, &challenge, &state).await?;Listens for the OAuth2 callback from MAL on callback_url, which is the redirect_uri
registered when obtaining the API token from MAL. Only HTTP URIs are supported right now.
For now only applications with a single registered URI are supported, having more than one seems to cause issues with the MAL api itself
Example
use lib_mal::ClientBuilder;
let redirect_uri = "localhost:2525";//<-- example uri,
//appears as "http://localhost:2525" in the API settings
let mut client = ClientBuilder::new().secret("[YOUR_SECRET_HERE]".to_string()).build_no_refresh();
let (url, challenge, state) = client.get_auth_parts();
println!("Go here to log in: {}", url);
client.auth(&redirect_uri, &challenge, &state).await?;
Returns the current access token. Intended mostly for debugging.
Example
let client = ClientBuilder::new().secret("[YOUR_SECRET_HERE]".to_string()).caching(true).cache_dir(Some(PathBuf::new())).build_with_refresh().await?;
let token = client.get_access_token();
Ok(())Gets a list of anime based on the query string provided
limit defaults to 100 if None
Example
let list = client.get_anime_list("Mobile Suit Gundam", None).await?;pub async fn get_anime_details(
&self,
id: u32,
fields: impl Into<Option<AnimeFields>>
) -> Result<AnimeDetails, MALError>
pub async fn get_anime_details(
&self,
id: u32,
fields: impl Into<Option<AnimeFields>>
) -> Result<AnimeDetails, MALError>
Gets the details for an anime by the show’s ID.
Only returns the fields specified in the fields parameter
Returns all fields when supplied None
Example
use lib_mal::model::fields::AnimeFields;
//returns an AnimeDetails struct with just the Rank, Mean, and Studio data for Mobile Suit Gundam
let res = client.get_anime_details(80, AnimeFields::Rank | AnimeFields::Mean | AnimeFields::Studios).await?;
pub async fn get_anime_ranking(
&self,
ranking_type: RankingType,
limit: impl Into<Option<u8>>
) -> Result<AnimeList, MALError>
pub async fn get_anime_ranking(
&self,
ranking_type: RankingType,
limit: impl Into<Option<u8>>
) -> Result<AnimeList, MALError>
Gets a list of anime ranked by RankingType
limit defaults to the max of 100 when None
Example
use lib_mal::model::options::RankingType;
// Gets a list of the top 5 most popular anime
let ranking_list = client.get_anime_ranking(RankingType::ByPopularity, 5).await?;
Gets the anime for a given season in a given year
limit defaults to the max of 100 when None
Example
use lib_mal::model::options::Season;
let summer_2019 = client.get_seasonal_anime(Season::Summer, 2019, None).await?;Returns the suggested anime for the current user. Can return an empty list if the user has no suggestions.
Example
let suggestions = client.get_suggested_anime(10).await?;pub async fn update_user_anime_status(
&self,
id: u32,
update: StatusUpdate
) -> Result<ListStatus, MALError>
pub async fn update_user_anime_status(
&self,
id: u32,
update: StatusUpdate
) -> Result<ListStatus, MALError>
Adds an anime to the list, or updates the element if it already exists
Example
use lib_mal::model::StatusBuilder;
use lib_mal::model::options::Status;
// add a new anime to the user's list
let updated_status = client.update_user_anime_status(80, StatusBuilder::new().status(Status::Watching).build()).await?;
// or update an existing one
let new_status = StatusBuilder::new().status(Status::Dropped).num_watched_episodes(2).build();
let updated_status = client.update_user_anime_status(32981, new_status).await?;
Returns the user’s full anime list as an AnimeList struct.
Example
let my_list = client.get_user_anime_list().await?;
Deletes the anime with id from the user’s anime list
Note
The API docs from MAL say this method should return 404 if the anime isn’t in the user’s list, but in my testing this wasn’t true. Without that there’s no way to tell if the item was actually deleted or not.
Example
client.delete_anime_list_item(80).await?;Returns a vector of HashMaps that represent all the forum boards on MAL
pub async fn get_forum_topic_detail(
&self,
topic_id: u32,
limit: impl Into<Option<u8>>
) -> Result<TopicDetails, MALError>
pub async fn get_forum_topic_detail(
&self,
topic_id: u32,
limit: impl Into<Option<u8>>
) -> Result<TopicDetails, MALError>
Returns details of the specified topic
Returns all topics for a given query