Skip to main content

busbar_sf_tooling/client/
mod.rs

1//! Salesforce Tooling API client.
2//!
3//! This client wraps `SalesforceClient` from `sf-client` and provides
4//! typed methods for Tooling API operations.
5
6use busbar_sf_client::{ClientConfig, SalesforceClient};
7
8use crate::error::Result;
9
10mod apex;
11mod code_intelligence;
12mod collections;
13mod composite;
14mod coverage;
15#[cfg(feature = "dependencies")]
16mod dependencies;
17mod describe;
18mod execute;
19mod logs;
20mod query;
21mod sobject;
22mod test_execution;
23mod trace_flags;
24
25/// Salesforce Tooling API client.
26///
27/// Provides typed methods for Tooling API operations:
28/// - Execute anonymous Apex
29/// - Query Apex classes, triggers, and logs
30/// - Manage debug logs and trace flags
31/// - Code coverage information
32///
33/// # Example
34///
35/// ```rust,ignore
36/// use sf_tooling::ToolingClient;
37///
38/// let client = ToolingClient::new(
39///     "https://myorg.my.salesforce.com",
40///     "access_token_here",
41/// )?;
42///
43/// // Execute anonymous Apex
44/// let result = client.execute_anonymous("System.debug('Hello');").await?;
45///
46/// // Query Apex classes
47/// let classes: Vec<ApexClass> = client
48///     .query_all("SELECT Id, Name FROM ApexClass")
49///     .await?;
50/// ```
51#[derive(Debug, Clone)]
52pub struct ToolingClient {
53    client: SalesforceClient,
54}
55
56impl ToolingClient {
57    /// Create a new Tooling API client with the given instance URL and access token.
58    pub fn new(instance_url: impl Into<String>, access_token: impl Into<String>) -> Result<Self> {
59        let client = SalesforceClient::new(instance_url, access_token)?;
60        Ok(Self { client })
61    }
62
63    /// Create a new Tooling API client with custom HTTP configuration.
64    pub fn with_config(
65        instance_url: impl Into<String>,
66        access_token: impl Into<String>,
67        config: ClientConfig,
68    ) -> Result<Self> {
69        let client = SalesforceClient::with_config(instance_url, access_token, config)?;
70        Ok(Self { client })
71    }
72
73    /// Create a Tooling client from an existing SalesforceClient.
74    pub fn from_client(client: SalesforceClient) -> Self {
75        Self { client }
76    }
77
78    /// Get the underlying SalesforceClient.
79    pub fn inner(&self) -> &SalesforceClient {
80        &self.client
81    }
82
83    /// Get the instance URL.
84    pub fn instance_url(&self) -> &str {
85        self.client.instance_url()
86    }
87
88    /// Get the API version.
89    pub fn api_version(&self) -> &str {
90        self.client.api_version()
91    }
92
93    /// Set the API version.
94    pub fn with_api_version(mut self, version: impl Into<String>) -> Self {
95        self.client = self.client.with_api_version(version);
96        self
97    }
98}
99
100#[cfg(test)]
101mod tests {
102    use super::*;
103
104    #[test]
105    fn test_client_creation() {
106        let client = ToolingClient::new("https://na1.salesforce.com", "token123").unwrap();
107
108        assert_eq!(client.instance_url(), "https://na1.salesforce.com");
109        assert_eq!(client.api_version(), "62.0");
110    }
111
112    #[test]
113    fn test_api_version_override() {
114        let client = ToolingClient::new("https://na1.salesforce.com", "token")
115            .unwrap()
116            .with_api_version("60.0");
117
118        assert_eq!(client.api_version(), "60.0");
119    }
120}