akahu_client/client/
mod.rs

1//! Akahu API client implementation.
2
3mod accounts;
4mod core;
5mod me;
6mod refresh;
7mod transactions;
8
9use crate::{AppSecret, AppToken};
10
11/// Default base URL for the Akahu API
12const DEFAULT_BASE_URL: &str = "https://api.akahu.io/v1";
13
14/// The main Akahu API client.
15///
16/// Use the builder pattern to construct a new client.
17pub struct AkahuClient {
18    /// HTTP client for making requests
19    client: reqwest::Client,
20    /// Application ID token
21    app_id_token: AppToken,
22    /// Optional application secret for app-scoped endpoints
23    app_secret: Option<AppSecret>,
24    /// Base URL for API requests
25    base_url: String,
26}
27
28impl AkahuClient {
29    /// Create a new Akahu client.
30    ///
31    /// # Arguments
32    ///
33    /// * `client` - The HTTP client to use for requests
34    /// * `app_id_token` - Your Akahu application ID token
35    /// * `base_url` - Optional custom base URL (defaults to `https://api.akahu.io/v1`)
36    pub fn new<T: Into<AppToken>>(
37        client: reqwest::Client,
38        app_id_token: T,
39        base_url: Option<String>,
40    ) -> Self {
41        let base_url = base_url.unwrap_or_else(|| DEFAULT_BASE_URL.to_string());
42
43        Self {
44            client,
45            app_id_token: app_id_token.into(),
46            app_secret: None,
47            base_url,
48        }
49    }
50
51    /// Set the app secret for app-scoped endpoints.
52    ///
53    /// The app secret is required for app-scoped endpoints like Categories.
54    /// These endpoints use HTTP Basic Authentication with app_id_token:app_secret.
55    pub fn with_app_secret<T: Into<AppSecret>>(mut self, app_secret: T) -> Self {
56        self.app_secret = Some(app_secret.into());
57        self
58    }
59}