Skip to main content

flix_tmdb/api/
collections.rs

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