supabase_rust/
client.rs

1use std::{env};
2use reqwest::{Client};
3
4use crate::Supabase;
5
6impl Supabase {
7    // Creates a new Supabase client. If no parameters are provided, it will attempt to read the
8    // environment variables `SUPABASE_URL`, `SUPABASE_API_KEY`, and `SUPABASE_JWT_SECRET`.
9    pub fn new(url: Option<&str>, api_key: Option<&str>, jwt: Option<&str>) -> Self {
10        let client: Client = Client::new();
11        let url: String = url
12            .map(String::from)
13            .unwrap_or_else(|| env::var("SUPABASE_URL").unwrap_or_else(|_| String::new()));
14        let api_key: String = api_key
15            .map(String::from)
16            .unwrap_or_else(|| env::var("SUPABASE_API_KEY").unwrap_or_else(|_| String::new()));
17        let jwt: String = jwt
18            .map(String::from)
19            .unwrap_or_else(|| env::var("SUPABASE_JWT_SECRET").unwrap_or_else(|_| String::new()));
20
21        Supabase {
22            client,
23            url: url.to_string(),
24            api_key: api_key.to_string(),
25            jwt: jwt.to_string(),
26            bearer_token: None,
27        }
28    }
29}
30
31#[cfg(test)]
32mod tests {
33    use super::*;
34
35    #[test]
36    fn test_client() {
37        let client: Supabase = Supabase::new(None, None, None);
38        let url = client.url.clone();
39        assert!(client.url == url);
40    }
41}