Esempio n. 1
0
 /// <summary>
 /// Specifies method to be used.
 /// </summary>
 /// <param name="method">method to be executed</param>
 /// <returns>RestBuilder</returns>
 public virtual RestBuilder Method(Method method)
 {
     _confFn = FunUtils.Compose(_confFn, (request) =>
     {
         request.Method = method;
         return(request);
     });
     return(this);
 }
Esempio n. 2
0
 /// <summary>
 /// Adds query url params. Like: http://baseurl/endpoint?param=value
 /// </summary>
 /// <param name="param">param name</param>
 /// <param name="value">param value</param>
 /// <returns></returns>
 public virtual RestBuilder AddUrlQueryParam(string param, string value)
 {
     _confFn = FunUtils.Compose(_confFn, (request) =>
     {
         request.AddQueryParameter(param, value);
         return(request);
     });
     return(this);
 }
Esempio n. 3
0
 /// <summary>
 /// Here you can add specific header.
 /// </summary>
 /// <param name="key">header name</param>
 /// <param name="value">header value</param>
 /// <returns>RestBuilder</returns>
 public virtual RestBuilder AddHeader(string key, string value)
 {
     _confFn = FunUtils.Compose(_confFn, (request) =>
     {
         request.AddHeader(key, value);
         return(request);
     });
     return(this);
 }
Esempio n. 4
0
        /// <summary>
        /// Here you can add json data.
        /// </summary>
        /// <param name="data">data to post</param>
        /// <returns>RestBuilder</returns>
        public virtual RestBuilder Data(object data)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            _confFn = FunUtils.Compose(_confFn, (request) =>
            {
                request.AddJsonBody(data);
                return(request);
            });
            return(this);
        }
Esempio n. 5
0
        /// <summary>
        /// Specifies end point or url suffix. Like: http://baseurl/endpoint?param=value
        /// </summary>
        /// <param name="resource">endpoint or resource to be executed against</param>
        /// <returns>RestBuilder</returns>
        public virtual RestBuilder ToEndPoint(string resource)
        {
            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }

            _confFn = FunUtils.Compose(_confFn, (request) =>
            {
                request.Resource = resource;
                return(request);
            });
            return(this);
        }
Esempio n. 6
0
        /// <summary>
        /// Here you can specify request headers.
        /// </summary>
        /// <param name="headers">key-value pairs of headers</param>
        /// <returns></returns>
        public virtual RestBuilder AddHeaders(IDictionary <string, string> headers)
        {
            if (headers == null)
            {
                throw new ArgumentNullException(nameof(headers));
            }

            _confFn = FunUtils.Compose(_confFn, (request) =>
            {
                foreach (KeyValuePair <string, string> pair in headers)
                {
                    request.AddHeader(pair.Key, pair.Value);
                }
                return(request);
            });
            return(this);
        }
Esempio n. 7
0
        /// <summary>
        /// Specifies file to be uploaded as a result request.
        /// That may be a good idea to use Stream for this scenario, but it seems the is some internal issue
        /// RestSharp atm. See discussion here: https://github.com/restsharp/RestSharp/issues/742
        /// This approach with abs file path seems to be working.
        /// </summary>
        /// <param name="absFilePath">Specifies file absolute path</param>
        /// <param name="fileString"></param>
        /// <param name="fileNameString"></param>
        /// <param name="isMultiPart"></param>
        /// <returns>RestBuilder</returns>
        public virtual RestBuilder AddFile(string absFilePath,
                                           string fileString     = "file",
                                           string fileNameString = "filename",
                                           bool isMultiPart      = true)
        {
            if (absFilePath == null)
            {
                throw new ArgumentNullException(nameof(absFilePath));
            }

            _confFn = FunUtils.Compose(_confFn, (request) =>
            {
                string filename = Path.GetFileName(absFilePath);
                request.AlwaysMultipartFormData = isMultiPart;
                request.AddParameter(fileNameString, filename, ParameterType.GetOrPost);
                request.AddFile(fileString, File.ReadAllBytes(absFilePath), filename);
                return(request);
            });
            return(this);
        }