public async Task <CompaniesHouseClientResponse <DocumentMetadata> > GetDocumentMetadataAsync(string documentId, CancellationToken caneCancellationToken = default)
        {
            var requestUri = _documentUriBuilder.Build(documentId);
            var response   = await _httpClient.GetAsync(requestUri, caneCancellationToken).ConfigureAwait(false);

            if (response.StatusCode != System.Net.HttpStatusCode.NotFound)
            {
                response.EnsureSuccessStatusCode();
            }

            var result = response.IsSuccessStatusCode
                ? await response.Content.ReadAsJsonAsync <DocumentMetadata>().ConfigureAwait(false)
                : null;

            return(new CompaniesHouseClientResponse <DocumentMetadata>(result));
        }
Exemplo n.º 2
0
        public async Task <CompaniesHouseClientResponse <DocumentDownload> > DownloadDocumentAsync(string documentId, CancellationToken cancellationToken = default)
        {
            var requestUri = _documentUriBuilder.Build(documentId);
            var response   = await _httpClient.GetAsync(requestUri, cancellationToken).ConfigureAwait(false);

            if (response.StatusCode != HttpStatusCode.NotFound)
            {
                response.EnsureSuccessStatusCode();
            }

            var data = response.IsSuccessStatusCode
                ? new DocumentDownload
            {
                Content       = await response.Content.ReadAsStreamAsync(),
                ContentLength = response.Content.Headers.ContentLength,
                ContentType   = response.Content.Headers.ContentType.MediaType
            }
                : null;

            return(new CompaniesHouseClientResponse <DocumentDownload>(data));
        }