public async Task <DataTransferObjects.OrderProductResponseItem> FetchDCP(ApiManager apiManager, string dunsNumber) { apiManager.Client.DefaultRequestHeaders.Clear(); apiManager.Client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); apiManager.Client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", apiManager.Token); try { // Task<HttpResponseMessage> response = client.GetAsync(new Uri(apiManager.ProductUrl)); HttpResponseMessage response = new HttpResponseMessage(); response = await apiManager.Client.GetAsync(new Uri("https://direct.dnb.com/V5.3/organizations/804735132/products/DCP_PREM")); if (response.IsSuccessStatusCode) { string data = await response.Content.ReadAsStringAsync(); var serializer = new JavaScriptSerializer(); var result = serializer.DeserializeObject(data); string json = JsonConvert.SerializeObject(result); JavaScriptSerializer jss = new JavaScriptSerializer(); jss.RegisterConverters(new JavaScriptConverter[] { new DynamicJsonConverter() }); dynamic dcp = jss.Deserialize(json, typeof(object)) as dynamic; DataTransferObjects.OrderProductResponseItem orderProductResponseItem = new DataTransferObjects.OrderProductResponseItem(); orderProductResponseItem.ServiceTransactionID = dcp.OrderProductResponse.TransactionDetail.ServiceTransactionID; orderProductResponseItem.TransactionTimestamp = dcp.OrderProductResponse.TransactionDetail.TransactionTimestamp; orderProductResponseItem.SeverityText = dcp.OrderProductResponse.TransactionResult.SeverityText; orderProductResponseItem.ResultID = dcp.OrderProductResponse.TransactionResult.ResultID; orderProductResponseItem.ResultText = dcp.OrderProductResponse.TransactionResult.ResultText; orderProductResponseItem.DUNSNumber = dcp.OrderProductResponse.OrderProductResponseDetail.InquiryDetail.DUNSNumber; orderProductResponseItem.CountryISOAlpha2Code = dcp.OrderProductResponse.OrderProductResponseDetail.InquiryDetail.CountryISOAlpha2Code; orderProductResponseItem.DNBProductID = dcp.OrderProductResponse.OrderProductResponseDetail.Product.DNBProductID; orderProductResponseItem.OrganizationSummaryText = dcp.OrderProductResponse.OrderProductResponseDetail.Product.Organization.SubjectHeader.OrganizationSummaryText; orderProductResponseItem.LastUpdateDate = dcp.OrderProductResponse.OrderProductResponseDetail.Product.Organization.SubjectHeader.LastUpdateDate; return(orderProductResponseItem); } else { return(null); } } catch (Exception e) { throw e; } }
public DnbIntegrationService(IDnbRepository repository, ApiManager apiManager) { _repository = repository; _apiManager = apiManager; }