crypto_pay_api/webhook/
config.rs1use std::time::Duration;
2
3use crate::client::DEFAULT_WEBHOOK_EXPIRATION_TIME;
4
5#[derive(Debug, Default)]
6pub struct WebhookHandlerConfig {
7 pub expiration_time: Option<Duration>,
8}
9
10pub struct WebhookHandlerConfigBuilder {
11 pub config: WebhookHandlerConfig,
12}
13
14impl WebhookHandlerConfigBuilder {
15 pub fn new() -> Self {
20 Self {
21 config: WebhookHandlerConfig {
22 expiration_time: Some(Duration::from_secs(DEFAULT_WEBHOOK_EXPIRATION_TIME)),
23 },
24 }
25 }
26 pub fn expiration_time(mut self, duration: Duration) -> Self {
28 self.config.expiration_time = Some(duration);
29 self
30 }
31 pub fn disable_expiration(mut self) -> Self {
33 self.config.expiration_time = None;
34 self
35 }
36 pub fn build(self) -> WebhookHandlerConfig {
38 self.config
39 }
40}
41
42impl Default for WebhookHandlerConfigBuilder {
43 fn default() -> Self {
44 Self::new()
45 }
46}
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51 use std::time::Duration;
52
53 #[test]
54 fn test_webhook_handler_config_builder() {
55 let config = WebhookHandlerConfigBuilder::new()
56 .expiration_time(Duration::from_secs(1000))
57 .build();
58
59 assert_eq!(config.expiration_time, Some(Duration::from_secs(1000)));
60 }
61
62 #[test]
63 fn test_webhook_handler_config_builder_disable_expiration() {
64 let config = WebhookHandlerConfigBuilder::new().disable_expiration().build();
65
66 assert_eq!(config.expiration_time, None);
67 }
68
69 #[test]
70 fn test_webhook_handler_config_builder_default() {
71 let config = WebhookHandlerConfigBuilder::default().build();
72
73 assert_eq!(config.expiration_time, Some(Duration::from_secs(600)));
74 }
75}