Example #1
0
        private static RestClient CreateRestClient(IRestRequest request)
        {
            var restClient = new RestClient(request.Url);

            if (request.UseNtlm)
            {
                restClient.Authenticator = new NtlmAuthenticator();
            }

            return(restClient);
        }
Example #2
0
        public IRestResponse Execute(IRestRequest request)
        {
            var restClient = CreateRestClient(request);

            var restSharpRestRequest = ConvertRestRequest(request);

            var restSharpRestResponse = restClient.Execute(restSharpRestRequest);

            var restResponse = ConvertRestResponse(restSharpRestResponse);

            return(restResponse);
        }
Example #3
0
        public async Task <IRestResponse> ExecuteAsync(IRestRequest request,
                                                       CancellationToken cancellationToken = default(CancellationToken))
        {
            var restClient = CreateRestClient(request);

            var restSharpRestRequest = ConvertRestRequest(request);

            var restSharpRestResponse = await restClient.ExecuteTaskAsync(restSharpRestRequest, cancellationToken);

            var restResponse = ConvertRestResponse(restSharpRestResponse);

            return(restResponse);
        }
Example #4
0
        private static RestRequest ConvertRestRequest(IRestRequest request)
        {
            var method = ConvertMethod(request.HttpMethod);

            var restSharpRestRequest = new RestRequest
            {
                Method   = method,
                Resource = string.Empty
            };

            restSharpRestRequest.AddParameter("application/json", request.RequestBody, ParameterType.RequestBody);

            foreach (var requestHeader in request.Headers)
            {
                restSharpRestRequest.AddHeader(requestHeader.Name, requestHeader.Value);
            }

            return(restSharpRestRequest);
        }