Class: Melaya::TemplatesAPI
- Inherits:
-
Object
- Object
- Melaya::TemplatesAPI
- Defined in:
- lib/melaya/templates.rb
Overview
Templates API — create, manage, share, and assign pipeline templates.
Templates bundle a pipeline definition into a reusable, shareable artifact. Visibility levels: private → team → community → assigned.
Maps to:
/api/v1/private/user-templates/* — CRUD + share + assignments
/api/v1/private/templates/* — global/validated lists
Instance Method Summary collapse
-
#assign(template_id, user_id: nil, project_id: nil) ⇒ Object
POST /api/v1/private/user-templates/:templateId/assignments Assign a template to a user or project.
-
#delete(template_id) ⇒ Object
DELETE /api/v1/private/user-templates/:id Delete (or soft-demote if shared) a template.
-
#duplicate(template_id, new_name: nil) ⇒ Object
POST /api/v1/private/user-templates/:sourceId/duplicate Duplicate a readable template into the caller's private library.
-
#initialize(http) ⇒ TemplatesAPI
constructor
A new instance of TemplatesAPI.
-
#list ⇒ Object
GET /api/v1/private/user-templates List all templates visible to the caller (own + team + community + assigned).
-
#list_assignments(template_id) ⇒ Object
GET /api/v1/private/user-templates/:templateId/assignments List all assignments (users / projects) for a template.
-
#list_global ⇒ Object
GET /api/v1/private/templates/global List all community-visibility (global) templates.
-
#list_validated ⇒ Object
GET /api/v1/private/templates/validated List IDs of all validated (platform-approved) templates.
-
#save(name:, payload:, description: nil, category: nil) ⇒ Object
POST /api/v1/private/user-templates Create a new private user template.
-
#share(template_id, visibility) ⇒ Object
PUT /api/v1/private/user-templates/:id/visibility Change the visibility of a template.
-
#share_targets ⇒ Object
GET /api/v1/private/user-templates/share-targets List projects the caller is a member of (for the share target picker UI).
-
#unassign(template_id, user_id: nil, project_id: nil) ⇒ Object
DELETE /api/v1/private/user-templates/:templateId/assignments Remove an assignment from a template.
-
#update(template_id, body = {}) ⇒ Object
PATCH /api/v1/private/user-templates/:id Update name/description/category/payload of a private user template.
Constructor Details
#initialize(http) ⇒ TemplatesAPI
Returns a new instance of TemplatesAPI.
19 20 21 |
# File 'lib/melaya/templates.rb', line 19 def initialize(http) @http = http end |
Instance Method Details
#assign(template_id, user_id: nil, project_id: nil) ⇒ Object
POST /api/v1/private/user-templates/:templateId/assignments
Assign a template to a user or project.
Provide exactly one of user_id: or project_id: (both UUIDs);
the server rejects requests carrying both or neither.
112 113 114 115 |
# File 'lib/melaya/templates.rb', line 112 def assign(template_id, user_id: nil, project_id: nil) @http.post("/api/v1/private/user-templates/#{enc(template_id)}/assignments", assignment_target(user_id, project_id)) end |
#delete(template_id) ⇒ Object
DELETE /api/v1/private/user-templates/:id Delete (or soft-demote if shared) a template.
77 78 79 |
# File 'lib/melaya/templates.rb', line 77 def delete(template_id) @http.delete("/api/v1/private/user-templates/#{enc(template_id)}") end |
#duplicate(template_id, new_name: nil) ⇒ Object
POST /api/v1/private/user-templates/:sourceId/duplicate Duplicate a readable template into the caller's private library.
69 70 71 72 |
# File 'lib/melaya/templates.rb', line 69 def duplicate(template_id, new_name: nil) body = new_name ? { "newName" => new_name } : nil @http.post("/api/v1/private/user-templates/#{enc(template_id)}/duplicate", body) end |
#list ⇒ Object
GET /api/v1/private/user-templates List all templates visible to the caller (own + team + community + assigned).
25 26 27 |
# File 'lib/melaya/templates.rb', line 25 def list @http.get("/api/v1/private/user-templates") end |
#list_assignments(template_id) ⇒ Object
GET /api/v1/private/user-templates/:templateId/assignments List all assignments (users / projects) for a template.
101 102 103 |
# File 'lib/melaya/templates.rb', line 101 def list_assignments(template_id) @http.get("/api/v1/private/user-templates/#{enc(template_id)}/assignments") end |
#list_global ⇒ Object
GET /api/v1/private/templates/global List all community-visibility (global) templates.
31 32 33 |
# File 'lib/melaya/templates.rb', line 31 def list_global @http.get("/api/v1/private/templates/global") end |
#list_validated ⇒ Object
GET /api/v1/private/templates/validated List IDs of all validated (platform-approved) templates.
37 38 39 |
# File 'lib/melaya/templates.rb', line 37 def list_validated @http.get("/api/v1/private/templates/validated") end |
#save(name:, payload:, description: nil, category: nil) ⇒ Object
POST /api/v1/private/user-templates Create a new private user template.
47 48 49 50 51 52 53 54 55 |
# File 'lib/melaya/templates.rb', line 47 def save(name:, payload:, description: nil, category: nil) body = compact( "name" => name, "payload" => payload, "description" => description, "category" => category ) @http.post("/api/v1/private/user-templates", body) end |
#share(template_id, visibility) ⇒ Object
PUT /api/v1/private/user-templates/:id/visibility Change the visibility of a template.
85 86 87 88 |
# File 'lib/melaya/templates.rb', line 85 def share(template_id, visibility) @http.put("/api/v1/private/user-templates/#{enc(template_id)}/visibility", "visibility" => visibility) end |
#share_targets ⇒ Object
GET /api/v1/private/user-templates/share-targets List projects the caller is a member of (for the share target picker UI).
92 93 94 |
# File 'lib/melaya/templates.rb', line 92 def share_targets @http.get("/api/v1/private/user-templates/share-targets") end |
#unassign(template_id, user_id: nil, project_id: nil) ⇒ Object
DELETE /api/v1/private/user-templates/:templateId/assignments
Remove an assignment from a template.
Provide exactly one of user_id: or project_id: (both UUIDs).
The target is sent as query params — the server ignores DELETE
request bodies.
125 126 127 128 |
# File 'lib/melaya/templates.rb', line 125 def unassign(template_id, user_id: nil, project_id: nil) @http.delete("/api/v1/private/user-templates/#{enc(template_id)}/assignments", assignment_target(user_id, project_id)) end |
#update(template_id, body = {}) ⇒ Object
PATCH /api/v1/private/user-templates/:id Update name/description/category/payload of a private user template.
61 62 63 |
# File 'lib/melaya/templates.rb', line 61 def update(template_id, body = {}) @http.patch("/api/v1/private/user-templates/#{enc(template_id)}", body) end |