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