crypto_pay_api/webhook/
mod.rs

1mod config;
2mod handler;
3
4pub use config::{WebhookHandlerConfig, WebhookHandlerConfigBuilder};
5pub use handler::WebhookHandler;
6
7use crate::client::CryptoBot;
8
9impl CryptoBot {
10    /// Creates a new webhook handler with the given config
11    ///
12    /// # Example
13    /// ```no_run
14    /// use crypto_pay_api::prelude::*;
15    /// use std::time::Duration;
16    ///
17    /// #[tokio::main]
18    /// async fn main() -> Result<(), CryptoBotError> {
19    ///     let client = CryptoBot::builder().api_token("YOUR_API_TOKEN").build().unwrap();
20    ///
21    ///     let config = WebhookHandlerConfigBuilder::new()
22    ///         .expiration_time(Duration::from_secs(60 * 10))
23    ///         .build();
24    ///
25    ///     let webhook_handler = client.webhook_handler(config);
26    ///     Ok(())
27    /// }
28    /// ```
29    pub fn webhook_handler(&self, config: WebhookHandlerConfig) -> WebhookHandler {
30        WebhookHandler::with_config(&self.api_token, config)
31    }
32}
33
34#[cfg(test)]
35mod tests {
36    use super::*;
37    use std::time::Duration;
38
39    #[test]
40    fn test_webhook_handler_creation() {
41        let client = CryptoBot::test_client();
42
43        // Test with default config
44        let config = WebhookHandlerConfigBuilder::new().build();
45        let handler = client.webhook_handler(config);
46
47        assert_eq!(handler.api_token, client.api_token);
48        assert_eq!(handler.config.expiration_time, Some(Duration::from_secs(600)));
49
50        // Test with custom config
51        let custom_config = WebhookHandlerConfigBuilder::new()
52            .expiration_time(Duration::from_secs(300))
53            .build();
54
55        let handler = client.webhook_handler(custom_config);
56
57        assert_eq!(handler.api_token, client.api_token);
58        assert_eq!(handler.config.expiration_time, Some(Duration::from_secs(300)));
59    }
60}