Example #1
0
        public GoogleApiResponse Search(string searchValue)
        {
            var request = new RestRequest($"https://www.googleapis.com/customsearch/v1", Method.GET);

            request.AddQueryParameter("key", _configuration["ApiKeys:GoogleApiKey"]);
            request.AddQueryParameter("cx", _configuration["ApiKeys:GoogleCx"]);
            request.AddQueryParameter("q", searchValue);

            var response = Execute <GoogleApiResponse>(request);
            var result   = new GoogleApiResponse();

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                result = response.Data;
            }
            else
            {
                _logger.LogRequestError(request, response);
            }

            return(result);
        }
Example #2
0
        public BingApiResponse Search(string searchValue)
        {
            var         url     = $"https://jamesbingendpoint.cognitiveservices.azure.com/bing/v7.0/search";
            RestRequest request = new RestRequest(url, Method.GET);

            request.AddHeader("Ocp-Apim-Subscription-Key", _configuration["ApiKeys:BingOcpApimSubscriptionKey"]);
            request.AddQueryParameter("q", searchValue);

            var response = Execute <BingApiResponse>(request);
            var result   = new BingApiResponse();

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                result = response.Data;
            }
            else
            {
                _logger.LogRequestError(request, response);
            }

            return(result);
        }