Skip to content

Commit 9e9e6a5

Browse files
committed
csharp: Add operational webhook endpoint API
1 parent 087335b commit 9e9e6a5

File tree

3 files changed

+390
-1
lines changed

3 files changed

+390
-1
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System.Collections.Generic;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using Svix.Model;
5+
using Svix.Models;
6+
7+
namespace Svix.Abstractions
8+
{
9+
public interface IOperationalWebhookEndpoint
10+
{
11+
OperationalWebhookEndpointOut Create(OperationalWebhookEndpointIn endpoint,
12+
string idempotencyKey = default);
13+
14+
Task<OperationalWebhookEndpointOut> CreateAsync(OperationalWebhookEndpointIn endpoint,
15+
string idempotencyKey = default, CancellationToken cancellationToken = default);
16+
17+
bool Delete(string endpointId, string idempotencyKey = default);
18+
19+
Task<bool> DeleteAsync(string endpointId, string idempotencyKey = default,
20+
CancellationToken cancellationToken = default);
21+
22+
OperationalWebhookEndpointOut Get(string endpointId, string idempotencyKey = default);
23+
24+
Task<OperationalWebhookEndpointOut> GetAsync(string endpointId, string idempotencyKey = default,
25+
CancellationToken cancellationToken = default);
26+
27+
string GetSecret(string endpointId, string idempotencyKey = default);
28+
29+
Task<string> GetSecretAsync(string endpointId, string idempotencyKey = default,
30+
CancellationToken cancellationToken = default);
31+
32+
ListResponseOperationalWebhookEndpointOut List(ListOptions options = null,
33+
string idempotencyKey = default);
34+
35+
Task<ListResponseOperationalWebhookEndpointOut> ListAsync(ListOptions options = null,
36+
string idempotencyKey = default, CancellationToken cancellationToken = default);
37+
38+
bool RotateSecret(string endpointId, OperationalWebhookEndpointSecretIn secret,
39+
string idempotencyKey = default);
40+
41+
Task<bool> RotateSecretAsync(string endpointId, OperationalWebhookEndpointSecretIn secret,
42+
string idempotencyKey = default, CancellationToken cancellationToken = default);
43+
44+
OperationalWebhookEndpointOut Update(string endpointId,
45+
OperationalWebhookEndpointUpdate endpoint, string idempotencyKey = default);
46+
47+
Task<OperationalWebhookEndpointOut> UpdateAsync(string endpointId,
48+
OperationalWebhookEndpointUpdate endpoint, string idempotencyKey = default,
49+
CancellationToken cancellationToken = default);
50+
}
51+
}
Lines changed: 334 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,334 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Net;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
using Microsoft.Extensions.Logging;
7+
using Svix.Abstractions;
8+
using Svix.Api;
9+
using Svix.Client;
10+
using Svix.Model;
11+
using Svix.Models;
12+
13+
namespace Svix
14+
{
15+
public sealed class OperationalWebhookEndpoint : SvixResourceBase, IOperationalWebhookEndpoint
16+
{
17+
private readonly IWebhookEndpointApi _opWebhookEndpointApi;
18+
19+
public OperationalWebhookEndpoint(ISvixClient svixClient, IWebhookEndpointApi endpoingApi)
20+
: base(svixClient)
21+
{
22+
_opWebhookEndpointApi = endpoingApi ?? throw new ArgumentNullException(nameof(_opWebhookEndpointApi));
23+
}
24+
25+
public OperationalWebhookEndpointOut Create(
26+
OperationalWebhookEndpointIn endpoint, string idempotencyKey = default)
27+
{
28+
try
29+
{
30+
var lEndpoint = _opWebhookEndpointApi.createOperationalWebhookEndpoint(
31+
endpoint,
32+
idempotencyKey);
33+
34+
return lEndpoint;
35+
}
36+
catch (ApiException e)
37+
{
38+
Logger?.LogError(e, $"{nameof(Create)} failed");
39+
40+
if (Throw)
41+
throw;
42+
43+
return null;
44+
}
45+
}
46+
47+
public async Task<OperationalWebhookEndpointOut> CreateAsync(
48+
OperationalWebhookEndpointIn endpoint, string idempotencyKey = default,
49+
CancellationToken cancellationToken = default)
50+
{
51+
try
52+
{
53+
var lEndpoint = await _opWebhookEndpointApi.createOperationalWebhookEndpointAsync(
54+
endpoint,
55+
idempotencyKey,
56+
cancellationToken);
57+
58+
return lEndpoint;
59+
}
60+
catch (ApiException e)
61+
{
62+
Logger?.LogError(e, $"{nameof(CreateAsync)} failed");
63+
64+
if (Throw)
65+
throw;
66+
67+
return null;
68+
}
69+
}
70+
71+
public bool Delete(string endpointId, string idempotencyKey = default)
72+
{
73+
try
74+
{
75+
var lResponse = _opWebhookEndpointApi.deleteOperationalWebhookEndpointWithHttpInfo(
76+
endpointId);
77+
78+
return lResponse.StatusCode == HttpStatusCode.NoContent;
79+
}
80+
catch (ApiException e)
81+
{
82+
Logger?.LogError(e, $"{nameof(Delete)} failed");
83+
84+
if (Throw)
85+
throw;
86+
87+
return false;
88+
}
89+
}
90+
91+
public async Task<bool> DeleteAsync(string endpointId, string idempotencyKey = default,
92+
CancellationToken cancellationToken = default)
93+
{
94+
try
95+
{
96+
var lResponse = await _opWebhookEndpointApi.deleteOperationalWebhookEndpointWithHttpInfoAsync(
97+
endpointId,
98+
cancellationToken);
99+
100+
return lResponse.StatusCode == HttpStatusCode.NoContent;
101+
}
102+
catch (ApiException e)
103+
{
104+
Logger?.LogError(e, $"{nameof(DeleteAsync)} failed");
105+
106+
if (Throw)
107+
throw;
108+
109+
return false;
110+
}
111+
}
112+
113+
public OperationalWebhookEndpointOut Get(string endpointId, string idempotencyKey = default)
114+
{
115+
try
116+
{
117+
var lEndpoint = _opWebhookEndpointApi.getOperationalWebhookEndpoint(endpointId);
118+
return lEndpoint;
119+
}
120+
catch (ApiException e)
121+
{
122+
Logger?.LogError(e, $"{nameof(Get)} failed");
123+
124+
if (Throw)
125+
throw;
126+
127+
return null;
128+
}
129+
}
130+
131+
public async Task<OperationalWebhookEndpointOut> GetAsync(string endpointId, string idempotencyKey = default,
132+
CancellationToken cancellationToken = default)
133+
{
134+
try
135+
{
136+
var lEndpoint = await _opWebhookEndpointApi.getOperationalWebhookEndpointAsync(
137+
endpointId,
138+
cancellationToken);
139+
140+
return lEndpoint;
141+
}
142+
catch (ApiException e)
143+
{
144+
Logger?.LogError(e, $"{nameof(GetAsync)} failed");
145+
146+
if (Throw)
147+
throw;
148+
149+
return null;
150+
}
151+
}
152+
153+
public string GetSecret(string endpointId, string idempotencyKey = default)
154+
{
155+
try
156+
{
157+
var lSecret = _opWebhookEndpointApi.getOperationalWebhookEndpointSecret(
158+
endpointId);
159+
160+
return lSecret?.Key;
161+
}
162+
catch (ApiException e)
163+
{
164+
Logger?.LogError(e, $"{nameof(GetSecret)} failed");
165+
166+
if (Throw)
167+
throw;
168+
169+
return null;
170+
}
171+
}
172+
173+
public async Task<string> GetSecretAsync(string endpointId, string idempotencyKey = default,
174+
CancellationToken cancellationToken = default)
175+
{
176+
try
177+
{
178+
var lSecret = await _opWebhookEndpointApi.getOperationalWebhookEndpointSecretAsync(
179+
endpointId,
180+
cancellationToken);
181+
182+
return lSecret.Key;
183+
}
184+
catch (ApiException e)
185+
{
186+
Logger?.LogError(e, $"{nameof(GetSecretAsync)} failed");
187+
188+
if (Throw)
189+
throw;
190+
191+
return null;
192+
}
193+
}
194+
195+
public ListResponseOperationalWebhookEndpointOut List(ListOptions options = null,
196+
string idempotencyKey = default)
197+
{
198+
try
199+
{
200+
var lEndpoints = _opWebhookEndpointApi.listOperationalWebhookEndpoints(
201+
options?.Limit,
202+
options?.Iterator,
203+
options?.Order);
204+
205+
return lEndpoints;
206+
}
207+
catch (ApiException e)
208+
{
209+
Logger?.LogError(e, $"{nameof(List)} failed");
210+
211+
if (Throw)
212+
throw;
213+
214+
return new ListResponseEndpointOut();
215+
}
216+
}
217+
218+
public async Task<ListResponseOperationalWebhookEndpointOut> ListAsync(
219+
ListOptions options = null, string idempotencyKey = default,
220+
CancellationToken cancellationToken = default)
221+
{
222+
try
223+
{
224+
var lEndpoints = await _opWebhookEndpointApi.listOperationalWebhookEndpointsAsync(
225+
options?.Limit,
226+
options?.Iterator,
227+
options?.Order,
228+
cancellationToken);
229+
230+
return lEndpoints;
231+
}
232+
catch (ApiException e)
233+
{
234+
Logger?.LogError(e, $"{nameof(ListAsync)} failed");
235+
236+
if (Throw)
237+
throw;
238+
239+
return new ListResponseEndpointOut();
240+
}
241+
}
242+
243+
public bool RotateSecret(string endpointId, OperationalWebhookEndpointSecretIn secret, string idempotencyKey = default)
244+
{
245+
try
246+
{
247+
var lResponse = _opWebhookEndpointApi.rotateOperationalWebhookEndpointSecretWithHttpInfo(
248+
endpointId,
249+
secret,
250+
idempotencyKey);
251+
252+
return lResponse.StatusCode == HttpStatusCode.NoContent;
253+
}
254+
catch (ApiException e)
255+
{
256+
Logger?.LogError(e, $"{nameof(RotateSecret)} failed");
257+
258+
if (Throw)
259+
throw;
260+
261+
return false;
262+
}
263+
}
264+
265+
public async Task<bool> RotateSecretAsync(string endpointId, OperationalWebhookEndpointSecretIn secret,
266+
string idempotencyKey = default, CancellationToken cancellationToken = default)
267+
{
268+
try
269+
{
270+
var lResponse = await _opWebhookEndpointApi.rotateOperationalWebhookEndpointSecretWithHttpInfoAsync(
271+
endpointId,
272+
secret,
273+
idempotencyKey);
274+
275+
return lResponse.StatusCode == HttpStatusCode.NoContent;
276+
}
277+
catch (ApiException e)
278+
{
279+
Logger?.LogError(e, $"{nameof(RotateSecretAsync)} failed");
280+
281+
if (Throw)
282+
throw;
283+
284+
return false;
285+
}
286+
}
287+
288+
public OperationalWebhookEndpointOut Update(string endpointId,
289+
OperationalWebhookEndpointUpdate endpoint, string idempotencyKey = default)
290+
{
291+
try
292+
{
293+
var lEndpoint = _opWebhookEndpointApi.updateOperationalWebhookEndpoint(
294+
endpointId,
295+
endpoint);
296+
297+
return lEndpoint;
298+
}
299+
catch (ApiException e)
300+
{
301+
Logger?.LogError(e, $"{nameof(Update)} failed");
302+
303+
if (Throw)
304+
throw;
305+
306+
return null;
307+
}
308+
}
309+
310+
public async Task<OperationalWebhookEndpointOut> UpdateAsync(string endpointId,
311+
OperationalWebhookEndpointUpdate endpoint, string idempotencyKey = default,
312+
CancellationToken cancellationToken = default)
313+
{
314+
try
315+
{
316+
var lEndpoint = await _opWebhookEndpointApi.updateOperationalWebhookEndpointAsync(
317+
endpointId,
318+
endpoint,
319+
cancellationToken);
320+
321+
return lEndpoint;
322+
}
323+
catch (ApiException e)
324+
{
325+
Logger?.LogError(e, $"{nameof(UpdateAsync)} failed");
326+
327+
if (Throw)
328+
throw;
329+
330+
return null;
331+
}
332+
}
333+
}
334+
}

0 commit comments

Comments
 (0)