45 lines
1.6 KiB
C#
45 lines
1.6 KiB
C#
using DocumentService.Client.Interfaces;
|
|
using DocumentService.Client.Models.Requests;
|
|
using Microsoft.Extensions.Logging;
|
|
using System.Net.Http;
|
|
|
|
namespace DocumentService.Client.Clients;
|
|
|
|
/// <summary>
|
|
/// Implementation of Swiss QR Code extraction client.
|
|
/// </summary>
|
|
public class SwissQrCodeClient(HttpClient httpClient, ILogger<SwissQrCodeClient> logger) : BaseDocumentClient(httpClient, logger), ISwissQrCodeClient
|
|
{
|
|
/// <inheritdoc />
|
|
public async Task<SwissQrCodeExtractionResult> ExtractSwissQrCodeAsync(Stream pdfStream, bool raw = false, CancellationToken cancellationToken = default)
|
|
{
|
|
var endpoint = $"/api/pdf/qr-code/extract-swiss?raw={raw}";
|
|
|
|
var result = await SendMultipartAsync<SwissQrCodeExtractionResult>(
|
|
endpoint,
|
|
pdfStream,
|
|
"document.pdf",
|
|
cancellationToken);
|
|
|
|
return result ?? throw new InvalidOperationException("API returned null response");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<SwissQrCodeExtractionResult> ExtractSwissQrCodeAsync(byte[] pdfBytes, bool raw = false, CancellationToken cancellationToken = default)
|
|
{
|
|
var endpoint = $"/api/pdf/qr-code/extract-swiss?raw={raw}";
|
|
|
|
var request = new ExtractSwissQrCodeBase64Request
|
|
{
|
|
Base64Pdf = ToBase64(pdfBytes)
|
|
};
|
|
|
|
var result = await SendJsonAsync<ExtractSwissQrCodeBase64Request, SwissQrCodeExtractionResult>(
|
|
endpoint,
|
|
request,
|
|
cancellationToken);
|
|
|
|
return result ?? throw new InvalidOperationException("API returned null response");
|
|
}
|
|
}
|