Class: Smtpcom::Sendapi::Template

Inherits:
ApiResource show all
Defined in:
lib/smtpcom/sendapi/template.rb

Constant Summary collapse

MAPPINGS =
{
  id:         :_id,
  name:       :TemplateName,
  from:       :From,
  from_name:  :FromName,
  subject:    :Subject,
  html:       :Html
}

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiResource

#_get, #_get_raw, #_post, build_from_response, #initialize, #prepare_params

Methods included from Request

included

Constructor Details

This class inherits a constructor from Smtpcom::Sendapi::ApiResource

Class Method Details

.allObject



16
17
18
19
20
# File 'lib/smtpcom/sendapi/template.rb', line 16

def all
  _get('/templates/get')['Data'].map do |row|
    build_from_response row
  end
end

.find(id) ⇒ Object



22
23
24
# File 'lib/smtpcom/sendapi/template.rb', line 22

def find(id)
  build_from_response _get('/template/get', TemplateID: id)['Data']
end

Instance Method Details

#deleteObject



44
45
46
# File 'lib/smtpcom/sendapi/template.rb', line 44

def delete
  _post('/templates/delete', { TemplateID: @id }, :formatted)
end

#saveObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/smtpcom/sendapi/template.rb', line 27

def save
  attrs = {
    TemplateName: @name,
    From:         @from,
    FromName:     @from_name,
    Subject:      @subject,
    Html:         @html
  }
  res = if @id
          _post '/templates/update', attrs.merge(TemplateID: @id), :formatted
        else
          _post '/templates/add', attrs, :formatted
        end
  @id = res[:id]
  res
end