Class: Axene::Mailer::Resources::Templates

Inherits:
Object
  • Object
show all
Defined in:
lib/axene/mailer/resources/templates.rb

Overview

The templates resource: reusable email templates (Starter plan and up). Accessed as client.templates.

Note the wire mapping for this resource: html maps to html_body and text maps to text_body (the emails resource keeps html/text).

Instance Method Summary collapse

Constructor Details

#initialize(transport) ⇒ Templates

Returns a new instance of Templates.

Parameters:



13
14
15
# File 'lib/axene/mailer/resources/templates.rb', line 13

def initialize(transport)
  @transport = transport
end

Instance Method Details

#create(name:, subject: nil, html: nil, text: nil, blocks_json: nil) ⇒ Hash

Create a template. variables are derived server-side from {name} placeholders in the bodies, so you do not pass them.

Parameters:

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

    maps to html_body

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

    maps to text_body

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

Returns:

  • (Hash)


33
34
35
# File 'lib/axene/mailer/resources/templates.rb', line 33

def create(name:, subject: nil, html: nil, text: nil, blocks_json: nil)
  @transport.request(:post, "/v1/templates/", body: serialize(name, subject, html, text, blocks_json))
end

#delete(id) ⇒ nil

Delete a template.

Parameters:

  • id (String)

Returns:

  • (nil)


63
64
65
# File 'lib/axene/mailer/resources/templates.rb', line 63

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

#duplicate(id) ⇒ Hash

Duplicate a template (the copy’s blocks_json is not carried over).

Parameters:

  • id (String)

Returns:

  • (Hash)


71
72
73
# File 'lib/axene/mailer/resources/templates.rb', line 71

def duplicate(id)
  @transport.request(:post, "/v1/templates/#{Util.escape(id)}/duplicate")
end

#get(id) ⇒ Hash

Fetch a single template.

Parameters:

  • id (String)

Returns:

  • (Hash)


41
42
43
# File 'lib/axene/mailer/resources/templates.rb', line 41

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

#listArray<Hash>

List all templates, most recently updated first.

Returns:

  • (Array<Hash>)


20
21
22
# File 'lib/axene/mailer/resources/templates.rb', line 20

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

#update(id, name: nil, subject: nil, html: nil, text: nil, blocks_json: nil) ⇒ Hash

Update a template (partial).

Parameters:

  • id (String)
  • name (String, nil) (defaults to: nil)
  • subject (String, nil) (defaults to: nil)
  • html (String, nil) (defaults to: nil)

    maps to html_body

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

    maps to text_body

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

Returns:

  • (Hash)


54
55
56
57
# File 'lib/axene/mailer/resources/templates.rb', line 54

def update(id, name: nil, subject: nil, html: nil, text: nil, blocks_json: nil)
  @transport.request(:patch, "/v1/templates/#{Util.escape(id)}",
                     body: serialize(name, subject, html, text, blocks_json))
end