flix_tmdb/
client.rs

1use std::rc::Rc;
2
3use crate::{Config, api};
4
5/// The primary client that references all other clients
6pub struct Client {
7	collections: api::collections::Client,
8	movies: api::movies::Client,
9	shows: api::shows::Client,
10	seasons: api::seasons::Client,
11	episodes: api::episodes::Client,
12}
13
14impl Client {
15	/// Create a new client from a default configuration using the bearer token
16	pub fn new(bearer_token: String) -> Self {
17		Self::new_with_config(Config::new(bearer_token))
18	}
19
20	/// Create a new client with the given configuration
21	pub fn new_with_config(config: Config) -> Self {
22		let config = Rc::new(config);
23		Self {
24			collections: api::collections::Client::new(config.clone()),
25			movies: api::movies::Client::new(config.clone()),
26			shows: api::shows::Client::new(config.clone()),
27			seasons: api::seasons::Client::new(config.clone()),
28			episodes: api::episodes::Client::new(config.clone()),
29		}
30	}
31}
32
33impl Client {
34	/// Access the Collections API
35	pub fn collections(&self) -> &api::collections::Client {
36		&self.collections
37	}
38
39	/// Access the Movies API
40	pub fn movies(&self) -> &api::movies::Client {
41		&self.movies
42	}
43
44	/// Access the Shows API
45	pub fn shows(&self) -> &api::shows::Client {
46		&self.shows
47	}
48
49	/// Access the Seasons API
50	pub fn seasons(&self) -> &api::seasons::Client {
51		&self.seasons
52	}
53
54	/// Access the Episodes API
55	pub fn episodes(&self) -> &api::episodes::Client {
56		&self.episodes
57	}
58}