Skip to main content

sure_client_rs/client/
mod.rs

1mod accounts;
2mod auth;
3mod categories;
4mod chats;
5mod core;
6mod merchants;
7mod sync;
8mod transactions;
9mod usage;
10mod valuations;
11
12use url::Url;
13
14use crate::types::Auth;
15
16/// The main Sure API client
17///
18/// This client provides access to all Sure API endpoints. It handles authentication,
19/// request execution, and error handling.
20///
21/// The API supports two authentication methods:
22/// - Bearer token (JWT) via Authorization header
23/// - API key via X-Api-Key header
24///
25/// # Example with API Key
26/// ```no_run
27/// use sure_client_rs::{SureClient, Auth};
28///
29/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
30/// let client = SureClient::new(
31///     reqwest::Client::new(),
32///     Auth::api_key("your_api_key"),
33///     "http://localhost:3000".to_string().parse().unwrap(),
34/// );
35///
36/// let categories = client.get_categories().call().await?;
37/// # Ok(())
38/// # }
39/// ```
40///
41/// # Example with Bearer Token
42/// ```no_run
43/// use sure_client_rs::{SureClient, Auth};
44///
45/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
46/// let client = SureClient::new(
47///     reqwest::Client::new(),
48///     Auth::bearer("your_jwt_token"),
49///     "http://localhost:3000".to_string().parse().unwrap(),
50/// );
51///
52/// let categories = client.get_categories().call().await?;
53/// # Ok(())
54/// # }
55/// ```
56#[derive(Debug, Clone)]
57pub struct SureClient {
58    /// The HTTP client for making requests
59    pub(crate) client: reqwest::Client,
60    /// Authentication credentials (Bearer token or API key)
61    pub(crate) auth: Auth,
62    /// Base URL for the API
63    pub(crate) base_url: Url,
64}
65
66impl SureClient {
67    /// Create a new Sure API client
68    ///
69    /// # Arguments
70    /// * `client` - A configured reqwest::Client for making HTTP requests
71    /// * `auth` - Authentication method (Bearer token or API key)
72    /// * `base_url` - base url to target
73    ///
74    /// # Example with API Key
75    /// ```no_run
76    /// use sure_client_rs::{SureClient, Auth};
77    ///
78    /// let client = SureClient::new(
79    ///     reqwest::Client::new(),
80    ///     Auth::api_key("your_api_key"),
81    ///     "http://localhost:3000".to_string().parse().unwrap()
82    /// );
83    /// ```
84    ///
85    /// # Example with Bearer Token
86    /// ```no_run
87    /// use sure_client_rs::{SureClient, Auth};
88    ///
89    /// let client = SureClient::new(
90    ///     reqwest::Client::new(),
91    ///     Auth::bearer("your_token"),
92    ///     "http://localhost:3000".to_string().parse().unwrap()
93    /// );
94    /// ```
95    pub fn new<T: Into<Auth>>(client: reqwest::Client, auth: T, base_url: Url) -> Self {
96        Self {
97            client,
98            auth: auth.into(),
99            base_url,
100        }
101    }
102}