Class: Klaviyo::EmailTemplates
- Defined in:
- lib/klaviyo/apis/email_templates.rb
Constant Summary collapse
- EMAIL_TEMPLATES =
'email-templates'
- EMAIL_TEMPLATE =
'email-template'
- CLONE =
'clone'
- RENDER =
'render'
- SEND =
'send'
Constants inherited from Client
Client::ALL, Client::BASE_API_URL, Client::CONTENT_JSON, Client::CONTENT_URL_FORM, Client::DEFAULT_COUNT, Client::DEFAULT_PAGE, Client::DEFAULT_SORT_DESC, Client::HTTP_DELETE, Client::HTTP_GET, Client::HTTP_POST, Client::HTTP_PUT, Client::METRIC, Client::METRICS, Client::TIMELINE, Client::V1_API, Client::V2_API
Class Method Summary collapse
-
.clone_template(template_id, name:) ⇒ JSON
Creates a copy of a given template with a new name.
-
.create_template(name: nil, html: nil) ⇒ JSON
Creates a new email template.
-
.delete_template(template_id) ⇒ JSON
Deletes a given template.
-
.get_templates ⇒ List
Returns a list of all the email templates you’ve created.
-
.render_template(template_id, context: {}) ⇒ JSON
Renders the specified template with the provided data and return HTML and text versions of the email.
-
.send_template(template_id, from_email:, from_name:, subject:, to:, context: {}) ⇒ JSON
Renders the specified template with the provided data and then send the contents in an email via the service specified.
-
.update_template(template_id, name:, html:) ⇒ JSON
Updates the name and/or HTML content of a template.
Class Method Details
.clone_template(template_id, name:) ⇒ JSON
Creates a copy of a given template with a new name
55 56 57 58 59 60 61 |
# File 'lib/klaviyo/apis/email_templates.rb', line 55 def self.clone_template(template_id, name:) path = "#{EMAIL_TEMPLATE}/#{template_id}/#{CLONE}" params = { name: name } v1_request(HTTP_POST, path, content_type: CONTENT_URL_FORM, params: params) end |
.create_template(name: nil, html: nil) ⇒ JSON
Creates a new email template
20 21 22 23 24 25 26 |
# File 'lib/klaviyo/apis/email_templates.rb', line 20 def self.create_template(name: nil, html: nil) params = { name: name, html: html } v1_request(HTTP_POST, EMAIL_TEMPLATES, content_type: CONTENT_URL_FORM, params: params) end |
.delete_template(template_id) ⇒ JSON
Deletes a given template.
46 47 48 49 |
# File 'lib/klaviyo/apis/email_templates.rb', line 46 def self.delete_template(template_id) path = "#{EMAIL_TEMPLATE}/#{template_id}" v1_request(HTTP_DELETE, path) end |
.get_templates ⇒ List
Returns a list of all the email templates you’ve created. The templates are returned in sorted order by name.
12 13 14 |
# File 'lib/klaviyo/apis/email_templates.rb', line 12 def self.get_templates() v1_request(HTTP_GET, EMAIL_TEMPLATES) end |
.render_template(template_id, context: {}) ⇒ JSON
Renders the specified template with the provided data and return HTML and text versions of the email
68 69 70 71 72 73 74 |
# File 'lib/klaviyo/apis/email_templates.rb', line 68 def self.render_template(template_id, context: {}) path = "#{EMAIL_TEMPLATE}/#{template_id}/#{RENDER}" params = { context: context } v1_request(HTTP_POST, path, content_type: CONTENT_URL_FORM, params: params) end |
.send_template(template_id, from_email:, from_name:, subject:, to:, context: {}) ⇒ JSON
Renders the specified template with the provided data and then send the contents in an email via the service specified
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/klaviyo/apis/email_templates.rb', line 85 def self.send_template(template_id, from_email:, from_name:, subject:, to:, context: {}) path = "#{EMAIL_TEMPLATE}/#{template_id}/#{SEND}" params = { from_email: from_email, from_name: from_name, subject: subject, to: to, context: context } v1_request(HTTP_POST, path, content_type: CONTENT_URL_FORM, params: params) end |
.update_template(template_id, name:, html:) ⇒ JSON
Updates the name and/or HTML content of a template. Only updates imported HTML templates; does not currently update drag & drop templates
34 35 36 37 38 39 40 41 |
# File 'lib/klaviyo/apis/email_templates.rb', line 34 def self.update_template(template_id, name:, html:) path = "#{EMAIL_TEMPLATE}/#{template_id}" params = { name: name, html: html } v1_request(HTTP_PUT, path, params) end |