コード例 #1
0
        public async Task <CompaniesHouseClientResponse <CompanyProfile> > GetCompanyProfileAsync(string companyNumber, CancellationToken cancellationToken = default(CancellationToken))
        {
            var requestUri = _companyProfileUriBuilder.Build(companyNumber);

            var response = await _httpClient.GetAsync(requestUri, cancellationToken).ConfigureAwait(false);

            // Return a null profile on 404s, but raise exception for all other error codes
            if (response.StatusCode != System.Net.HttpStatusCode.NotFound)
            {
                response.EnsureSuccessStatusCode();
            }

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

            return(new CompaniesHouseClientResponse <CompanyProfile>(result));
        }