Struct tosho_rbean::RBClient

source ·
pub struct RBClient { /* private fields */ }
Expand description

Main client for interacting with the 小豆 (Red Bean) API

§Examples

use tosho_rbean::{RBClient, RBConfig, RBPlatform};

#[tokio::main]
async fn main() {
    let config = RBConfig {
        token: "123".to_string(),
        refresh_token: "abcxyz".to_string(),
        platform: RBPlatform::Android,
    };

    let mut client = RBClient::new(config);
    // Refresh token
    client.refresh_token().await.unwrap();
    let user = client.get_user().await.unwrap();
    println!("{:?}", user);
}

Implementations§

source§

impl RBClient

source

pub fn new(config: RBConfig) -> Self

Create a new client instance.

§Arguments
  • config - The configuration to use for the client.
source

pub fn with_proxy(&self, proxy: Proxy) -> Self

Attach a proxy to the client.

This will clone the client and return a new client with the proxy attached.

§Arguments
  • proxy - The proxy to attach to the client
source

pub fn set_expiry_at(&mut self, expiry_at: Option<i64>)

source

pub async fn refresh_token(&mut self) -> Result<()>

Refresh the token of the client.

The following function will be called on each request to ensure the token is always valid.

The first request will always be a token refresh, and subsequent requests will only refresh if the token is expired.

source

pub fn get_token(&self) -> &str

Get the current token of the client.

source

pub fn get_expiry_at(&self) -> Option<i64>

Get the expiry time of the token.

source

pub async fn get_user(&mut self) -> Result<UserAccount>

Get the current user account information.

source

pub async fn get_reading_list(&mut self) -> Result<Vec<ReadingListItem>>

Get the current user reading list.

source

pub async fn get_manga(&mut self, uuid: &str) -> Result<Manga>

Get the manga information for a specific manga.

§Arguments
  • uuid - The UUID of the manga.
source

pub async fn get_manga_filters(&mut self) -> Result<Manga>

Get the manga filters for searching manga.

source

pub async fn get_chapter_list( &mut self, uuid: &str, ) -> Result<ChapterListResponse>

Get chapter list for a specific manga.

§Arguments
  • uuid - The UUID of the manga.
source

pub async fn get_chapter( &mut self, uuid: &str, ) -> Result<ChapterDetailsResponse>

Get the chapter details for a specific chapter.

§Arguments
  • uuid - The UUID of the chapter.
source

pub async fn get_chapter_viewer( &mut self, uuid: &str, ) -> Result<ChapterPageDetailsResponse>

Get the chapter viewer for a specific chapter.

§Arguments
  • uuid - The UUID of the chapter.
source

pub async fn search( &mut self, query: &str, offset: Option<u32>, count: Option<u32>, sort: Option<SortOption>, ) -> Result<MangaListResponse>

Do a search for a manga.

§Arguments
  • query - The query to search for.
  • offset - The offset of the search result, default to 0
  • count - The count of the search result, default to 999
  • sort - The sort option of the search result, default to SortOption::Alphabetical
source

pub async fn get_home_page(&mut self) -> Result<HomeResponse>

Get the home page information.

source

pub async fn get_publisher(&mut self, slug: &str) -> Result<Publisher>

Get specific publisher information by their slug.

§Arguments
  • slug - The slug of the publisher.
source

pub fn modify_url_for_highres(url: &str) -> Result<String>

Modify the URL to get the high resolution image URL.

§Arguments
  • url - The URL to modify.
source

pub async fn stream_download( &self, url: &str, writer: impl AsyncWrite + Unpin, ) -> Result<()>

Stream download the image from the given URL.

The URL can be obtained from RBClient::get_chapter_viewer.

§Parameters
  • url - The URL to download the image from.
  • writer - The writer to write the image to.
source

pub async fn test_high_res(&self, url: &str) -> Result<bool>

Try checking if the “hidden” high resolution image is available.

Give the URL of any image that is requested from the API.

source

pub async fn login( email: &str, password: &str, platform: RBPlatform, ) -> Result<RBLoginResponse>

Trait Implementations§

source§

impl Clone for RBClient

source§

fn clone(&self) -> RBClient

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for RBClient

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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