Skip to main content

flix_tmdb/api/
episodes.rs

1//! Episodes API
2
3use std::rc::Rc;
4use std::sync::RwLock;
5
6use flix_model::numbers::{EpisodeNumber, SeasonNumber};
7
8use crate::api::exec_request;
9use crate::model::Episode;
10use crate::model::id::ShowId;
11use crate::{Cache, CachePolicy, Config};
12
13use super::{Error, make_request};
14
15/// TMDB Episodes API client
16pub struct Client {
17	config: Rc<Config>,
18	cache: Rc<dyn Cache>,
19	policy: Rc<RwLock<CachePolicy>>,
20}
21
22impl Client {
23	/// Create a new client with the given configuration
24	pub fn new(config: Rc<Config>, cache: Rc<dyn Cache>, policy: Rc<RwLock<CachePolicy>>) -> Self {
25		Self {
26			config,
27			cache,
28			policy,
29		}
30	}
31}
32
33impl Client {
34	/// Fetch the details of the episode refered to by ID, season number and episode number
35	pub async fn get_details(
36		&self,
37		id: impl Into<ShowId>,
38		season: impl Into<SeasonNumber>,
39		episode: impl Into<EpisodeNumber>,
40		language: Option<&str>,
41	) -> Result<Episode, Error> {
42		let request = make_request(
43			&self.config,
44			&format!(
45				"/3/tv/{}/season/{}/episode/{}",
46				id.into().into_raw(),
47				season.into(),
48				episode.into()
49			),
50			language,
51		)?;
52		exec_request(&self.config, &*self.cache, &self.policy, request).await
53	}
54}