Class: Axene::Mailer::Resources::Templates
- Inherits:
-
Object
- Object
- Axene::Mailer::Resources::Templates
- 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
-
#create(name:, subject: nil, html: nil, text: nil, blocks_json: nil) ⇒ Hash
Create a template.
-
#delete(id) ⇒ nil
Delete a template.
-
#duplicate(id) ⇒ Hash
Duplicate a template (the copy’s
blocks_jsonis not carried over). -
#get(id) ⇒ Hash
Fetch a single template.
-
#initialize(transport) ⇒ Templates
constructor
A new instance of Templates.
-
#list ⇒ Array<Hash>
List all templates, most recently updated first.
-
#update(id, name: nil, subject: nil, html: nil, text: nil, blocks_json: nil) ⇒ Hash
Update a template (partial).
Constructor Details
#initialize(transport) ⇒ Templates
Returns a new instance of Templates.
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.
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.
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).
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.
41 42 43 |
# File 'lib/axene/mailer/resources/templates.rb', line 41 def get(id) @transport.request(:get, "/v1/templates/#{Util.escape(id)}") end |
#list ⇒ Array<Hash>
List all templates, most recently updated first.
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).
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 |