Class: Sendara::Resources::Templates

Inherits:
Sendara::Resource show all
Defined in:
lib/sendara/resources/templates.rb

Instance Method Summary collapse

Methods inherited from Sendara::Resource

#initialize

Constructor Details

This class inherits a constructor from Sendara::Resource

Instance Method Details

#create(name:, channel: "email", subject: nil, body_text: nil, body_html: nil, body_json: nil, variables: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/sendara/resources/templates.rb', line 16

def create(name:, channel: "email", subject: nil, body_text: nil, body_html: nil,
           body_json: nil, variables: nil)
  body = compact_params(
    "name" => name,
    "channel" => channel,
    "subject" => subject,
    "body_text" => body_text,
    "body_html" => body_html,
    "body_json" => body_json,
    "variables" => variables
  )
  request(:post, "/v1/templates", body: body) || {}
end

#delete(id) ⇒ Object



44
45
46
47
# File 'lib/sendara/resources/templates.rb', line 44

def delete(id)
  request(:delete, "/v1/templates/#{encode(id)}")
  nil
end

#get(id) ⇒ Object



12
13
14
# File 'lib/sendara/resources/templates.rb', line 12

def get(id)
  request(:get, "/v1/templates/#{encode(id)}") || {}
end

#listObject



6
7
8
9
10
# File 'lib/sendara/resources/templates.rb', line 6

def list
  response = request(:get, "/v1/templates") || {}
  templates = response["templates"]
  templates.is_a?(Array) ? templates : []
end

#render(id, vars = {}) ⇒ Object



49
50
51
# File 'lib/sendara/resources/templates.rb', line 49

def render(id, vars = {})
  request(:post, "/v1/templates/#{encode(id)}/render", body: { "vars" => vars || {} }) || {}
end

#update(id, name: nil, subject: nil, body_text: nil, body_html: nil, body_json: nil, variables: nil, is_active: nil) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/sendara/resources/templates.rb', line 30

def update(id, name: nil, subject: nil, body_text: nil, body_html: nil,
           body_json: nil, variables: nil, is_active: nil)
  body = compact_params(
    "name" => name,
    "subject" => subject,
    "body_text" => body_text,
    "body_html" => body_html,
    "body_json" => body_json,
    "variables" => variables,
    "is_active" => is_active
  )
  request(:put, "/v1/templates/#{encode(id)}", body: body) || {}
end