use crate::client::InkittRequestBuilder;
use crate::types::{ChaptersResponse, StoryResponse};
use crate::InkittError;
use std::sync::atomic::AtomicBool;
use std::sync::{Arc, RwLock};
use crate::types::StoryResult;
pub struct StoryClient {
pub(crate) http: reqwest::Client,
pub(crate) is_authenticated: Arc<AtomicBool>,
pub(crate) auth_token: Arc<RwLock<Option<String>>>,
}
impl StoryClient {
pub async fn get_story_info(&self, story_id: u64) -> Result<StoryResponse, InkittError> {
let wrapper: StoryResult = InkittRequestBuilder::new(
&self.http,
&self.is_authenticated,
&self.auth_token,
reqwest::Method::GET,
&format!("/2/stories/{}", story_id),
)
.execute()
.await?;
Ok(wrapper.response)
}
pub async fn get_all_chapter_info(
&self,
story_id: u64,
include_text: bool,
) -> Result<ChaptersResponse, InkittError> {
let mut builder = InkittRequestBuilder::new(
&self.http,
&self.is_authenticated,
&self.auth_token,
reqwest::Method::GET,
&format!("/2/stories/{}/chapters", story_id),
);
if include_text {
builder = builder
.param("include_text", Some(true))
.requires_auth();
}
builder.execute().await
}
}