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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// Code generated by oagen. DO NOT EDIT.
use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
use serde::Serialize;
pub struct WebhooksApi<'a> {
pub(crate) client: &'a Client,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct ListWebhookEndpointsParams {
/// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `before="obj_123"` to fetch a new batch of objects before `"obj_123"`.
#[serde(skip_serializing_if = "Option::is_none")]
pub before: Option<String>,
/// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `after="obj_123"` to fetch a new batch of objects after `"obj_123"`.
#[serde(skip_serializing_if = "Option::is_none")]
pub after: Option<String>,
/// Upper limit on the number of objects to return, between `1` and `100`.
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
/// Order the results by the creation time. Supported values are `"asc"` (ascending), `"desc"` (descending), and `"normal"` (descending with reversed cursor semantics where `before` fetches older records and `after` fetches newer records). Defaults to descending.
#[serde(skip_serializing_if = "Option::is_none")]
pub order: Option<PaginationOrder>,
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateWebhookEndpointParams {
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: CreateWebhookEndpoint,
}
impl CreateWebhookEndpointParams {
/// Construct a new `CreateWebhookEndpointParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: CreateWebhookEndpoint) -> Self {
Self { body }
}
}
#[derive(Debug, Clone, Serialize)]
pub struct UpdateWebhookEndpointParams {
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: UpdateWebhookEndpoint,
}
impl UpdateWebhookEndpointParams {
/// Construct a new `UpdateWebhookEndpointParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: UpdateWebhookEndpoint) -> Self {
Self { body }
}
}
impl<'a> WebhooksApi<'a> {
/// List Webhook Endpoints
///
/// Get a list of all of your existing webhook endpoints.
pub async fn list_webhook_endpoints(
&self,
params: ListWebhookEndpointsParams,
) -> Result<WebhookEndpointList, Error> {
self.list_webhook_endpoints_with_options(params, None).await
}
/// Variant of [`Self::list_webhook_endpoints`] that accepts per-request [`crate::RequestOptions`].
pub async fn list_webhook_endpoints_with_options(
&self,
params: ListWebhookEndpointsParams,
options: Option<&crate::RequestOptions>,
) -> Result<WebhookEndpointList, Error> {
let path = "/webhook_endpoints".to_string();
let method = http::Method::GET;
self.client
.request_with_query_opts(method, &path, ¶ms, options)
.await
}
/// Returns an async [`futures_util::Stream`] that yields every `WebhookEndpointJson`
/// across all pages, advancing the `after` cursor under the hood.
///
/// ```ignore
/// use futures_util::TryStreamExt;
/// let all: Vec<WebhookEndpointJson> = self
/// .list_webhook_endpoints_auto_paging(params)
/// .try_collect()
/// .await?;
/// ```
pub fn list_webhook_endpoints_auto_paging(
&self,
params: ListWebhookEndpointsParams,
) -> impl futures_util::Stream<Item = Result<WebhookEndpointJson, Error>> + '_ {
crate::pagination::auto_paginate_pages(move |after| {
let mut params = params.clone();
params.after = after;
async move {
let page = self.list_webhook_endpoints(params).await?;
Ok((page.data, page.list_metadata.after))
}
})
}
/// Create a Webhook Endpoint
///
/// Create a new webhook endpoint to receive event notifications.
pub async fn create_webhook_endpoint(
&self,
params: CreateWebhookEndpointParams,
) -> Result<WebhookEndpointJson, Error> {
self.create_webhook_endpoint_with_options(params, None)
.await
}
/// Variant of [`Self::create_webhook_endpoint`] that accepts per-request [`crate::RequestOptions`].
pub async fn create_webhook_endpoint_with_options(
&self,
params: CreateWebhookEndpointParams,
options: Option<&crate::RequestOptions>,
) -> Result<WebhookEndpointJson, Error> {
let path = "/webhook_endpoints".to_string();
let method = http::Method::POST;
self.client
.request_with_body_opts(method, &path, ¶ms, Some(¶ms.body), options)
.await
}
/// Update a Webhook Endpoint
///
/// Update the properties of an existing webhook endpoint.
pub async fn update_webhook_endpoint(
&self,
id: &str,
params: UpdateWebhookEndpointParams,
) -> Result<WebhookEndpointJson, Error> {
self.update_webhook_endpoint_with_options(id, params, None)
.await
}
/// Variant of [`Self::update_webhook_endpoint`] that accepts per-request [`crate::RequestOptions`].
pub async fn update_webhook_endpoint_with_options(
&self,
id: &str,
params: UpdateWebhookEndpointParams,
options: Option<&crate::RequestOptions>,
) -> Result<WebhookEndpointJson, Error> {
let id = crate::client::path_segment(id);
let path = format!("/webhook_endpoints/{id}");
let method = http::Method::PATCH;
self.client
.request_with_body_opts(method, &path, ¶ms, Some(¶ms.body), options)
.await
}
/// Delete a Webhook Endpoint
///
/// Delete an existing webhook endpoint.
pub async fn delete_webhook_endpoint(&self, id: &str) -> Result<(), Error> {
self.delete_webhook_endpoint_with_options(id, None).await
}
/// Variant of [`Self::delete_webhook_endpoint`] that accepts per-request [`crate::RequestOptions`].
pub async fn delete_webhook_endpoint_with_options(
&self,
id: &str,
options: Option<&crate::RequestOptions>,
) -> Result<(), Error> {
let id = crate::client::path_segment(id);
let path = format!("/webhook_endpoints/{id}");
let method = http::Method::DELETE;
self.client
.request_with_query_opts_empty(method, &path, &(), options)
.await
}
}