/// <summary>
        /// Performs POST request with body to specified path
        /// </summary>
        /// <typeparam name="T">The type of object to create and populate with the returned data.</typeparam>
        /// <param name="path">relative API request path</param>
        /// <param name="payload">object to send</param>
        /// <param name="queryParams">query parameters</param>
        /// <returns>mapped object</returns>
        /// <exception cref="EzTextingApiException">         in case HTTP response code is something different from codes listed above.</exception>
        /// <exception cref="EzTextingClientException">      in case error has occurred in client.</exception>
        public EzTextingResponse <T> Post <T>(string path, EzTextingModel payload = null,
                                              IEnumerable <KeyValuePair <string, object> > queryParams = null) where T : new()
        {
            Logger.Debug("POST request to {0} params: {1} entity: \n{2}", path, queryParams, payload);
            var restRequest = CreateRestRequest(path, Method.POST, payload, queryParams);

            return(DoRequest <EzTextingResponse <T> >(restRequest));
        }
        /// <summary>
        /// Performs GET request to specified path
        /// </summary>
        /// <typeparam name="T">The type of object to create and populate with the returned data.</typeparam>
        /// <param name="path">relative API request path</param>
        /// <param name="request">API request object</param>
        /// <param name="queryParams">query parameters</param>
        /// <returns>mapped object</returns>
        /// <exception cref="EzTextingApiException">         in case HTTP response code is something different from codes listed above.</exception>
        /// <exception cref="EzTextingClientException">      in case error has occurred in client.</exception>
        public EzTextingResponse <T> Get <T>(string path, EzTextingModel request = null,
                                             IEnumerable <KeyValuePair <string, object> > queryParams = null) where T : new()
        {
            Logger.Debug("GET request to {0} with params: {1}", path, queryParams);
            var restRequest = CreateRestRequest(path, Method.GET, request, queryParams);

            return(DoRequest <EzTextingResponse <T> >(restRequest));
        }
        private IRestRequest CreateRestRequest(string path, Method method, EzTextingModel model         = null,
                                               IEnumerable <KeyValuePair <string, object> > queryParams = null)
        {
            var request = new RestRequest
            {
                Method         = method,
                RequestFormat  = DataFormat.Json,
                JsonSerializer = _jsonSerializer
            };
            var authString       = _authentication.AsParamString();
            var requestPath      = new StringBuilder(path);
            var modelQueryParams = ClientUtils.BuildQueryParams(model);
            var extraQueryParams = new StringBuilder();

            if (queryParams != null)
            {
                foreach (var param in queryParams)
                {
                    extraQueryParams
                    .Append(param.Key)
                    .Append("=")
                    .Append(param.Value.ToString().UrlEncode())
                    .Append('&');
                }
            }

            if (method == Method.GET || method == Method.DELETE)
            {
                requestPath.Append('&').Append(authString);
                CombineParameters(requestPath, modelQueryParams.ToString(), extraQueryParams.ToString());
            }
            else if (method == Method.POST)
            {
                var postBody = new StringBuilder(authString);
                CombineParameters(postBody, modelQueryParams.ToString(), extraQueryParams.ToString());
                request.AddParameter(ClientConstants.FormEncodedContentType, postBody.ToString(),
                                     ClientConstants.FormEncodedContentType, ParameterType.RequestBody);
            }
            else
            {
                throw new EzTextingClientException("HTTP method " + method + " isn't supported.");
            }
            request.AddHeader("Accept", ClientConstants.JsonContentType);
            request.Resource = requestPath.ToString();

            return(request);
        }