flix_tmdb/api/
seasons.rs

1//! Seasons API
2
3use core::time::Duration;
4use std::rc::Rc;
5
6use flix_model::numbers::SeasonNumber;
7
8use governor::Jitter;
9
10use crate::Config;
11use crate::model::Season;
12use crate::model::id::ShowId;
13
14use super::{Error, make_request};
15
16/// TMDB Seasons API client
17pub struct Client {
18	config: Rc<Config>,
19}
20
21impl Client {
22	/// Create a new client with the given configuration
23	pub fn new(config: Rc<Config>) -> Self {
24		Self { config }
25	}
26}
27
28impl Client {
29	/// Fetch the details of the season refered to by ID and season number
30	pub async fn get_details(
31		&self,
32		id: impl Into<ShowId>,
33		season: impl Into<SeasonNumber>,
34		language: Option<&str>,
35	) -> Result<Season, Error> {
36		self.config
37			.limiter
38			.until_ready_with_jitter(Jitter::new(
39				Duration::from_millis(0),
40				Duration::from_millis(50),
41			))
42			.await;
43
44		Ok(self
45			.config
46			.client
47			.execute(make_request(
48				&self.config,
49				&format!("/3/tv/{}/season/{}", id.into().into_raw(), season.into()),
50				language,
51			)?)
52			.await?
53			.error_for_status()?
54			.json()
55			.await?)
56	}
57}