MALClient

Struct MALClient 

Source
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

Source

pub fn new( client_secret: String, dirs: PathBuf, access_token: String, client: Client, caching: bool, need_auth: bool, ) -> Self

Source

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

Source

pub fn set_cache_dir(&mut self, dir: PathBuf)

Sets the directory the client will use for the token cache

Source

pub fn set_caching(&mut self, caching: bool)

Sets wether the client will cache or not

Source

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?;
Source

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?;
Source

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(())
Source

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?;
Source

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?;
Source

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?;
Source

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?;
Source

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?;
Source

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?;

Source

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?;
Source

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?;
Source

pub async fn get_forum_boards(&self) -> Result<ForumBoards, MALError>

Returns a vector of HashMaps that represent all the forum boards on MAL

Source

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

Source

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

Source

pub async fn get_my_user_info(&self) -> Result<User, MALError>

Gets the details for the current user

§Example
     let me = client.get_my_user_info().await?;

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,