Skip to main content

flix_tmdb/api/
seasons.rs

1//! Seasons API
2
3use std::rc::Rc;
4use std::sync::RwLock;
5
6use flix_model::numbers::SeasonNumber;
7
8use crate::api::exec_request;
9use crate::model::Season;
10use crate::model::id::ShowId;
11use crate::{Cache, CachePolicy, Config};
12
13use super::{Error, make_request};
14
15/// TMDB Seasons 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 season refered to by ID and season number
35	pub async fn get_details(
36		&self,
37		id: impl Into<ShowId>,
38		season: impl Into<SeasonNumber>,
39		language: Option<&str>,
40	) -> Result<Season, Error> {
41		let request = make_request(
42			&self.config,
43			&format!("/3/tv/{}/season/{}", id.into().into_raw(), season.into()),
44			language,
45		)?;
46		exec_request(&self.config, &*self.cache, &self.policy, request).await
47	}
48}