Class: Melaya::TemplatesAPI

Inherits:
Object
  • Object
show all
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

Examples:

templates = melaya.templates.list
t = melaya.templates.save(name: "My report", payload: { steps: [] })
melaya.templates.share(t["id"], "team")
melaya.templates.delete(t["id"])

Instance Method Summary collapse

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.

Parameters:

  • template_id (String)
  • user_id (String, nil) (defaults to: nil)

    target user UUID

  • project_id (String, nil) (defaults to: nil)

    target project UUID



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.

Parameters:

  • template_id (String)


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.

Parameters:

  • template_id (String)

    the source template to copy

  • new_name (String, nil) (defaults to: nil)


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

#listObject

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.

Parameters:

  • template_id (String)


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_globalObject

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_validatedObject

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.

Parameters:

  • name (String)
  • payload (Hash)
  • description (String, nil) (defaults to: nil)
  • category (String, nil) (defaults to: nil)


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.

Parameters:

  • template_id (String)
  • visibility (String)

    "private", "team", "community", or "assigned"



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_targetsObject

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.

Parameters:

  • template_id (String)
  • user_id (String, nil) (defaults to: nil)

    target user UUID

  • project_id (String, nil) (defaults to: nil)

    target project UUID



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.

Parameters:

  • template_id (String)
  • body (Hash) (defaults to: {})


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