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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
use crate::api::*;
use crate::{ApiError, ClientConfig, HttpClient, RequestOptions};
use reqwest::Method;
pub struct WebhooksClient {
pub http_client: HttpClient,
}
impl WebhooksClient {
pub fn new(config: ClientConfig) -> Result<Self, ApiError> {
Ok(Self {
http_client: HttpClient::new(config.clone())?,
})
}
/// Register a webhook endpoint for the given event types (`*` for every event). The URL must be an https address that resolves to a public network (422 otherwise). The signing secret is generated unless `secret` is given, and this call is the only one that returns it.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn subscriptions_create(
&self,
request: &SubscriptionsCreateWebhooksRequest,
options: Option<RequestOptions>,
) -> Result<SubscriptionsCreateWebhooksResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"v1/webhooks/subscriptions/create",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// List the company's webhook subscriptions with their last delivery state. Filterable by `url` and `isActive`; sortable by `createdAt` and `url`.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn subscriptions_list(
&self,
request: &SubscriptionsListWebhooksRequest,
options: Option<RequestOptions>,
) -> Result<SubscriptionsListWebhooksResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"v1/webhooks/subscriptions/list",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Change the URL, event types or `isActive` flag of a subscription; at least one field is required (400) and a new URL must be an https address that resolves to a public network (422). Setting `isActive` to true also clears `pausedAt` and `consecutiveFailures`, which is how a subscription paused after 5 failed deliveries in a row is switched back on.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn subscriptions_update(
&self,
request: &SubscriptionsUpdateWebhooksRequest,
options: Option<RequestOptions>,
) -> Result<SubscriptionsUpdateWebhooksResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"v1/webhooks/subscriptions/update",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Delete a webhook subscription.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn subscriptions_delete(
&self,
request: &SubscriptionsDeleteWebhooksRequest,
options: Option<RequestOptions>,
) -> Result<SubscriptionsDeleteWebhooksResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"v1/webhooks/subscriptions/delete",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// List the company's webhook deliveries, newest first. Filterable by `status`, `eventType` and `subscriptionId`; sortable by `createdAt`.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn deliveries_list(
&self,
request: &DeliveriesListWebhooksRequest,
options: Option<RequestOptions>,
) -> Result<DeliveriesListWebhooksResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"v1/webhooks/deliveries/list",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
/// Send a delivery again now: its status goes back to `pending` with the attempt count and last error cleared. Answers 409 when the subscription is inactive.
///
/// # Arguments
///
/// * `options` - Additional request options such as headers, timeout, etc.
///
/// # Returns
///
/// JSON response from the API
pub async fn deliveries_redeliver(
&self,
request: &DeliveriesRedeliverWebhooksRequest,
options: Option<RequestOptions>,
) -> Result<DeliveriesRedeliverWebhooksResponse, ApiError> {
self.http_client
.execute_request(
Method::POST,
"v1/webhooks/deliveries/redeliver",
Some(serde_json::to_value(request).map_err(ApiError::Serialization)?),
None,
options,
)
.await
}
}