/// <summary>
        /// Executes a request initialized with parameters.
        /// </summary>
        /// <param name="restClientParameters">Parameters.</param>
        /// <returns>Rest response.</returns>
        public IRestResponse Execute(RestClientParameters restClientParameters)
        {
            var client  = GetRestClient(restClientParameters);
            var request = GetRestRequest(restClientParameters);

            return(Execute(client, request));
        }
 private void SetRequestBody(IRestRequest request, RestClientParameters restClientParameters)
 {
     if (restClientParameters.RequestBody != null)
     {
         request.AddBody(restClientParameters.RequestBody);
     }
 }
        /// <summary>
        /// Returns an initialized client.
        /// </summary>
        /// <param name="restClientParameters">Parameters.</param>
        /// <returns>Rest client.</returns>
        public IRestClient GetRestClient(RestClientParameters restClientParameters)
        {
            var client = new RestClient(restClientParameters.BaseUrl)
            {
                Authenticator = GetAuthenticator()
            };

            return(client);
        }
        /// <summary>
        /// Returns an initialized request.
        /// </summary>
        /// <param name="restClientParameters">Parameters.</param>
        /// <returns>Rest request.</returns>
        public IRestRequest GetRestRequest(RestClientParameters restClientParameters)
        {
            var request = new RestRequest(restClientParameters.RequestUrl)
            {
                Method        = GetRequestMethod(restClientParameters),
                RequestFormat = GetDataFormat(restClientParameters),
                DateFormat    = restClientParameters.RequestDateFormat,
            };

            SetRequestParameters(request, restClientParameters.RequestHeaders, ParameterType.HttpHeader);
            SetRequestParameters(request, restClientParameters.RequestUrlSegments, ParameterType.UrlSegment);
            SetRequestParameters(request, restClientParameters.RequestQueryParameters, ParameterType.QueryString);
            SetRequestBody(request, restClientParameters);
            return(request);
        }
        private Method GetRequestMethod(RestClientParameters restClientParameters)
        {
            switch (restClientParameters.RequestMethod)
            {
            case RequestMethod.Get:
                return(Method.GET);

            case RequestMethod.Post:
                return(Method.POST);

            case RequestMethod.Put:
                return(Method.PUT);

            case RequestMethod.Patch:
                return(Method.PATCH);

            case RequestMethod.Delete:
                return(Method.DELETE);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 private DataFormat GetDataFormat(RestClientParameters restClientParameters)
 {
     return(restClientParameters.RequestFormat == RequestFormat.Xml
         ? DataFormat.Xml
         : DataFormat.Json);
 }