pub struct MALClient {
pub need_auth: bool,
/* private fields */
}
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: bool
Implementations§
Source§impl MALClient
impl MALClient
pub fn new( client_secret: String, dirs: PathBuf, access_token: String, client: Client, caching: bool, need_auth: bool, ) -> Self
Sourcepub fn with_access_token(token: &str) -> Self
pub fn with_access_token(token: &str) -> 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
Sourcepub fn set_cache_dir(&mut self, dir: PathBuf)
pub fn set_cache_dir(&mut self, dir: PathBuf)
Sets the directory the client will use for the token cache
Sourcepub fn set_caching(&mut self, caching: bool)
pub fn set_caching(&mut self, caching: bool)
Sets wether the client will cache or not
Sourcepub fn get_auth_parts(&self) -> (String, String, String)
pub fn get_auth_parts(&self) -> (String, String, String)
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?;
Sourcepub async fn auth(
&mut self,
callback_url: &str,
challenge: &str,
state: &str,
) -> Result<(), MALError>
pub async fn auth( &mut self, callback_url: &str, challenge: &str, state: &str, ) -> Result<(), MALError>
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.
§NOTE
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?;
Sourcepub fn get_access_token(&self) -> &str
pub fn get_access_token(&self) -> &str
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(())
Sourcepub async fn get_anime_list(
&self,
query: &str,
limit: impl Into<Option<u8>>,
) -> Result<AnimeList, MALError>
pub async fn get_anime_list( &self, query: &str, limit: impl Into<Option<u8>>, ) -> Result<AnimeList, MALError>
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?;
Sourcepub 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?;
Sourcepub 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?;
Sourcepub async fn get_seasonal_anime(
&self,
season: Season,
year: u32,
limit: impl Into<Option<u8>>,
) -> Result<AnimeList, MALError>
pub async fn get_seasonal_anime( &self, season: Season, year: u32, limit: impl Into<Option<u8>>, ) -> Result<AnimeList, MALError>
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?;
Sourcepub async fn get_suggested_anime(
&self,
limit: impl Into<Option<u8>>,
) -> Result<AnimeList, MALError>
pub async fn get_suggested_anime( &self, limit: impl Into<Option<u8>>, ) -> Result<AnimeList, MALError>
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?;
Sourcepub 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?;
Sourcepub async fn get_user_anime_list(&self) -> Result<AnimeList, MALError>
pub async fn get_user_anime_list(&self) -> Result<AnimeList, MALError>
Returns the user’s full anime list as an AnimeList
struct.
§Example
let my_list = client.get_user_anime_list().await?;
Sourcepub async fn delete_anime_list_item(&self, id: u32) -> Result<(), MALError>
pub async fn delete_anime_list_item(&self, id: u32) -> Result<(), MALError>
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?;
Sourcepub async fn get_forum_boards(&self) -> Result<ForumBoards, MALError>
pub async fn get_forum_boards(&self) -> Result<ForumBoards, MALError>
Returns a vector of HashMap
s that represent all the forum boards on MAL
Sourcepub 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
Sourcepub async fn get_forum_topics(
&self,
board_id: impl Into<Option<u32>>,
subboard_id: impl Into<Option<u32>>,
query: impl Into<Option<String>>,
topic_user_name: impl Into<Option<String>>,
user_name: impl Into<Option<String>>,
limit: impl Into<Option<u32>>,
) -> Result<ForumTopics, MALError>
pub async fn get_forum_topics( &self, board_id: impl Into<Option<u32>>, subboard_id: impl Into<Option<u32>>, query: impl Into<Option<String>>, topic_user_name: impl Into<Option<String>>, user_name: impl Into<Option<String>>, limit: impl Into<Option<u32>>, ) -> Result<ForumTopics, MALError>
Returns all topics for a given query