DynamicRest.Fluent.RestClientBuilder.Build C# (CSharp) Method

Build() public method

public Build ( ) : dynamic
return dynamic
        public dynamic Build()
        {
            _timeout = _timeout == 0 ? 100000 : _timeout; // default timeout i the CLR is 100s

            _contentType = _contentType ?? "application/xml";
            _acceptType = _acceptType ?? "application/xml";
            if (_noAcceptHeader){
                _acceptType = string.Empty;
            }

            if (_requestBuilder == null) {
                _requestBuilder = new HttpVerbRequestBuilder(new RequestFactory());
            }

            if (_responseProcessor == null) {
                var serviceType = _acceptType.Contains("xml") ? RestService.Xml : _acceptType.Contains("json") ? RestService.Json : _acceptType.EndsWith("plain") ? RestService.Text: RestService.Binary;
                if (_noAcceptHeader){
                    serviceType = RestService.Xml;
                }

                this._responseProcessor = new ResponseProcessor(new StandardResultBuilder(serviceType));
            }

            if (_proxy != null)
            {
                _requestBuilder.Proxy = _proxy;
            }

            _requestBuilder.Uri = _uri;
            _requestBuilder.ContentType = _contentType;
            _requestBuilder.AcceptHeader = _acceptType;
            _requestBuilder.Body = _body;
            _requestBuilder.AllowAutoRedirect = _autoRedirect;
            _requestBuilder.UserAgent = _userAgent;
            _requestBuilder.Timeout = _timeout;
            if (!string.IsNullOrEmpty(_token))
            {
                _requestBuilder.SetOAuth2AuthorizationHeader(_token);
            }
            if(!string.IsNullOrEmpty(_acceptEncodingType))
            {
                _requestBuilder.AddHeader(HttpRequestHeader.AcceptEncoding, _acceptEncodingType);
            }

            if(_ifModifiedSince.HasValue)
            {

                _requestBuilder.IfModifiedSince(_ifModifiedSince.Value);
            }

            foreach (var header in _headers)
            {
                _requestBuilder.AddHeader(header.Key, header.Value);
            }

            foreach (var header in _customHeaders)
            {
                _requestBuilder.AddCustomHeader(header.Key, header.Value);
            }

            return new RestClient(_requestBuilder, _responseProcessor);
        }

Usage Example

Exemplo n.º 1
0
        public RestOperation Put()
        {
            if (HttpRuntime.Cache[_pathManager.FindRootPath()] != null)
               {
                HttpRuntime.Cache.Remove(_pathManager.FindRootPath());
               }

            var restClientBuilder = new RestClientBuilder()
                .WithUri(_pathManager.CreatePath())
                .WithOAuth2Token(_token.GetAccessToken())
                .WithBody(_body)
                .WithAcceptHeader(_acceptHeader)
                .WithContentType("application/vnd.huddle.data+json");
            var response = restClientBuilder.Build().Put();

            //this is fine and dandy but then we have to update any cache that holds info about this i.e thhe parent folder cache
            var restClientBuilderParent = new RestClientBuilder()
                .WithUri(_pathManager.FindRootPath())
                .WithOAuth2Token(_token.GetAccessToken())
                .WithAcceptHeader(_acceptHeader);

               var parentResponse = restClientBuilderParent.Build().get();

               IEnumerable<Link> linkAsArray = LinkBuilder.Build(parentResponse.Result.link);
               var parentLink = linkAsArray.Single(l => l.Rel == "parent");

               if (HttpRuntime.Cache[parentLink.Href] != null)
               {
               HttpRuntime.Cache.Remove(parentLink.Href);
               HttpRuntime.Cache.Insert(parentLink.Href, parentResponse, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0));
               }

            return response;
        }
All Usage Examples Of DynamicRest.Fluent.RestClientBuilder::Build