public async Task <ValidationEntryListSegment> ListEntriesSegmentedAsync(Guid validationId, ValidationEntryListingOptions options = default, CancellationToken cancellationToken = default) { // Generate the additional parameters, where needed var restClient = _restClientFactory.Build(); // Send the request to the Verifalia servers Dictionary <string, string> queryParams = null; if (options != null) { queryParams = new Dictionary <string, string>(); if (options.Limit > 0) { queryParams["limit"] = options.Limit.ToString(CultureInfo.InvariantCulture); } // Predicates if (options.StatusFilter != null) { foreach (var fragment in options.StatusFilter.Serialize("status")) { queryParams[fragment.Key] = fragment.Value; } } } using (var response = await restClient .InvokeAsync(HttpMethod.Get, $"email-validations/{validationId:D}/entries", queryParams: queryParams, headers: new Dictionary <string, object> { { "Accept", WellKnownMimeContentTypes.ApplicationJson } }, cancellationToken: cancellationToken) .ConfigureAwait(false)) { return(await ListEntriesSegmentedImplAsync(restClient, response) .ConfigureAwait(false)); } }
public async Task <Stream> ExportEntriesAsync(Guid validationId, ExportedEntriesFormat format, ValidationEntryListingOptions options = default, CancellationToken cancellationToken = default) { // Determines the acceptable MIME content type var acceptableMimeContentType = format switch { ExportedEntriesFormat.Csv => WellKnownMimeContentTypes.TextCsv, ExportedEntriesFormat.ExcelXls => WellKnownMimeContentTypes.ExcelXls, ExportedEntriesFormat.ExcelXlsx => WellKnownMimeContentTypes.ExcelXlsx, _ => throw new ArgumentOutOfRangeException(nameof(format), format, null) }; // Sends the request to the Verifalia servers var restClient = _restClientFactory.Build(); var response = await restClient .InvokeAsync(HttpMethod.Get, $"email-validations/{validationId:D}/entries", headers : new Dictionary <string, object> { { "Accept", acceptableMimeContentType } }, cancellationToken : cancellationToken) .ConfigureAwait(false); // On success, returns the response body (which is formatted according to the requested export format) if (response.StatusCode == HttpStatusCode.OK) { return(await response .Content #if NET5_0_OR_GREATER .ReadAsStreamAsync(cancellationToken) #else .ReadAsStreamAsync() #endif .ConfigureAwait(false)); } // An unexpected HTTP status code has been received at this point var responseBody = await response .Content #if NET5_0_OR_GREATER .ReadAsStringAsync(cancellationToken) #else .ReadAsStringAsync() #endif .ConfigureAwait(false); throw new VerifaliaException($"Unexpected HTTP response: {(int)response.StatusCode} {responseBody}"); } }
public IAsyncEnumerable <ValidationEntry> ListEntriesAsync(Guid validationId, ValidationEntryListingOptions options = default, CancellationToken cancellationToken = default) { return(AsyncEnumerableHelper .ToAsyncEnumerable <ValidationEntryListSegment, ValidationEntry, ValidationEntryListingOptions>( (listingOptions, token) => ListEntriesSegmentedAsync(validationId, listingOptions, token), (cursor, token) => ListEntriesSegmentedAsync(validationId, cursor, token), options, cancellationToken)); }