Exemplo n.º 1
0
        private string ProcessPostEndpoint(string endpoint, RestPostOptions options)
        {
            var processedEndpoint = endpoint;

            if (options.PathParameters.HasKeys())
                processedEndpoint = ReplaceTokens(endpoint, options.PathParameters);
            if (options.QueryStringParameters.HasKeys())
                processedEndpoint = BuildQueryString(processedEndpoint, options.QueryStringParameters);

            return processedEndpoint;
        }
Exemplo n.º 2
0
        public async Task can_do_post_async_single_string_request()
        {
            var msg = "Hello World at " + DateTime.UtcNow.ToString();

            var endpoint = "/users/{username}/statuses.json";
            var options = new RestPostOptions();
            options.PathParameters.Add("username", "admin");
            options.PostParameters.Add("MessageBody", msg);
            var status = await Host.PostToStringAsync(2, endpoint, true, options);

            Assert.IsFalse(string.IsNullOrWhiteSpace(status));
            Assert.IsTrue(status.Contains(msg));
        }
Exemplo n.º 3
0
        public async Task can_do_post_async_single_dynamic_request()
        {
            var msg = "Hello World at " + DateTime.UtcNow.ToString();

            var endpoint = "/users/{username}/statuses.json";
            var options = new RestPostOptions();
            options.PathParameters.Add("username","admin");
            options.PostParameters.Add("MessageBody",msg);
            dynamic status = await Host.PostToDynamicAsync(2, endpoint, true, options);

            Assert.IsNotNull(status.StatusMessage);
            Assert.AreEqual(msg,status.StatusMessage.Body);
        }
Exemplo n.º 4
0
        public  void can_do_post_async_single_stream_request_sync()
        {
            var msg = "Hello World at " + DateTime.UtcNow.ToString();

            var endpoint = "/users/{username}/statuses.json";
            var options = new RestPostOptions();
            options.PathParameters.Add("username", "admin");
            options.PostParameters.Add("MessageBody", msg);
            using (var status =  Host.PostToStream(2, endpoint, true, options))
            {
                Assert.IsNotNull(status);
                using (var reader = new StreamReader(status))
                {
                    var data = reader.ReadToEnd();
                    Assert.IsTrue(data.Contains(msg));
                }
            }

        }
Exemplo n.º 5
0
        public Stream PostEndpointStream(RestHost host, int version, string endpoint, bool enableImpersonation = true, RestPostOptions options = null)
        {
            if (options == null)
                options = new RestPostOptions();
            var processedEndpoint = ProcessPostEndpoint(endpoint, options);

            string postData = options.PostParameters.MakeQuerystring(true);
            return _proxy.Post(host, MakeEndpointUrl(host, version, processedEndpoint), postData,
                (req) => AdjustPostRequest(host, req, enableImpersonation, options));
        }
Exemplo n.º 6
0
        public async Task<Stream> PostEndpointStream(RestHost host, int version, string endpoint, Stream postStream, bool enableImpersonation, Action<WebResponse> responseAction, RestPostOptions options = null)
        {
            //TODO: Review this for refactor, is it necessary or can it be collpased
            return
                await
                    _proxy.PostEndpointStream(host, MakeEndpointUrl(host, version, endpoint), postStream,
                        (request) => AdjustPostRequest(host, request, enableImpersonation, options), responseAction);

        }
Exemplo n.º 7
0
        public async Task<string> PostEndpointStringAsync(RestHost host, int version, string endpoint, bool enableImpersonation = true, RestPostOptions options = null)
        {
            if (options == null)
                options = new RestPostOptions();
            var processedEndpoint = ProcessPostEndpoint(endpoint, options);

            string postData = options.PostParameters.MakeQuerystring(true);

            var stream = await _proxy.PostAsync(host, MakeEndpointUrl(host, version, processedEndpoint), postData, (request) => AdjustPostRequest(host, request, true, options));
            return await ReadResponseStreamAsync(stream);
        }
Exemplo n.º 8
0
        public async Task<XElement> PostEndpointXmlAsync(RestHost host, int version, string endpoint, HttpPostedFileBase file = null, bool enableImpersonation = true, RestPostOptions options = null)
        {

            if (options == null)
                options = new RestPostOptions();

            var processedEndpoint = ProcessPostEndpoint(endpoint, options);


            string postData = options.PostParameters.MakeQuerystring(true);
            return XElement.Parse(await ReadResponseStreamAsync(await _proxy.PostAsync(host, MakeEndpointUrl(host, version, processedEndpoint), postData, (request) => AdjustPostRequest(host, request, true, options))));
        }
Exemplo n.º 9
0
 private void AdjustPostRequest(RestHost host, HttpWebRequest request, bool enableImpersonation, RestPostOptions options)
 {
     AdjustRequestBase(host, request, enableImpersonation);
     if (options != null && options.AdditionalHeaders != null)
         SetAdditionalHeaders(request, options.AdditionalHeaders);
 }
Exemplo n.º 10
0
        /// <summary>
        /// REST POST Request (Async)
        /// </summary>
        /// <param name="version">The REST Api version</param>
        /// <param name="endpoint">The Url without aspi.ashx and ther version</param>
        /// <param name="enableImpersonation">Use the locally authenticated user versus the default</param>
        /// <param name="options">Additional options for this request type.</param>
        /// <returns>Stream</returns>
        public  Task<Stream> PostToStreamAsync(int version, string endpoint, bool enableImpersonation = true, RestPostOptions options = null)
        {
            return  Rest.PostEndpointStreamAsync(this, version, endpoint, enableImpersonation, options);

        }
Exemplo n.º 11
0
 /// <summary>
 /// POST GET Request for JSON
 /// </summary>
 /// <param name="version">The REST Api version</param>
 /// <param name="endpoint">The Url without aspi.ashx and ther version</param>
 /// <param name="enableImpersonation">Use the locally authenticated user versus the default</param>
 /// <param name="options">Additional options for this request type.</param>
 /// <returns>dynamic</returns>
 public dynamic PostToDynamic(int version, string endpoint, bool enableImpersonation = true, RestPostOptions options = null)
 {
     var json =  Rest.PostEndpointString(this, version, endpoint, enableImpersonation, options);
     return json != null ? JsonConvert.Deserialize(json) : null;
 }
Exemplo n.º 12
0
 /// <summary>
 /// REST POST Request for Xml
 /// </summary>
 /// <param name="version">The REST Api version</param>
 /// <param name="endpoint">The Url without aspi.ashx and ther version</param>
 /// <param name="enableImpersonation">Use the locally authenticated user versus the default</param>
 /// <param name="options">Additional options for this request type.</param>
 /// <returns>XElement</returns>
 ///
 public XElement PostToXml(int version, string endpoint, HttpPostedFileBase file, bool enableImpersonation, RestPostOptions options = null)
 {
     return Rest.PostEndpointXml( this, version, endpoint, file, enableImpersonation, options);
 }