Ejemplo n.º 1
0
        public async Task <IList <GetHookData.Hook> > GetHooks(string folder, string hub)
        {
            string folderId = HookInputData.ExtractFolderIdFromHref(folder);

            if (string.IsNullOrWhiteSpace(folderId))
            {
                return(null);
            }

            string hubId = HookInputData.ExtractHubIdFromHref(hub);

            if (string.IsNullOrWhiteSpace(hubId))
            {
                return(null);
            }

            Credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);

            if (Credentials == null)
            {
                return(null);
            }

            DMWebhook webhooksApi          = new DMWebhook(Credentials.TokenInternal, CallbackUrl);
            IList <GetHookData.Hook> hooks = await webhooksApi.Hooks(Event.VersionAdded, folderId, await webhooksApi.GetHubRegion(hubId));

            return(hooks);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreateHook([FromForm] HookInputData input)
        {
            string folderId = ExtractFolderIdFromHref(input.href);

            if (string.IsNullOrWhiteSpace(folderId))
            {
                return(BadRequest());
            }

            string projectId = ExtractProjectIdFromHref(input.href);

            if (string.IsNullOrWhiteSpace(projectId))
            {
                return(BadRequest());
            }

            Credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);

            if (Credentials == null)
            {
                return(Unauthorized());
            }

            DMWebhook webhooksApi = new DMWebhook(Credentials.TokenInternal, CallbackUrl);
            await webhooksApi.CreateHook(Event.VersionAdded, projectId, folderId);

            return(Ok());
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> DeleteHook(HookInputData input)
        {
            if (string.IsNullOrWhiteSpace(input.FolderId))
            {
                return(BadRequest());
            }
            if (string.IsNullOrWhiteSpace(input.ProjectId))
            {
                return(BadRequest());
            }
            if (string.IsNullOrWhiteSpace(input.HubId))
            {
                return(BadRequest());
            }

            Credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies);

            if (Credentials == null)
            {
                return(Unauthorized());
            }

            DMWebhook webhooksApi = new DMWebhook(Credentials.TokenInternal, CallbackUrl);
            await webhooksApi.DeleteHook(Event.VersionAdded, input.FolderId, await webhooksApi.GetHubRegion(input.HubId));

            return(Ok());
        }