Class: Deckle::Templates

Inherits:
Object
  • Object
show all
Defined in:
lib/deckle/templates.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Templates

Returns a new instance of Templates.



5
6
7
# File 'lib/deckle/templates.rb', line 5

def initialize(client)
  @client = client
end

Instance Method Details

#create(name:, html_content:, schema: nil, is_public: false) ⇒ Hash

Create a new template.

Parameters:

  • name (String)

    Template name.

  • html_content (String)

    HTML content of the template.

  • schema (Hash, nil) (defaults to: nil)

    JSON schema for template data validation.

  • is_public (Boolean) (defaults to: false)

    Whether the template is publicly accessible.

Returns:

  • (Hash)

    Created template.



16
17
18
19
20
21
# File 'lib/deckle/templates.rb', line 16

def create(name:, html_content:, schema: nil, is_public: false)
  body = { "name" => name, "html_content" => html_content, "is_public" => is_public }
  body["schema"] = schema if schema

  @client.request(:post, "/v1/templates", body: body)
end

#delete(id) ⇒ Hash

Delete a template.

Parameters:

  • id (String)

    Template ID.

Returns:

  • (Hash)

    Deletion confirmation.



60
61
62
# File 'lib/deckle/templates.rb', line 60

def delete(id)
  @client.request(:delete, "/v1/templates/#{id}")
end

#get(id) ⇒ Hash

Get a template by ID.

Parameters:

  • id (String)

    Template ID.

Returns:

  • (Hash)

    Template details.



34
35
36
# File 'lib/deckle/templates.rb', line 34

def get(id)
  @client.request(:get, "/v1/templates/#{id}")
end

#listHash

List all templates.

Returns:

  • (Hash)

    List response with data array.



26
27
28
# File 'lib/deckle/templates.rb', line 26

def list
  @client.request(:get, "/v1/templates")
end

#update(id, name: nil, html_content: nil, schema: nil, is_public: nil) ⇒ Hash

Update a template.

Parameters:

  • id (String)

    Template ID.

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

    New template name.

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

    New HTML content.

  • schema (Hash, nil) (defaults to: nil)

    New JSON schema.

  • is_public (Boolean, nil) (defaults to: nil)

    New public visibility setting.

Returns:

  • (Hash)

    Updated template.



46
47
48
49
50
51
52
53
54
# File 'lib/deckle/templates.rb', line 46

def update(id, name: nil, html_content: nil, schema: nil, is_public: nil)
  body = {}
  body["name"] = name unless name.nil?
  body["html_content"] = html_content unless html_content.nil?
  body["schema"] = schema unless schema.nil?
  body["is_public"] = is_public unless is_public.nil?

  @client.request(:put, "/v1/templates/#{id}", body: body)
end