private static async Task <OutputRecord.OutputRecordData> FetchEntityMetadata(string entityName) { var uriSearch = BingSearchApiEndpoint + "?q=" + entityName + "&mkt=en-us&count=1&answerCount=1&promote=images%2Cvideos"; var result = new OutputRecord.OutputRecordData(); var client = new HttpClient(); var request = new HttpRequestMessage(); request.Method = HttpMethod.Get; request.Headers.Add("Ocp-Apim-Subscription-Key", Key); request.RequestUri = new Uri(uriSearch); HttpResponseMessage responseSearch = await client.SendAsync(request); string responseSearchBody = await responseSearch?.Content?.ReadAsStringAsync(); BingSearchEntity bingSearchEntity = JsonConvert.DeserializeObject <BingSearchEntity>(responseSearchBody); if (bingSearchEntity != null) { return(AddTopEntityData(entityName, bingSearchEntity)); } return(result); }
private static OutputRecord.OutputRecordData AddTopEntityData(string entityName, BingSearchEntity bingSearchEntity) { if (bingSearchEntity != null && bingSearchEntity.WebPages != null) { if (bingSearchEntity.Videos != null && bingSearchEntity.Videos?.value.Count > 2) { bingSearchEntity.Videos.Name = entityName; bingSearchEntity.Videos.value.RemoveRange(2, bingSearchEntity.Videos.value.Count - 2); } if (bingSearchEntity.WebPages?.value[0].deepLinks?.Count > 2) { bingSearchEntity.WebPages.value[0].deepLinks.RemoveRange(2, bingSearchEntity.WebPages.value[0].deepLinks.Count - 2); } bingSearchEntity.WebPages.Name = entityName; return(new OutputRecord.OutputRecordData() { Videos = bingSearchEntity.Videos, WebPages = bingSearchEntity.WebPages }); } return(new OutputRecord.OutputRecordData()); }