plausible_rs/
plausible_analytics.rs

1use reqwest::Client;
2
3pub const BASE_URL: &str = "https://plausible.io";
4
5/// Plausible Analytics client.
6#[derive(Debug, Clone)]
7pub struct Plausible {
8    pub(crate) client: Client,
9    pub(crate) base_url: String,
10}
11
12impl Plausible {
13    /// Create a new Plausible Analytics client with a brand new `reqwest::Client`.
14    ///
15    /// The `client` is initialized with TLS certs from
16    /// [webpki roots](https://github.com/rustls/webpki-roots) by default.
17    #[must_use]
18    pub fn new() -> Self {
19        Self {
20            client: Client::new(),
21            base_url: BASE_URL.to_string(),
22        }
23    }
24
25    /// Create a new Plausible Analytics client with a given `reqwest::Client`.
26    #[must_use]
27    pub fn new_with_client(client: Client) -> Self {
28        Self {
29            client,
30            base_url: BASE_URL.to_string(),
31        }
32    }
33}
34
35impl Default for Plausible {
36    /// Defaults to `Self::new()`.
37    fn default() -> Self {
38        Self::new()
39    }
40}