gelbooru_api/
client.rs

1use crate::AuthDetails;
2
3type HClient = hyper::Client<hyper_rustls::HttpsConnector<hyper::client::HttpConnector>>;
4
5/// Gelbooru API client.
6/// Used for authentication requests.
7///
8/// Should generally be reused for multiple requests.
9pub struct Client {
10    pub(crate) http_client: HClient,
11    pub(crate) auth: Option<AuthDetails>,
12}
13
14impl Client {
15    fn base() -> Self {
16        let connector = hyper_rustls::HttpsConnectorBuilder::new()
17            .with_native_roots()
18            .https_only()
19            .enable_http1()
20            .build();
21        let http_client = hyper::Client::builder().build::<_, hyper::Body>(connector);
22
23        Self {
24            http_client,
25            auth: None,
26        }
27    }
28
29    /// A basic unauthenticated client.
30    ///
31    /// May incur rate-limiting.
32    pub fn public() -> Self {
33        Self::base()
34    }
35
36    /// An authenticated client.
37    ///
38    /// May incur rate-limiting in extreme cases.
39    /// Users that have supported on Patreon have no rate-limiting whatsoever.
40    pub fn with_auth(details: AuthDetails) -> Self {
41        let mut client = Self::base();
42        client.auth = Some(details);
43        client
44    }
45}