Skip to main content

flix_tmdb/
config.rs

1use governor::clock::MonotonicClock;
2use governor::state::{InMemoryState, NotKeyed};
3use governor::{Quota, RateLimiter};
4use nonzero_ext::nonzero;
5use url::Url;
6use url_macro::url;
7
8/// The client configuration
9pub struct Config {
10	/// The base URL of the API
11	pub base_url: Url,
12	/// The reqwest client that is used for every request
13	pub client: reqwest::Client,
14	/// The rate limiter to use for the client
15	pub limiter: RateLimiter<NotKeyed, InMemoryState, MonotonicClock>,
16	/// The bearer token for readonly access to the API
17	pub bearer_token: String,
18	/// An optional user agent string to provide to the API
19	pub user_agent: Option<String>,
20}
21
22impl Config {
23	/// Create a new configuration using the provided bearer token
24	pub fn new(bearer_token: String) -> Self {
25		Self {
26			base_url: url!("https://api.themoviedb.org"),
27			client: reqwest::Client::new(),
28			limiter: RateLimiter::direct(Quota::per_second(nonzero!(30u32))),
29			bearer_token,
30			user_agent: None,
31		}
32	}
33}