edgarkit/
config.rs

1//! Configuration types for customizing Edgar client behavior.
2//!
3//! The configuration system allows you to control rate limiting, HTTP timeouts,
4//! base URLs, and user agent strings. Most users can rely on the defaults provided
5//! by `Edgar::new()`, but custom configurations are useful for testing, research
6//! applications with specific performance requirements, or compliance scenarios.
7
8use std::time::Duration;
9
10/// Configuration settings for the Edgar HTTP client.
11///
12/// This struct contains all the settings needed to customize how the Edgar client
13/// behaves, including network timeouts, rate limiting, and service endpoints. The
14/// default configuration is optimized for general use and SEC.gov compliance, but
15/// you can adjust these settings based on your application's needs.
16///
17/// # Examples
18///
19/// Using defaults:
20/// ```rust
21/// # use edgarkit::EdgarConfig;
22/// let config = EdgarConfig::default();
23/// ```
24///
25/// Custom configuration:
26/// ```rust
27/// # use edgarkit::{EdgarConfig, EdgarUrls};
28/// # use std::time::Duration;
29/// let config = EdgarConfig::new(
30///     "research_app/1.0 contact@university.edu",
31///     5,  // More conservative rate
32///     Duration::from_secs(45),
33///     None,  // Use default URLs
34/// );
35/// ```
36#[derive(Debug, Clone)]
37pub struct EdgarConfig {
38    /// User agent string for HTTP requests (required by SEC)
39    pub user_agent: String,
40
41    /// Rate limit in requests per second (default: 10)
42    pub rate_limit: u32,
43
44    /// HTTP request timeout duration
45    pub timeout: Duration,
46
47    /// Base URLs for different EDGAR services
48    pub base_urls: EdgarUrls,
49}
50
51/// Base URLs for the different SEC EDGAR service endpoints.
52///
53/// The SEC EDGAR system is distributed across multiple domains, each serving
54/// different types of content. The archives domain hosts historical filings,
55/// the data domain provides structured API access, and the files domain serves
56/// various data files. You typically won't need to change these unless you're
57/// running tests against a mock server.
58#[derive(Debug, Clone)]
59pub struct EdgarUrls {
60    /// Archives base URL (historical filings)
61    pub archives: String,
62
63    /// Data API base URL (structured data)
64    pub data: String,
65
66    /// Files base URL (company tickers, etc.)
67    pub files: String,
68
69    /// Search API base URL
70    pub search: String,
71}
72
73impl Default for EdgarConfig {
74    fn default() -> Self {
75        Self {
76            user_agent: "edgarkit/0.1.0".to_string(),
77            rate_limit: 10,
78            timeout: Duration::from_secs(30),
79            base_urls: EdgarUrls {
80                archives: "https://www.sec.gov/Archives/edgar".to_string(),
81                data: "https://data.sec.gov".to_string(),
82                files: "https://www.sec.gov/files".to_string(),
83                search: "https://efts.sec.gov/LATEST/search-index/".to_string(),
84            },
85        }
86    }
87}
88
89impl EdgarConfig {
90    /// Creates custom Edgar configuration.
91    ///
92    /// # Example
93    ///
94    /// ```ignore
95    /// use edgarkit::{EdgarConfig, EdgarUrls};
96    /// use std::time::Duration;
97    ///
98    /// let config = EdgarConfig::new(
99    ///     "MyApp contact@example.com",
100    ///     10,
101    ///     Duration::from_secs(30),
102    ///     None,
103    /// );
104    /// ```
105    pub fn new(
106        user_agent: impl Into<String>,
107        rate_limit: u32,
108        timeout: Duration,
109        base_urls: Option<EdgarUrls>,
110    ) -> Self {
111        Self {
112            user_agent: user_agent.into(),
113            rate_limit,
114            timeout,
115            base_urls: base_urls.unwrap_or_default(),
116        }
117    }
118}
119
120impl Default for EdgarUrls {
121    fn default() -> Self {
122        Self {
123            archives: "https://www.sec.gov/Archives/edgar".to_string(),
124            data: "https://data.sec.gov".to_string(),
125            files: "https://www.sec.gov/files".to_string(),
126            search: "https://efts.sec.gov/LATEST/search-index/".to_string(),
127        }
128    }
129}