Пример #1
0
        public static async Task <Suggestions> callAutosuggestSearchAPI(BingAutosuggestQuery query)
        {
            var url = $"{ApiEndpoints.AUTOSUGGEST_URL}{query.ToQueryString()}";

            using (var bingClient = new BingHttpClient(query.SearchKey))
            {
                var httpResponseMessage = await bingClient.GetAsync(url);

                if (httpResponseMessage.IsSuccessStatusCode)
                {
                    var responseContent = httpResponseMessage.Content.ReadAsStringAsync().Result;
                    return(JsonConvert.DeserializeObject <Suggestions>(responseContent));
                }
                else
                {
                    throw new InvalidOperationException("An error occurred fetching the results from the autosuggest service");
                }
            }
        }
Пример #2
0
        public static async Task <BingVideoSearchResponse> CallVideoSearchAPI(BingVideoSearchQuery query)
        {
            var url = $"{ApiEndpoints.VIDEO_SEARCH_URL}{query.ToQueryString()}";

            using (var bingClient = new BingHttpClient(query.SearchKey))
            {
                var httpResponseMessage = await bingClient.GetAsync(url);

                if (httpResponseMessage.IsSuccessStatusCode)
                {
                    var responseContent = httpResponseMessage.Content.ReadAsStringAsync().Result;
                    return(JsonConvert.DeserializeObject <BingVideoSearchResponse>(responseContent));
                }
                else
                {
                    throw new InvalidOperationException("An error occurred fetching the results from the video service");
                }
            }
        }