Class: CakeMail::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/cakemail/template.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, user) ⇒ Template

Returns a new instance of Template.



17
18
19
20
21
# File 'lib/cakemail/template.rb', line 17

def initialize(id, user)
  @user = user
  @id = id
  get_info
end

Instance Attribute Details

#client_idObject (readonly)

Returns the value of attribute client_id.



14
15
16
# File 'lib/cakemail/template.rb', line 14

def client_id
  @client_id
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/cakemail/template.rb', line 14

def id
  @id
end

#messageObject

Returns the value of attribute message.



15
16
17
# File 'lib/cakemail/template.rb', line 15

def message
  @message
end

#nameObject

Returns the value of attribute name.



15
16
17
# File 'lib/cakemail/template.rb', line 15

def name
  @name
end

#typeObject

Returns the value of attribute type.



15
16
17
# File 'lib/cakemail/template.rb', line 15

def type
  @type
end

Class Method Details

.create(args) ⇒ Object

Creates a new template.

Arguments :

  • options = { :user => required, :name => required, :type => optional, :message => optional }

Raises:

  • (ArgumentError)


54
55
56
57
58
59
60
61
# File 'lib/cakemail/template.rb', line 54

def create(args)
  raise ArgumentError if args.nil? or args[:user].nil?
  options = { :name => name, :user_key => args[:user].user_key }
  options[:type] = args[:type] unless args[:type].nil?
  options[:message] = args[:message] unless args[:message].nil?
   res = args[:user].session.request("CakeMail::API::ClassTemplate", "Create", options)
   Template.new(res['id'].first, args[:user])
end

.get_list(args) ⇒ Object

Retrieves the list of template.

Arguments :

  • args = { :user => required, :count => optional, :type => optional, :limit => optional, :offset => optional }

Raises:

  • (ArgumentError)


66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/cakemail/template.rb', line 66

def get_list(args)
  raise ArgumentError if args.nil? or args[:user].nil?
  options = { :user_key => args[:user].user_key }
  options[:type] = args[:type] unless args[:status].nil?
  options[:limit] = args[:limit] unless args[:limit].nil?
  options[:offset] = args[:offset] unless args[:offset].nil?
  options[:count] = args[:count] unless args[:count].nil?
  res = args[:user].session.request("CakeMail::API::ClassTemplate", "GetList", options)
  if !args[:count].nil?
    return res['count']
  end
  return res['template']
end

Instance Method Details

#deleteObject

Deletes a template.



23
24
25
26
# File 'lib/cakemail/template.rb', line 23

def delete
  @user.session.request("CakeMail::API::ClassTemplate", "Delete", { :template_id => @id, :user_key => @user.user_key })
  self.freeze
end

#get_info(id = @id) ⇒ Object

Returns information about a template.



28
29
30
31
32
33
34
35
# File 'lib/cakemail/template.rb', line 28

def get_info(id = @id)
  res = @user.session.request("CakeMail::API::ClassTemplate", "GetInfo", { :template_id => id, :user_key => @user.user_key })
  @id = res['id'].first
  @client_id = res['client_id'].first
  @name = res['name'].first
  @type = res['type'].first
  @message = res['message'].first
end

#saveObject



37
38
39
# File 'lib/cakemail/template.rb', line 37

def save
  self.setinfo
end

#set_infoObject

Modifies a template.



41
42
43
44
45
46
47
# File 'lib/cakemail/template.rb', line 41

def set_info
  args = { :template_id => @id, :user_key => @user.user_key }
  args[:name] = @name unless @name.nil?
  args[:message] = @message unless @message.nil?
  args[:type] = @type unless @type
  res = @user.session.request("CakeMail::API::ClassTemplate", "SetInfo", args)
end