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::KL_USER_AGENT, Client::KL_VERSION, Client::METRIC, Client::METRICS, Client::TIMELINE, Client::V1_API, Client::V2_API
Class Method Summary collapse
-
.clone_template(template_id, name:, api_key: nil) ⇒ JSON
Creates a copy of a given template with a new name.
-
.create_template(name: nil, html: nil, api_key: nil) ⇒ JSON
Creates a new email template.
-
.delete_template(template_id, api_key: nil) ⇒ JSON
Deletes a given template.
-
.get_templates(api_key: nil) ⇒ List
Returns a list of all the email templates you’ve created.
-
.render_template(template_id, context: {}, api_key: nil) ⇒ 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: {}, api_key: nil) ⇒ 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:, api_key: nil) ⇒ JSON
Updates the name and/or HTML content of a template.
Class Method Details
.clone_template(template_id, name:, api_key: nil) ⇒ JSON
Creates a copy of a given template with a new name
60 61 62 63 64 65 66 |
# File 'lib/klaviyo/apis/email_templates.rb', line 60 def self.clone_template(template_id, name:, api_key: nil) path = "#{EMAIL_TEMPLATE}/#{template_id}/#{CLONE}" params = { name: name } v1_request(HTTP_POST, path, api_key: api_key, content_type: CONTENT_URL_FORM, params: params) end |
.create_template(name: nil, html: nil, api_key: nil) ⇒ JSON
Creates a new email template
22 23 24 25 26 27 28 |
# File 'lib/klaviyo/apis/email_templates.rb', line 22 def self.create_template(name: nil, html: nil, api_key: nil) params = { name: name, html: html } v1_request(HTTP_POST, EMAIL_TEMPLATES, api_key: api_key, content_type: CONTENT_URL_FORM, params: params) end |
.delete_template(template_id, api_key: nil) ⇒ JSON
Deletes a given template.
50 51 52 53 |
# File 'lib/klaviyo/apis/email_templates.rb', line 50 def self.delete_template(template_id, api_key: nil) path = "#{EMAIL_TEMPLATE}/#{template_id}" v1_request(HTTP_DELETE, path, api_key: api_key) end |
.get_templates(api_key: nil) ⇒ List
Returns a list of all the email templates you’ve created. The templates are returned in sorted order by name.
13 14 15 |
# File 'lib/klaviyo/apis/email_templates.rb', line 13 def self.get_templates(api_key: nil) v1_request(HTTP_GET, EMAIL_TEMPLATES, api_key: api_key) end |
.render_template(template_id, context: {}, api_key: nil) ⇒ JSON
Renders the specified template with the provided data and return HTML and text versions of the email
74 75 76 77 78 79 80 |
# File 'lib/klaviyo/apis/email_templates.rb', line 74 def self.render_template(template_id, context: {}, api_key: nil) path = "#{EMAIL_TEMPLATE}/#{template_id}/#{RENDER}" params = { context: context } v1_request(HTTP_POST, path, api_key: api_key, content_type: CONTENT_URL_FORM, params: params) end |
.send_template(template_id, from_email:, from_name:, subject:, to:, context: {}, api_key: nil) ⇒ JSON
Renders the specified template with the provided data and then send the contents in an email via the service specified
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/klaviyo/apis/email_templates.rb', line 92 def self.send_template(template_id, from_email:, from_name:, subject:, to:, context: {}, api_key: nil) 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, api_key: api_key, content_type: CONTENT_URL_FORM, params: params) end |
.update_template(template_id, name:, html:, api_key: nil) ⇒ JSON
Updates the name and/or HTML content of a template. Only updates imported HTML templates; does not currently update drag & drop templates
37 38 39 40 41 42 43 44 |
# File 'lib/klaviyo/apis/email_templates.rb', line 37 def self.update_template(template_id, name:, html:, api_key: nil) path = "#{EMAIL_TEMPLATE}/#{template_id}" params = { name: name, html: html } v1_request(HTTP_PUT, path, api_key: api_key, **params) end |