|
| 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 EventsPublicConsumerOptions : SvixOptionsBase |
| 9 | + { |
| 10 | + public ulong? Limit { get; set; } |
| 11 | + public string? Iterator { get; set; } |
| 12 | + public string? EventType { get; set; } |
| 13 | + public string? Channel { get; set; } |
| 14 | + |
| 15 | + public new Dictionary<string, string> QueryParams() |
| 16 | + { |
| 17 | + return SerializeParams( |
| 18 | + new Dictionary<string, object?> |
| 19 | + { |
| 20 | + { "limit", Limit }, |
| 21 | + { "iterator", Iterator }, |
| 22 | + { "event_type", EventType }, |
| 23 | + { "channel", Channel }, |
| 24 | + } |
| 25 | + ); |
| 26 | + } |
| 27 | + } |
| 28 | + |
| 29 | + public class EventsPublicConsumerSeekOptions : SvixOptionsBase |
| 30 | + { |
| 31 | + public string? IdempotencyKey { get; set; } |
| 32 | + |
| 33 | + public new Dictionary<string, string> HeaderParams() |
| 34 | + { |
| 35 | + return SerializeParams( |
| 36 | + new Dictionary<string, object?> { { "idempotency-key", IdempotencyKey } } |
| 37 | + ); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + public class EventsPublic(SvixClient client) |
| 42 | + { |
| 43 | + readonly SvixClient _client = client; |
| 44 | + |
| 45 | + /// <summary> |
| 46 | + /// Reads the stream of created messages for an application, filtered on the Sink's event types and |
| 47 | + /// Channels, using server-managed iterator tracking. |
| 48 | + /// </summary> |
| 49 | + public async Task<PollingEndpointOut> ConsumerAsync( |
| 50 | + string appId, |
| 51 | + string sinkId, |
| 52 | + string consumerId, |
| 53 | + EventsPublicConsumerOptions? options = null, |
| 54 | + CancellationToken cancellationToken = default |
| 55 | + ) |
| 56 | + { |
| 57 | + try |
| 58 | + { |
| 59 | + var response = await _client.SvixHttpClient.SendRequestAsync<PollingEndpointOut>( |
| 60 | + method: HttpMethod.Get, |
| 61 | + path: "/api/v1/app/{app_id}/poller/{sink_id}/consumer/{consumer_id}", |
| 62 | + pathParams: new Dictionary<string, string> |
| 63 | + { |
| 64 | + { "app_id", appId }, |
| 65 | + { "sink_id", sinkId }, |
| 66 | + { "consumer_id", consumerId }, |
| 67 | + }, |
| 68 | + queryParams: options?.QueryParams(), |
| 69 | + headerParams: options?.HeaderParams(), |
| 70 | + cancellationToken: cancellationToken |
| 71 | + ); |
| 72 | + return response.Data; |
| 73 | + } |
| 74 | + catch (ApiException e) |
| 75 | + { |
| 76 | + _client.Logger?.LogError(e, $"{nameof(ConsumerAsync)} failed"); |
| 77 | + |
| 78 | + throw; |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// Reads the stream of created messages for an application, filtered on the Sink's event types and |
| 84 | + /// Channels, using server-managed iterator tracking. |
| 85 | + /// </summary> |
| 86 | + public PollingEndpointOut Consumer( |
| 87 | + string appId, |
| 88 | + string sinkId, |
| 89 | + string consumerId, |
| 90 | + EventsPublicConsumerOptions? options = null |
| 91 | + ) |
| 92 | + { |
| 93 | + try |
| 94 | + { |
| 95 | + var response = _client.SvixHttpClient.SendRequest<PollingEndpointOut>( |
| 96 | + method: HttpMethod.Get, |
| 97 | + path: "/api/v1/app/{app_id}/poller/{sink_id}/consumer/{consumer_id}", |
| 98 | + pathParams: new Dictionary<string, string> |
| 99 | + { |
| 100 | + { "app_id", appId }, |
| 101 | + { "sink_id", sinkId }, |
| 102 | + { "consumer_id", consumerId }, |
| 103 | + }, |
| 104 | + queryParams: options?.QueryParams(), |
| 105 | + headerParams: options?.HeaderParams() |
| 106 | + ); |
| 107 | + return response.Data; |
| 108 | + } |
| 109 | + catch (ApiException e) |
| 110 | + { |
| 111 | + _client.Logger?.LogError(e, $"{nameof(Consumer)} failed"); |
| 112 | + |
| 113 | + throw; |
| 114 | + } |
| 115 | + } |
| 116 | + |
| 117 | + /// <summary> |
| 118 | + /// Sets the starting offset for the consumer of a polling endpoint. |
| 119 | + /// </summary> |
| 120 | + public async Task<PollingEndpointConsumerSeekOut> ConsumerSeekAsync( |
| 121 | + string appId, |
| 122 | + string sinkId, |
| 123 | + string consumerId, |
| 124 | + PollingEndpointConsumerSeekIn pollingEndpointConsumerSeekIn, |
| 125 | + EventsPublicConsumerSeekOptions? options = null, |
| 126 | + CancellationToken cancellationToken = default |
| 127 | + ) |
| 128 | + { |
| 129 | + pollingEndpointConsumerSeekIn = |
| 130 | + pollingEndpointConsumerSeekIn |
| 131 | + ?? throw new ArgumentNullException(nameof(pollingEndpointConsumerSeekIn)); |
| 132 | + try |
| 133 | + { |
| 134 | + var response = |
| 135 | + await _client.SvixHttpClient.SendRequestAsync<PollingEndpointConsumerSeekOut>( |
| 136 | + method: HttpMethod.Post, |
| 137 | + path: "/api/v1/app/{app_id}/poller/{sink_id}/consumer/{consumer_id}/seek", |
| 138 | + pathParams: new Dictionary<string, string> |
| 139 | + { |
| 140 | + { "app_id", appId }, |
| 141 | + { "sink_id", sinkId }, |
| 142 | + { "consumer_id", consumerId }, |
| 143 | + }, |
| 144 | + queryParams: options?.QueryParams(), |
| 145 | + headerParams: options?.HeaderParams(), |
| 146 | + content: pollingEndpointConsumerSeekIn, |
| 147 | + cancellationToken: cancellationToken |
| 148 | + ); |
| 149 | + return response.Data; |
| 150 | + } |
| 151 | + catch (ApiException e) |
| 152 | + { |
| 153 | + _client.Logger?.LogError(e, $"{nameof(ConsumerSeekAsync)} failed"); |
| 154 | + |
| 155 | + throw; |
| 156 | + } |
| 157 | + } |
| 158 | + |
| 159 | + /// <summary> |
| 160 | + /// Sets the starting offset for the consumer of a polling endpoint. |
| 161 | + /// </summary> |
| 162 | + public PollingEndpointConsumerSeekOut ConsumerSeek( |
| 163 | + string appId, |
| 164 | + string sinkId, |
| 165 | + string consumerId, |
| 166 | + PollingEndpointConsumerSeekIn pollingEndpointConsumerSeekIn, |
| 167 | + EventsPublicConsumerSeekOptions? options = null |
| 168 | + ) |
| 169 | + { |
| 170 | + pollingEndpointConsumerSeekIn = |
| 171 | + pollingEndpointConsumerSeekIn |
| 172 | + ?? throw new ArgumentNullException(nameof(pollingEndpointConsumerSeekIn)); |
| 173 | + try |
| 174 | + { |
| 175 | + var response = _client.SvixHttpClient.SendRequest<PollingEndpointConsumerSeekOut>( |
| 176 | + method: HttpMethod.Post, |
| 177 | + path: "/api/v1/app/{app_id}/poller/{sink_id}/consumer/{consumer_id}/seek", |
| 178 | + pathParams: new Dictionary<string, string> |
| 179 | + { |
| 180 | + { "app_id", appId }, |
| 181 | + { "sink_id", sinkId }, |
| 182 | + { "consumer_id", consumerId }, |
| 183 | + }, |
| 184 | + queryParams: options?.QueryParams(), |
| 185 | + headerParams: options?.HeaderParams(), |
| 186 | + content: pollingEndpointConsumerSeekIn |
| 187 | + ); |
| 188 | + return response.Data; |
| 189 | + } |
| 190 | + catch (ApiException e) |
| 191 | + { |
| 192 | + _client.Logger?.LogError(e, $"{nameof(ConsumerSeek)} failed"); |
| 193 | + |
| 194 | + throw; |
| 195 | + } |
| 196 | + } |
| 197 | + } |
| 198 | +} |
0 commit comments