Inheritance: IRestClientBuilder
Beispiel #1
0
        public RestOperation Post()
        {
            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);
            var response = restClientBuilder.Build().Post();

            //to cache it we need to know where we  made the object so lets get its self link

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

            HttpRuntime.Cache.Insert(selfLink.Href, response, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0));

            if (HttpRuntime.Cache[parentLink.Href] != null)
            {
                HttpRuntime.Cache.Remove(parentLink.Href);
            }

            return response;
        }
Beispiel #2
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;
        }
Beispiel #3
0
        public RestOperation Get()
        {
            if (HttpRuntime.Cache[_pathManager.FindRootPath()] != null)
            {
                return (RestOperation)HttpRuntime.Cache[_pathManager.FindRootPath()];
            }

            var restClientBuilder = new RestClientBuilder()
                .WithUri(_pathManager.CreatePath())
                .WithOAuth2Token(_token.GetAccessToken())
                .WithAcceptHeader(_acceptHeader)
                .Build();
            var response = restClientBuilder.Get();

            if (!String.IsNullOrEmpty(response.GetResponseHeader(HttpResponseHeader.Location)))
            {
                var redirect = (response.GetResponseHeader(HttpResponseHeader.Location));
                var redirectFinder = new ResourceFinder(redirect, _token, _acceptHeader);
                var redirectResponse =  redirectFinder.Get();
                HttpRuntime.Cache.Insert(_pathManager.FindRootPath(), redirectResponse, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0));
                return redirectResponse;
            }

            HttpRuntime.Cache.Insert(_pathManager.FindRootPath(), response, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0));
            return response;
        }
Beispiel #4
0
        public RestOperation Delete()
        {
            if (HttpRuntime.Cache[_pathManager.FindRootPath()] != null)
            {
                HttpRuntime.Cache.Remove(_pathManager.FindRootPath());
            }

            //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);
            }

            var restClientBuilder = new RestClientBuilder()
                .WithUri(_pathManager.CreatePath())
                .WithOAuth2Token(_token.GetAccessToken())
                .WithAcceptHeader(_acceptHeader);
            var response = restClientBuilder.Build().Delete();

            return response;
        }
Beispiel #5
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())
                .WithCustomHeaders(customHeaders)
                .WithAcceptHeader(_acceptHeader);
            var response = restClientBuilder.Build().Put();

            HttpRuntime.Cache.Insert(_pathManager.FindRootPath(), response, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0));
            return response;
        }
Beispiel #6
0
        public RootObject GetToken(TokenRequest request)
        {
            var client = new RestClientBuilder()
                .WithAcceptHeader("application/json")
                .WithContentType("application/x-www-form-urlencoded")
                .WithBody(request.ToForm())
                .WithUri(Settings.Default.HuddleAuthServer + Settings.Default.HuddleTokenEndPoint)
                .Build().Post();

            if (client.StatusCode == HttpStatusCode.BadRequest)
            {

            }

            var token = new RootObject();
            token.access_token = client.Result.access_token;
            token.expires_in = DateTime.Now.AddSeconds(client.Result.expires_in);
            token.refresh_token = client.Result.refresh_token;

            return token;
        }
Beispiel #7
0
        public RestOperation SendMutiPartRequest()
        {
            string boundary = Guid.NewGuid().ToString();
            var data = new GetMutiPartData(_fileToUpload);

            var restClientBuilder = new RestClientBuilder()
                .WithUri(_pathManager.CreatePath())
                .WithContentType("multipart/form-data; boundary=" + boundary)
                .WithOAuth2Token(_token.GetAccessToken())
                .WithBody(data.ConstructMutiPartData(boundary))
                .WithAcceptHeader(_acceptHeader);
            var response = restClientBuilder.Build().Put();

            if (HttpRuntime.Cache[_pathManager.FindRootPath()] != null)
            {
                HttpRuntime.Cache.Remove(_pathManager.FindRootPath());
            }

            HttpRuntime.Cache.Insert(_pathManager.FindRootPath(), response, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 0));

            return response;
        }
        private Folder GetFolderFromPath(string path)
        {
            var resource = ExtractResourceFromPath(path);

            var restClientBuilder = new RestClientBuilder()
                .WithUri(GetFolderUri(resource))
                .WithOAuth2Token(_user.Token)
                .WithAcceptHeader(ACCEPT_HEADER );

            var response = restClientBuilder.Build().Get();

            return new FolderFactory(response);
        }