From 333c02b33f281701aa5db1293ccb80d29bd3ead2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Z=C3=BCbeyde=20Civelek?= Date: Tue, 3 Dec 2024 15:54:18 +0100 Subject: [PATCH] Add Bruno Collection for REST API's --- ...Collection - CDS Videos Publish Video.json | 306 ++++++++++++++++++ README.rst | 186 ++++++++--- 2 files changed, 447 insertions(+), 45 deletions(-) create mode 100644 Bruno Collection - CDS Videos Publish Video.json diff --git a/Bruno Collection - CDS Videos Publish Video.json b/Bruno Collection - CDS Videos Publish Video.json new file mode 100644 index 000000000..f49531916 --- /dev/null +++ b/Bruno Collection - CDS Videos Publish Video.json @@ -0,0 +1,306 @@ +{ + "name": "CDS Videos Publish Video", + "version": "1", + "items": [ + { + "type": "http", + "name": "Optional Change access of the video", + "seq": 8, + "request": { + "url": "{{baseURl}}/api/deposits/video/{{video_id}}", + "method": "PUT", + "headers": [ + { + "name": "content-type", + "value": "application/vnd.video.partial+json", + "enabled": true + } + ], + "params": [], + "body": { + "mode": "json", + "json": "{\n \"_access\": {\n \"update\": [\n \"admin@test.ch\",\n \"atlas-outreach-cds-video@cern.ch\" //Update the access according to category\n ],\n // If you want to restrict the video, update access read\n \"read\": [\n \"atlas-readaccess-active-members@cern.ch\"\n ]\n\n }\n}\n\n", + "formUrlEncoded": [], + "multipartForm": [] + }, + "script": {}, + "vars": {}, + "assertions": [], + "tests": "", + "auth": { + "mode": "inherit" + } + } + }, + { + "type": "http", + "name": "Get project to check the flow is finished", + "seq": 5, + "request": { + "url": "{{baseURl}}/api/deposits/project/{{project_id}}", + "method": "GET", + "headers": [ + { + "name": "content-type", + "value": "application/vnd.project.partial+json", + "enabled": true + } + ], + "params": [], + "body": { + "mode": "json", + "json": "", + "formUrlEncoded": [], + "multipartForm": [] + }, + "script": {}, + "vars": {}, + "assertions": [], + "tests": "", + "auth": { + "mode": "inherit" + } + } + }, + { + "type": "http", + "name": "Step 1- Create a project", + "seq": 1, + "request": { + "url": "{{baseURl}}/api/deposits/project/", + "method": "POST", + "headers": [ + { + "name": "content-type", + "value": "application/vnd.project.partial+json", + "enabled": true + } + ], + "params": [], + "body": { + "mode": "json", + "json": "{\n \"$schema\": \"https://localhost:5000/schemas/deposits/records/videos/project/project-v1.0.0.json\",\n \"_access\": {\n \"update\": [\n \"admin@test.ch\",\n \"atlas-outreach-cds-video@cern.ch\"\n ],\n \"read\": [ // If you want to restrict the project, add access read\n \"atlas-readaccess-active-members@cern.ch\"\n ]\n },\n // Add category and type\n \"category\": \"ATLAS\",\n \"type\": \"VIDEO\"\n}", + "formUrlEncoded": [], + "multipartForm": [] + }, + "script": { + "res": "let data = res.body ;\nbru.setEnvVar(\"project_id\", data.id);" + }, + "vars": {}, + "assertions": [], + "tests": "", + "auth": { + "mode": "inherit" + } + } + }, + { + "type": "http", + "name": "Step 2- Create a video", + "seq": 2, + "request": { + "url": "{{baseURl}}/api/deposits/video/", + "method": "POST", + "headers": [ + { + "name": "content-type", + "value": "application/vnd.video.partial+json", + "enabled": true + } + ], + "params": [], + "body": { + "mode": "json", + "json": "{\n \"$schema\":\"https://localhost:5000/schemas/deposits/records/videos/video/video-v1.0.0.json\",\n \"_project_id\":\"{{project_id}}\",\n \"title\":\n {\n \"title\":\"217490_medium\"\n },\n\n \"vr\": false,\n \"featured\": false,\n \"language\": \"en\",\n \"contributors\": [\n {\n \"name\": \"Civelek, Zubeyde\",\n \"ids\": [\n {\n \"value\": \"868056\",\n \"source\": \"cern\"\n }\n ],\n \"email\": \"zubeyde.civelek@cern.ch\",\n \"role\": \"Co-Producer\"\n }\n ],\n \"description\": \"Description\",\n \"date\": \"2024-11-12\"\n}", + "formUrlEncoded": [], + "multipartForm": [] + }, + "script": { + "res": "let data = res.body ;\nbru.setEnvVar(\"video_id\", data.id);\nbru.setEnvVar(\"bucket_id\", data.metadata._buckets.deposit);\n" + }, + "vars": {}, + "assertions": [], + "tests": "", + "auth": { + "mode": "inherit" + } + } + }, + { + "type": "http", + "name": "Step 3- Upload the video", + "seq": 3, + "request": { + "url": "{{baseURl}}/api/files/{{bucket_id}}/{{video_name}}", + "method": "PUT", + "headers": [ + { + "name": "content-type", + "value": "video/mp4", + "enabled": true + }, + { + "name": "Accept", + "value": "application/json, text/plain, */*", + "enabled": true + }, + { + "name": "Accept-Encoding", + "value": "gzip, deflate, br, zstd", + "enabled": true + } + ], + "params": [], + "body": { + "mode": "formUrlEncoded", + "formUrlEncoded": [], + "multipartForm": [ + { + "type": "file", + "name": "", + "value": [ + "/Users/zubeydecivelek/Downloads/217490_medium.mp4" + ], + "enabled": true + } + ] + }, + "script": { + "req": "const fs = require('fs');\nconst path = require('path');\n\n// File details\nconst filename = \"CHANGE HERE\";\nconst filePath = \"CHANGE HERE\";\nbru.setEnvVar(\"video_name\",filename);\n\n// Read the file as raw binary data\nconst fileContent = fs.readFileSync(filePath);\n\n// Set request headers\nreq.setHeader(\"Content-Type\", \"video/mp4\"); // File content type\nreq.setHeader(\"Accept\", \"application/json, text/plain, */*\"); \nreq.setHeader(\"Accept-Encoding\", \"gzip, deflate, br, zstd\"); \nreq.setHeader(\"Content-Length\", fileContent.length);\n\n// Attach the file content as the request body\nreq.setBody(fileContent);\n", + "res": "let data = res.body ;\nbru.setEnvVar(\"main_file_version_id\", data.version_id);\nbru.setEnvVar(\"video_key\", data.key);" + }, + "vars": {}, + "assertions": [], + "tests": "", + "auth": { + "mode": "inherit" + } + } + }, + { + "type": "http", + "name": "Step 4- Create a flow", + "seq": 4, + "request": { + "url": "{{baseURl}}/api/flows/", + "method": "POST", + "headers": [ + { + "name": "content-type", + "value": "application/vnd.project.partial+json", + "enabled": true + } + ], + "params": [], + "body": { + "mode": "json", + "json": "{\n \"version_id\":\"{{main_file_version_id}}\", //response of the put the video 'version_id' \n \"key\": \"{{video_key}}\",//response of the put the video 'key' \n \"bucket_id\":\"{{bucket_id}}\", // create video response \n \"deposit_id\":\"{{video_id}}\" // create video response\n}", + "formUrlEncoded": [], + "multipartForm": [] + }, + "script": {}, + "vars": {}, + "assertions": [], + "tests": "", + "auth": { + "mode": "inherit" + } + } + }, + { + "type": "http", + "name": "Step 5- Upload additional file", + "seq": 6, + "request": { + "url": "{{baseURl}}/api/files/{{bucket_id}}/{{additional_file}}", + "method": "PUT", + "headers": [], + "params": [], + "body": { + "mode": "json", + "json": "", + "formUrlEncoded": [], + "multipartForm": [] + }, + "script": { + "req": "const fs = require('fs');\nconst path = require('path');\n\n// File details\nconst filename = \"CHANGE HERE\";\nconst filePath = \"CHANGE HERE\";\nbru.setEnvVar(\"additional_file\", filename);\n\n// Read the file as raw binary data\nconst fileContent = fs.readFileSync(filePath);\n\n// Set request headers\nreq.setHeader(\"Accept\", \"application/json, text/plain, */*\"); \nreq.setHeader(\"Accept-Encoding\", \"gzip, deflate, br, zstd\"); \nreq.setHeader(\"Content-Length\", fileContent.length);\n\n// Attach the file content as the request body\nreq.setBody(fileContent);\n" + }, + "vars": {}, + "assertions": [], + "tests": "", + "auth": { + "mode": "inherit" + } + } + }, + { + "type": "http", + "name": "Step 6- Publish", + "seq": 7, + "request": { + "url": "{{baseURl}}/api/deposits/video/{{video_id}}/actions/publish", + "method": "POST", + "headers": [ + { + "name": "content-type", + "value": "application/json", + "enabled": true + } + ], + "params": [], + "body": { + "mode": "json", + "json": "", + "formUrlEncoded": [], + "multipartForm": [] + }, + "script": {}, + "vars": {}, + "assertions": [], + "tests": "", + "auth": { + "mode": "inherit" + } + } + } + ], + "activeEnvironmentUid": "zqLEVCQ0eIhimP48VysTg", + "environments": [ + { + "variables": [ + { + "name": "baseURl", + "value": "https://localhost:5000/", + "enabled": true, + "secret": false, + "type": "text" + } + ], + "name": "Localhost" + } + ], + "root": { + "request": { + "auth": { + "mode": "bearer", + "bearer": { + "token": "CHANGE HERE" + } + } + } + }, + "brunoConfig": { + "version": "1", + "name": "CDS Videos Publish Video", + "type": "collection", + "scripts": { + "filesystemAccess": { + "allow": true + } + }, + "ignore": [ + "node_modules", + ".git" + ] + } +} \ No newline at end of file diff --git a/README.rst b/README.rst index c511d3a48..54b8106e1 100644 --- a/README.rst +++ b/README.rst @@ -185,10 +185,10 @@ Publish Video through REST API Generate a Personal Access Token --------------------------------- - - Navigate to the ``CDS Videos`` platform. - - Click your user info in the top-right corner. - - Go to **Applications** and create a new **Personal Access Token**. - - Copy the token and store it securely. +- Navigate to the ``CDS Videos`` platform. +- Click your user info in the top-right corner. +- Go to **Applications** and create a new **Personal Access Token**. +- Copy the token and store it securely. Using `Bruno` ~~~~~~~~~~~~~ @@ -197,11 +197,12 @@ If you'd like to use the pre-configured REST API collection in Bruno, ensure you 1. **Install Bruno:** - Visit the official Bruno `Bruno collection <./Bruno Collection - CDS Videos Publish Video.json>`_ or repository and install the application. + Visit the official Bruno `documentation `_ or repository and install the application. -2. **Create an Environment for the Collection:** +2. **Import the Collection:** - - Open Bruno and import this [collection](https://link). + - Download this `Bruno collection <./Bruno%20Collection%20-%20CDS%20Videos%20Publish%20Video.json>`_. + - Open Bruno and import downloaded collection. - Create an environment for the collection. - Configure the environment by adding a variable named ``baseURl``. Set its value to your API base URL (e.g., ``http://localhost:5000``). @@ -231,22 +232,48 @@ Step 1: Create a Project - **Type** - **Location** - **Description** + - **Required/Optional** * - **$schema** - string - body - Schema URL for the project creation. + - Required * - **category** - string - body - Category of the project. + - Required * - **type** - string - body - Type of the project. + - Required * - **_access** - json - body - - Access options for the video. + - Access options for the project. + - Optional + * - **contributors** + - array + - body + - List of contributors, including their details. + - Optional + * - **description** + - string + - body + - Description of the project. + - Optional + * - **title** + - json + - body + - Title of the project. + - Optional + * - **keywords** + - list + - body + - Keywords related to the project. + - Optional + **Body:** @@ -254,20 +281,52 @@ To restrict the project, add ``_access/read``: .. code-block:: json - { - "$schema": "https://localhost:5000/schemas/deposits/records/videos/project/project-v1.0.0.json", - "_access": { + { + "$schema": "https://localhost:5000/schemas/deposits/records/videos/project/project-v1.0.0.json", + "_access": { "update": [ - "admin@test.ch", - "atlas-outreach-cds-video@cern.ch" - ], - "read": [ - "atlas-readaccess-active-members@cern.ch" - ] - }, - "category": "ATLAS", - "type": "VIDEO" - } + "admin@test.ch", + "atlas-outreach-cds-video@cern.ch" + ], + "read": [ + "atlas-readaccess-active-members@cern.ch" + ] + }, + "category": "ATLAS", + "type": "VIDEO", + "contributors": [ + { + "name": "Surname, Name", + "ids": [ + { + "value": "cern id", + "source": "cern" + } + ], + "email": "test@cern.ch", + "role": "Co-Producer" + } + ], + "title": + { + "title":"project title" + }, + "keywords":[ + { + "name": "keyword", + "value": { + "name": "keyword" + } + }, + { + "name": "keyword2", + "value": { + "name": "keyword2" + } + } + ], + "description": "Description" + } **Response:** @@ -294,83 +353,120 @@ Step 2: Create a Video - **Type** - **Location** - **Description** + - **Required/Optional** * - **$schema** - string - body - Schema URL for video creation. + - Required * - **_project_id** - string - body - ID of the project. + - Required * - **title** - string - body - Title of the video. + - Required * - **_access** - - json, optional + - json - body - - Access details for the project. + - Access details for the video. + - Optional * - **vr** - boolean - body - + - Optional * - **contributors** - array - body - List of contributors, including their details. + - Required * - **description** - string - body - Description of the video. + - Required * - **date** - string (date) - body - Date in ``YYYY-MM-DD`` format. + - Required * - **language** - string - body - Language of the video. + - Optional * - **featured** - boolean - body - Whether the video is featured. + - Optional + * - **keywords** + - list + - body + - Keywords related to the video. + - Optional + * - **related_links** + - list + - body + - Links related to the video. + - Optional **Body:** -To restrict the video, add ``_access/read``. The `_access/update` will be the same as the project: +To restrict the video, add ``_access/read``. The ``_access/update`` will be the same as the project: .. code-block:: json - { + { "$schema":"https://localhost:5000/schemas/deposits/records/videos/video/video-v1.0.0.json", - "_project_id":"{{project_id}}", - "title": { - "title":"217490_medium" - }, - "_access": { - "read": [ - "atlas-readaccess-active-members@cern.ch" - ] - }, + "_project_id":"{{project_id}}", + "title": + { + "title":"217490_medium" + }, "vr": false, "featured": false, "language": "en", "contributors": [ - { - "name": "Surname, Name", - "ids": [ + { + "name": "Surname, Name", + "ids": [ { - "value": "cern id", - "source": "cern" + "value": "cern id", + "source": "cern" } - ], - "email": "email@cern.ch", - "role": "Co-Producer" - } + ], + "email": "test@cern.ch", + "role": "Co-Producer" + } ], "description": "Description", - "date": "2024-11-12" - } + "date": "2024-11-12", + "keywords":[ + { + "name": "keyword", + "value": { + "name": "keyword" + } + }, + { + "name": "keyword2", + "value": { + "name": "keyword2" + } + } + ], + "related_links":[ + { + "name": "related link", + "url": "https://relatedlink" + } + ] + } **Response:**