cstats_core/api/
mod.rs

1//! API client and data structures
2
3use std::time::Duration;
4
5use reqwest::Client;
6// Re-export serde traits for public use
7pub use serde::{Deserialize, Serialize};
8
9use crate::{config::ApiConfig, Error, Result};
10
11pub mod client;
12pub mod types;
13pub mod usage_tracker;
14
15pub use client::{AnthropicApiClient, ApiClient};
16pub use types::*;
17pub use usage_tracker::LocalUsageTracker;
18
19/// HTTP client wrapper for API operations
20#[derive(Debug, Clone)]
21pub struct HttpClient {
22    client: Client,
23    config: ApiConfig,
24}
25
26impl HttpClient {
27    /// Create a new HTTP client with the given configuration
28    pub fn new(config: ApiConfig) -> Result<Self> {
29        let client = Client::builder()
30            .timeout(Duration::from_secs(config.timeout_seconds))
31            .build()
32            .map_err(Error::Http)?;
33
34        Ok(Self { client, config })
35    }
36
37    /// Get the underlying reqwest client
38    pub fn client(&self) -> &Client {
39        &self.client
40    }
41
42    /// Get the configuration
43    pub fn config(&self) -> &ApiConfig {
44        &self.config
45    }
46}