Class: CakeMail::Trigger

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, user) ⇒ Trigger

Returns a new instance of Trigger.



18
19
20
21
22
# File 'lib/cakemail/trigger.rb', line 18

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

Instance Attribute Details

#actionObject

Returns the value of attribute action.



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

def action
  @action
end

#delayObject

Returns the value of attribute delay.



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

def delay
  @delay
end

#encodingObject

Returns the value of attribute encoding.



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

def encoding
  @encoding
end

#html_messageObject

Returns the value of attribute html_message.



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

def html_message
  @html_message
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#parent_idObject

Returns the value of attribute parent_id.



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

def parent_id
  @parent_id
end

#send_toObject

Returns the value of attribute send_to.



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

def send_to
  @send_to
end

#sender_emailObject

Returns the value of attribute sender_email.



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

def sender_email
  @sender_email
end

#sender_nameObject

Returns the value of attribute sender_name.



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

def sender_name
  @sender_name
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

#subjectObject

Returns the value of attribute subject.



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

def subject
  @subject
end

#text_messageObject

Returns the value of attribute text_message.



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

def text_message
  @text_message
end

Class Method Details

.create(args) ⇒ Object

Creates a trigger.

Arguments :

  • args = { :user => required, :name => required, :list_id => required, :encoding => optional, :description => optional }

Raises:

  • (ArgumentError)


68
69
70
71
72
73
74
75
# File 'lib/cakemail/trigger.rb', line 68

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

.get_list(args) ⇒ Object

Retrieves the list of triggers.

  • args = { :user => required, :status => optional, :action => optional, :list_id => optional, :parent_id => optional, :limit => optional, :offset => optional, :count => optional }

Raises:

  • (ArgumentError)


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/cakemail/trigger.rb', line 80

def get_list(args)
  raise ArgumentError if args.nil? or args[:user].nil?
  options = { :user_key => args[:user].user_key }
  options[:status] = args[:status] unless args[:status].nil?
  options[:action] = args[:action] unless args[:action].nil?
  options[:list_id] = args[:list_id] unless args[:list_id].nil?
  options[:parent_id] = args[:parent_id] unless args[:parent_id].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::ClassTrigger", "GetList", options)
  if !args[:count].nil?
    return res['count'].first
  end
  return res['trigger']
end

Instance Method Details

#get_info(id = @id) ⇒ Object

Returns information about a trigger.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cakemail/trigger.rb', line 24

def get_info(id = @id)
  res = @user.session.request("CakeMail::API::ClassTrigger", "GetInfo", { :trigger_id => id, :user_key => @user.user_key })
  @id = res['id'].first
  @status = res['status'].first
  @encoding = res['encoding'].first
  @action = res['action'].first
  @name = res['name'].first
  @description = res['description'].first
  @delay = res['delay'].first
  @parent_id = res['list_id'].first
  @send_to = res['send_to'].first
  @subject = res['subject'].first
  @sender_name = res['sender_name'].first
  @sender_email = res['sender_email'].first
  @html_message = res['html_message'].first
  @text_message = res['text_message'].first
end

#saveObject



42
43
44
# File 'lib/cakemail/trigger.rb', line 42

def save
  self.setinfo
end

#set_infoObject

Returns information about a trigger.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/cakemail/trigger.rb', line 46

def set_info
  args = { :trigger_id => id, :user_key => @user.user_key }
  args[:status] = status unless status.nil?
  args[:encoding] = encoding unless encoding.nil?
  args[:action] = action unless action.nil?
  args[:name] = name unless name.nil?
  args[:description] = description unless description.nil?
  args[:delay] = delay unless delay.nil?
  args[:parent_id] = parent_id unless parent_id.nil?
  args[:send_to] = send_to unless send_to.nil?
  args[:subject] = subject unless subject.nil?
  args[:sender_name] = sender_name unless sender_name.nil?
  args[:html_message] = html_message unless html_message.nil?
  args[:text_message] = text_message unless text_message.nil?
  res = @user.session.request("CakeMail::API::ClassTrigger", "SetInfo", args)
end