|
| 1 | +// this file is @generated |
| 2 | +#nullable enable |
| 3 | +using Microsoft.Extensions.Logging; |
| 4 | +using Svix.Models; |
| 5 | + |
| 6 | +namespace Svix |
| 7 | +{ |
| 8 | + public class IngestSourceListOptions : SvixOptionsBase |
| 9 | + { |
| 10 | + public ulong? Limit { get; set; } |
| 11 | + public string? Iterator { get; set; } |
| 12 | + public Ordering? Order { get; set; } |
| 13 | + |
| 14 | + public new Dictionary<string, string> QueryParams() |
| 15 | + { |
| 16 | + return SerializeParams( |
| 17 | + new Dictionary<string, object?> |
| 18 | + { |
| 19 | + { "limit", Limit }, |
| 20 | + { "iterator", Iterator }, |
| 21 | + { "order", Order }, |
| 22 | + } |
| 23 | + ); |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + public class IngestSourceCreateOptions : SvixOptionsBase |
| 28 | + { |
| 29 | + public string? IdempotencyKey { get; set; } |
| 30 | + |
| 31 | + public new Dictionary<string, string> HeaderParams() |
| 32 | + { |
| 33 | + return SerializeParams( |
| 34 | + new Dictionary<string, object?> { { "idempotency-key", IdempotencyKey } } |
| 35 | + ); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + public class IngestSourceRotateTokenOptions : SvixOptionsBase |
| 40 | + { |
| 41 | + public string? IdempotencyKey { get; set; } |
| 42 | + |
| 43 | + public new Dictionary<string, string> HeaderParams() |
| 44 | + { |
| 45 | + return SerializeParams( |
| 46 | + new Dictionary<string, object?> { { "idempotency-key", IdempotencyKey } } |
| 47 | + ); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + public class IngestSource(SvixClient client) |
| 52 | + { |
| 53 | + readonly SvixClient _client = client; |
| 54 | + |
| 55 | + /// <summary> |
| 56 | + /// List of all the organization's Ingest Sources. |
| 57 | + /// </summary> |
| 58 | + public async Task<ListResponseIngestSourceOut> ListAsync( |
| 59 | + IngestSourceListOptions? options = null, |
| 60 | + CancellationToken cancellationToken = default |
| 61 | + ) |
| 62 | + { |
| 63 | + try |
| 64 | + { |
| 65 | + var response = |
| 66 | + await _client.SvixHttpClient.SendRequestAsync<ListResponseIngestSourceOut>( |
| 67 | + method: HttpMethod.Get, |
| 68 | + path: "/ingest/api/v1/source", |
| 69 | + queryParams: options?.QueryParams(), |
| 70 | + headerParams: options?.HeaderParams(), |
| 71 | + cancellationToken: cancellationToken |
| 72 | + ); |
| 73 | + return response.Data; |
| 74 | + } |
| 75 | + catch (ApiException e) |
| 76 | + { |
| 77 | + _client.Logger?.LogError(e, $"{nameof(ListAsync)} failed"); |
| 78 | + |
| 79 | + throw; |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + /// <summary> |
| 84 | + /// List of all the organization's Ingest Sources. |
| 85 | + /// </summary> |
| 86 | + public ListResponseIngestSourceOut List(IngestSourceListOptions? options = null) |
| 87 | + { |
| 88 | + try |
| 89 | + { |
| 90 | + var response = _client.SvixHttpClient.SendRequest<ListResponseIngestSourceOut>( |
| 91 | + method: HttpMethod.Get, |
| 92 | + path: "/ingest/api/v1/source", |
| 93 | + queryParams: options?.QueryParams(), |
| 94 | + headerParams: options?.HeaderParams() |
| 95 | + ); |
| 96 | + return response.Data; |
| 97 | + } |
| 98 | + catch (ApiException e) |
| 99 | + { |
| 100 | + _client.Logger?.LogError(e, $"{nameof(List)} failed"); |
| 101 | + |
| 102 | + throw; |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + /// <summary> |
| 107 | + /// Create Ingest Source. |
| 108 | + /// </summary> |
| 109 | + public async Task<IngestSourceOut> CreateAsync( |
| 110 | + IngestSourceIn ingestSourceIn, |
| 111 | + IngestSourceCreateOptions? options = null, |
| 112 | + CancellationToken cancellationToken = default |
| 113 | + ) |
| 114 | + { |
| 115 | + ingestSourceIn = |
| 116 | + ingestSourceIn ?? throw new ArgumentNullException(nameof(ingestSourceIn)); |
| 117 | + try |
| 118 | + { |
| 119 | + var response = await _client.SvixHttpClient.SendRequestAsync<IngestSourceOut>( |
| 120 | + method: HttpMethod.Post, |
| 121 | + path: "/ingest/api/v1/source", |
| 122 | + queryParams: options?.QueryParams(), |
| 123 | + headerParams: options?.HeaderParams(), |
| 124 | + content: ingestSourceIn, |
| 125 | + cancellationToken: cancellationToken |
| 126 | + ); |
| 127 | + return response.Data; |
| 128 | + } |
| 129 | + catch (ApiException e) |
| 130 | + { |
| 131 | + _client.Logger?.LogError(e, $"{nameof(CreateAsync)} failed"); |
| 132 | + |
| 133 | + throw; |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + /// <summary> |
| 138 | + /// Create Ingest Source. |
| 139 | + /// </summary> |
| 140 | + public IngestSourceOut Create( |
| 141 | + IngestSourceIn ingestSourceIn, |
| 142 | + IngestSourceCreateOptions? options = null |
| 143 | + ) |
| 144 | + { |
| 145 | + ingestSourceIn = |
| 146 | + ingestSourceIn ?? throw new ArgumentNullException(nameof(ingestSourceIn)); |
| 147 | + try |
| 148 | + { |
| 149 | + var response = _client.SvixHttpClient.SendRequest<IngestSourceOut>( |
| 150 | + method: HttpMethod.Post, |
| 151 | + path: "/ingest/api/v1/source", |
| 152 | + queryParams: options?.QueryParams(), |
| 153 | + headerParams: options?.HeaderParams(), |
| 154 | + content: ingestSourceIn |
| 155 | + ); |
| 156 | + return response.Data; |
| 157 | + } |
| 158 | + catch (ApiException e) |
| 159 | + { |
| 160 | + _client.Logger?.LogError(e, $"{nameof(Create)} failed"); |
| 161 | + |
| 162 | + throw; |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + /// <summary> |
| 167 | + /// Get an Ingest Source by id or uid. |
| 168 | + /// </summary> |
| 169 | + public async Task<IngestSourceOut> GetAsync( |
| 170 | + string sourceId, |
| 171 | + CancellationToken cancellationToken = default |
| 172 | + ) |
| 173 | + { |
| 174 | + try |
| 175 | + { |
| 176 | + var response = await _client.SvixHttpClient.SendRequestAsync<IngestSourceOut>( |
| 177 | + method: HttpMethod.Get, |
| 178 | + path: "/ingest/api/v1/source/{source_id}", |
| 179 | + pathParams: new Dictionary<string, string> { { "source_id", sourceId } }, |
| 180 | + cancellationToken: cancellationToken |
| 181 | + ); |
| 182 | + return response.Data; |
| 183 | + } |
| 184 | + catch (ApiException e) |
| 185 | + { |
| 186 | + _client.Logger?.LogError(e, $"{nameof(GetAsync)} failed"); |
| 187 | + |
| 188 | + throw; |
| 189 | + } |
| 190 | + } |
| 191 | + |
| 192 | + /// <summary> |
| 193 | + /// Get an Ingest Source by id or uid. |
| 194 | + /// </summary> |
| 195 | + public IngestSourceOut Get(string sourceId) |
| 196 | + { |
| 197 | + try |
| 198 | + { |
| 199 | + var response = _client.SvixHttpClient.SendRequest<IngestSourceOut>( |
| 200 | + method: HttpMethod.Get, |
| 201 | + path: "/ingest/api/v1/source/{source_id}", |
| 202 | + pathParams: new Dictionary<string, string> { { "source_id", sourceId } } |
| 203 | + ); |
| 204 | + return response.Data; |
| 205 | + } |
| 206 | + catch (ApiException e) |
| 207 | + { |
| 208 | + _client.Logger?.LogError(e, $"{nameof(Get)} failed"); |
| 209 | + |
| 210 | + throw; |
| 211 | + } |
| 212 | + } |
| 213 | + |
| 214 | + /// <summary> |
| 215 | + /// Update an Ingest Source. |
| 216 | + /// </summary> |
| 217 | + public async Task<IngestSourceOut> UpdateAsync( |
| 218 | + string sourceId, |
| 219 | + IngestSourceIn ingestSourceIn, |
| 220 | + CancellationToken cancellationToken = default |
| 221 | + ) |
| 222 | + { |
| 223 | + ingestSourceIn = |
| 224 | + ingestSourceIn ?? throw new ArgumentNullException(nameof(ingestSourceIn)); |
| 225 | + try |
| 226 | + { |
| 227 | + var response = await _client.SvixHttpClient.SendRequestAsync<IngestSourceOut>( |
| 228 | + method: HttpMethod.Put, |
| 229 | + path: "/ingest/api/v1/source/{source_id}", |
| 230 | + pathParams: new Dictionary<string, string> { { "source_id", sourceId } }, |
| 231 | + content: ingestSourceIn, |
| 232 | + cancellationToken: cancellationToken |
| 233 | + ); |
| 234 | + return response.Data; |
| 235 | + } |
| 236 | + catch (ApiException e) |
| 237 | + { |
| 238 | + _client.Logger?.LogError(e, $"{nameof(UpdateAsync)} failed"); |
| 239 | + |
| 240 | + throw; |
| 241 | + } |
| 242 | + } |
| 243 | + |
| 244 | + /// <summary> |
| 245 | + /// Update an Ingest Source. |
| 246 | + /// </summary> |
| 247 | + public IngestSourceOut Update(string sourceId, IngestSourceIn ingestSourceIn) |
| 248 | + { |
| 249 | + ingestSourceIn = |
| 250 | + ingestSourceIn ?? throw new ArgumentNullException(nameof(ingestSourceIn)); |
| 251 | + try |
| 252 | + { |
| 253 | + var response = _client.SvixHttpClient.SendRequest<IngestSourceOut>( |
| 254 | + method: HttpMethod.Put, |
| 255 | + path: "/ingest/api/v1/source/{source_id}", |
| 256 | + pathParams: new Dictionary<string, string> { { "source_id", sourceId } }, |
| 257 | + content: ingestSourceIn |
| 258 | + ); |
| 259 | + return response.Data; |
| 260 | + } |
| 261 | + catch (ApiException e) |
| 262 | + { |
| 263 | + _client.Logger?.LogError(e, $"{nameof(Update)} failed"); |
| 264 | + |
| 265 | + throw; |
| 266 | + } |
| 267 | + } |
| 268 | + |
| 269 | + /// <summary> |
| 270 | + /// Delete an Ingest Source. |
| 271 | + /// </summary> |
| 272 | + public async Task<bool> DeleteAsync( |
| 273 | + string sourceId, |
| 274 | + CancellationToken cancellationToken = default |
| 275 | + ) |
| 276 | + { |
| 277 | + try |
| 278 | + { |
| 279 | + var response = await _client.SvixHttpClient.SendRequestAsync<bool>( |
| 280 | + method: HttpMethod.Delete, |
| 281 | + path: "/ingest/api/v1/source/{source_id}", |
| 282 | + pathParams: new Dictionary<string, string> { { "source_id", sourceId } }, |
| 283 | + cancellationToken: cancellationToken |
| 284 | + ); |
| 285 | + return response.Data; |
| 286 | + } |
| 287 | + catch (ApiException e) |
| 288 | + { |
| 289 | + _client.Logger?.LogError(e, $"{nameof(DeleteAsync)} failed"); |
| 290 | + |
| 291 | + throw; |
| 292 | + } |
| 293 | + } |
| 294 | + |
| 295 | + /// <summary> |
| 296 | + /// Delete an Ingest Source. |
| 297 | + /// </summary> |
| 298 | + public bool Delete(string sourceId) |
| 299 | + { |
| 300 | + try |
| 301 | + { |
| 302 | + var response = _client.SvixHttpClient.SendRequest<bool>( |
| 303 | + method: HttpMethod.Delete, |
| 304 | + path: "/ingest/api/v1/source/{source_id}", |
| 305 | + pathParams: new Dictionary<string, string> { { "source_id", sourceId } } |
| 306 | + ); |
| 307 | + return response.Data; |
| 308 | + } |
| 309 | + catch (ApiException e) |
| 310 | + { |
| 311 | + _client.Logger?.LogError(e, $"{nameof(Delete)} failed"); |
| 312 | + |
| 313 | + throw; |
| 314 | + } |
| 315 | + } |
| 316 | + |
| 317 | + /// <summary> |
| 318 | + /// Rotate the Ingest Source's Url Token. |
| 319 | + /// |
| 320 | + /// This will rotate the ingest source's token, which is used to |
| 321 | + /// construct the unique `ingestUrl` for the source. Previous tokens |
| 322 | + /// will remain valid for 48 hours after rotation. The token can be |
| 323 | + /// rotated a maximum of three times within the 48-hour period. |
| 324 | + /// </summary> |
| 325 | + public async Task<RotateTokenOut> RotateTokenAsync( |
| 326 | + string sourceId, |
| 327 | + IngestSourceRotateTokenOptions? options = null, |
| 328 | + CancellationToken cancellationToken = default |
| 329 | + ) |
| 330 | + { |
| 331 | + try |
| 332 | + { |
| 333 | + var response = await _client.SvixHttpClient.SendRequestAsync<RotateTokenOut>( |
| 334 | + method: HttpMethod.Post, |
| 335 | + path: "/ingest/api/v1/source/{source_id}/token/rotate", |
| 336 | + pathParams: new Dictionary<string, string> { { "source_id", sourceId } }, |
| 337 | + queryParams: options?.QueryParams(), |
| 338 | + headerParams: options?.HeaderParams(), |
| 339 | + cancellationToken: cancellationToken |
| 340 | + ); |
| 341 | + return response.Data; |
| 342 | + } |
| 343 | + catch (ApiException e) |
| 344 | + { |
| 345 | + _client.Logger?.LogError(e, $"{nameof(RotateTokenAsync)} failed"); |
| 346 | + |
| 347 | + throw; |
| 348 | + } |
| 349 | + } |
| 350 | + |
| 351 | + /// <summary> |
| 352 | + /// Rotate the Ingest Source's Url Token. |
| 353 | + /// |
| 354 | + /// This will rotate the ingest source's token, which is used to |
| 355 | + /// construct the unique `ingestUrl` for the source. Previous tokens |
| 356 | + /// will remain valid for 48 hours after rotation. The token can be |
| 357 | + /// rotated a maximum of three times within the 48-hour period. |
| 358 | + /// </summary> |
| 359 | + public RotateTokenOut RotateToken( |
| 360 | + string sourceId, |
| 361 | + IngestSourceRotateTokenOptions? options = null |
| 362 | + ) |
| 363 | + { |
| 364 | + try |
| 365 | + { |
| 366 | + var response = _client.SvixHttpClient.SendRequest<RotateTokenOut>( |
| 367 | + method: HttpMethod.Post, |
| 368 | + path: "/ingest/api/v1/source/{source_id}/token/rotate", |
| 369 | + pathParams: new Dictionary<string, string> { { "source_id", sourceId } }, |
| 370 | + queryParams: options?.QueryParams(), |
| 371 | + headerParams: options?.HeaderParams() |
| 372 | + ); |
| 373 | + return response.Data; |
| 374 | + } |
| 375 | + catch (ApiException e) |
| 376 | + { |
| 377 | + _client.Logger?.LogError(e, $"{nameof(RotateToken)} failed"); |
| 378 | + |
| 379 | + throw; |
| 380 | + } |
| 381 | + } |
| 382 | + } |
| 383 | +} |
0 commit comments