1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//! Webhooks API
//!
//! This module provides functionality to manage webhooks.
use crate::client::RainClient;
use crate::error::Result;
use crate::models::webhooks::*;
use uuid::Uuid;
impl RainClient {
/// Get all webhooks
///
/// # Arguments
///
/// * `params` - Query parameters to filter webhooks
///
/// # Returns
///
/// Returns a [`Vec<Webhook>`] containing the list of webhooks.
///
/// # Errors
///
/// This method can return the following errors:
/// - `401` - Invalid authorization
/// - `403` - Forbidden
/// - `404` - User not found
/// - `500` - Internal server error
///
/// # Examples
///
/// ```no_run
/// use rain_sdk::{RainClient, Config, Environment, AuthConfig};
/// use rain_sdk::models::webhooks::ListWebhooksParams;
///
/// # #[cfg(feature = "async")]
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let config = Config::new(Environment::Dev);
/// let auth = AuthConfig::with_api_key("your-api-key".to_string());
/// let client = RainClient::new(config, auth)?;
///
/// let params = ListWebhooksParams {
/// resource_id: None,
/// resource_type: None,
/// resource_action: None,
/// request_sent_at_before: None,
/// request_sent_at_after: None,
/// response_received_at_before: None,
/// response_received_at_after: None,
/// cursor: None,
/// limit: Some(20),
/// };
/// let webhooks = client.list_webhooks(¶ms).await?;
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "async")]
pub async fn list_webhooks(&self, params: &ListWebhooksParams) -> Result<Vec<Webhook>> {
let path = "/webhooks";
let query_string = serde_urlencoded::to_string(params)?;
let full_path = if query_string.is_empty() {
path.to_string()
} else {
format!("{path}?{query_string}")
};
self.get(&full_path).await
}
/// Get a webhook by its id
///
/// # Arguments
///
/// * `webhook_id` - The unique identifier of the webhook
///
/// # Returns
///
/// Returns a [`Webhook`] containing the webhook information.
///
/// # Errors
///
/// This method can return the following errors:
/// - `401` - Invalid authorization
/// - `403` - Forbidden
/// - `404` - Transaction not found
/// - `500` - Internal server error
///
/// # Examples
///
/// ```no_run
/// use rain_sdk::{RainClient, Config, Environment, AuthConfig};
/// use uuid::Uuid;
///
/// # #[cfg(feature = "async")]
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// let config = Config::new(Environment::Dev);
/// let auth = AuthConfig::with_api_key("your-api-key".to_string());
/// let client = RainClient::new(config, auth)?;
///
/// let webhook_id = Uuid::new_v4();
/// let webhook = client.get_webhook(&webhook_id).await?;
/// # Ok(())
/// # }
/// ```
#[cfg(feature = "async")]
pub async fn get_webhook(&self, webhook_id: &Uuid) -> Result<Webhook> {
let path = format!("/webhooks/{webhook_id}");
self.get(&path).await
}
/// Get all webhooks (blocking)
///
/// # Arguments
///
/// * `params` - Query parameters to filter webhooks
///
/// # Returns
///
/// Returns a [`Vec<Webhook>`] containing the list of webhooks.
#[cfg(feature = "sync")]
pub fn list_webhooks_blocking(&self, params: &ListWebhooksParams) -> Result<Vec<Webhook>> {
let path = "/webhooks";
let query_string = serde_urlencoded::to_string(params)?;
let full_path = if query_string.is_empty() {
path.to_string()
} else {
format!("{path}?{query_string}")
};
self.get_blocking(&full_path)
}
/// Get a webhook by its id (blocking)
///
/// # Arguments
///
/// * `webhook_id` - The unique identifier of the webhook
///
/// # Returns
///
/// Returns a [`Webhook`] containing the webhook information.
#[cfg(feature = "sync")]
pub fn get_webhook_blocking(&self, webhook_id: &Uuid) -> Result<Webhook> {
let path = format!("/webhooks/{webhook_id}");
self.get_blocking(&path)
}
}