Class: CakeMail::Mailing

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(campaign, id) ⇒ Mailing

Returns a new instance of Mailing.



40
41
42
43
44
# File 'lib/cakemail/mailing.rb', line 40

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

Instance Attribute Details

#active_emailsObject (readonly)

Returns the value of attribute active_emails.



36
37
38
# File 'lib/cakemail/mailing.rb', line 36

def active_emails
  @active_emails
end

#campaign_idObject

Returns the value of attribute campaign_id.



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

def campaign_id
  @campaign_id
end

#clickthru_htmlObject

Returns the value of attribute clickthru_html.



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

def clickthru_html
  @clickthru_html
end

#clickthru_textObject

Returns the value of attribute clickthru_text.



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

def clickthru_text
  @clickthru_text
end

#created_onObject (readonly)

Returns the value of attribute created_on.



36
37
38
# File 'lib/cakemail/mailing.rb', line 36

def created_on
  @created_on
end

#encodingObject

Returns the value of attribute encoding.



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

def encoding
  @encoding
end

#html_messageObject

Returns the value of attribute html_message.



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

def html_message
  @html_message
end

#idObject (readonly)

Returns the value of attribute id.



36
37
38
# File 'lib/cakemail/mailing.rb', line 36

def id
  @id
end

#in_queueObject (readonly)

Returns the value of attribute in_queue.



36
37
38
# File 'lib/cakemail/mailing.rb', line 36

def in_queue
  @in_queue
end

#list_idObject

Returns the value of attribute list_id.



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

def list_id
  @list_id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#next_stepObject

Returns the value of attribute next_step.



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

def next_step
  @next_step
end

#opening_statsObject

Returns the value of attribute opening_stats.



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

def opening_stats
  @opening_stats
end

#out_queueObject (readonly)

Returns the value of attribute out_queue.



36
37
38
# File 'lib/cakemail/mailing.rb', line 36

def out_queue
  @out_queue
end

#recipientsObject (readonly)

Returns the value of attribute recipients.



36
37
38
# File 'lib/cakemail/mailing.rb', line 36

def recipients
  @recipients
end

#scheduled_forObject (readonly)

Returns the value of attribute scheduled_for.



36
37
38
# File 'lib/cakemail/mailing.rb', line 36

def scheduled_for
  @scheduled_for
end

#scheduled_onObject (readonly)

Returns the value of attribute scheduled_on.



36
37
38
# File 'lib/cakemail/mailing.rb', line 36

def scheduled_on
  @scheduled_on
end

#sender_emailObject

Returns the value of attribute sender_email.



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

def sender_email
  @sender_email
end

#sender_nameObject

Returns the value of attribute sender_name.



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

def sender_name
  @sender_name
end

#statusObject (readonly)

Returns the value of attribute status.



36
37
38
# File 'lib/cakemail/mailing.rb', line 36

def status
  @status
end

#subjectObject

Returns the value of attribute subject.



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

def subject
  @subject
end

#sublist_idObject

Returns the value of attribute sublist_id.



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

def sublist_id
  @sublist_id
end

#suspendedObject (readonly)

Returns the value of attribute suspended.



36
37
38
# File 'lib/cakemail/mailing.rb', line 36

def suspended
  @suspended
end

#text_messageObject

Returns the value of attribute text_message.



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

def text_message
  @text_message
end

Returns the value of attribute unsub_bottom_link.



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

def unsub_bottom_link
  @unsub_bottom_link
end

Class Method Details

.create(campaign, name, encoding = nil) ⇒ Object

Creates a mailing.



190
191
192
193
194
195
# File 'lib/cakemail/mailing.rb', line 190

def create(campaign, name, encoding = nil)
  args = { :campaign_id => campaign.id, :name => name, :user_key => campaign.user.user_key }
  args[:encoding] = encoding unless encoding.nil?
  res = campaign.user.session.request("CakeMail::API::ClassMailing", "Create", args)
  Mailing.new(campaign, res['id'].first)
end

.get_list(args) ⇒ Object

Returns the list of mailings.

Arguments :

  • args = { :campaign => required, :status => optional, :campaign_id => optional, :list_id => optional, :limit => optional, :offset => optional, :count => optional }

Raises:

  • (ArgumentError)


201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/cakemail/mailing.rb', line 201

def get_list(args)
  raise ArgumentError if args.nil? or args[:campaign].nil?
  options = { :user_key => args[:campaign].user.user_key }
  options[:status] = args[:status] unless args[:status].nil?
  options[:campaign_id] = args[:campaign_id] unless args[:campaign_id].nil?
  options[:list_id] = args[:list_id] unless args[:list_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[:campaign].user.session.request("CakeMail::API::ClassMailing", "GetList", options)
  res['mailing']
end

Instance Method Details

#deleteObject

Deletes a mailing.



46
47
48
49
# File 'lib/cakemail/mailing.rb', line 46

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

#get_email_messageObject

Returns the subject and the message of the mailing.



51
52
53
54
55
56
# File 'lib/cakemail/mailing.rb', line 51

def get_email_message
  @campaign.user.session.request("CakeMail::API::ClassMailing", "GetEmailMessage", { :mailing_id => @id, 
    :user_key => @campaign.user.user_key })
  @subject = res['subject'].first
  @message = res['message'].first
end

#get_html_messageObject

Retrieves the html message of a mailing.



58
59
60
61
62
# File 'lib/cakemail/mailing.rb', line 58

def get_html_message
  @campaign.user.session.request("CakeMail::API::ClassMailing", "GetHtmlMessage", { :mailing_id => @id, 
    :user_key => @campaign.user.user_key })
  @html_message = res['html_message'].first
end

#get_info(id = @id) ⇒ Object

Retrieves the setting for a mailing.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/cakemail/mailing.rb', line 70

def get_info(id = @id)
  res = @campaign.user.session.request("CakeMail::API::ClassMailing", "GetInfo", { :mailing_id => @id, 
    :user_key => @campaign.user.user_key })
  @active_emails = res['active_emails'].first
  @campaign_id = res['campaign_id'].first
  @clickthru_html = res['clickthru_html'].first
  @clickthru_text = res['clickthru_text'].first
  @created_on = res['created_on'].first
  @encoding = res['encoding'].first
  @html_message = res['html_message'].first
  @id = res['id'].first
  @in_queue = res['in_queue'].first
  @list_id = res['list_id'].first
  @name = res['name'].first
  @next_step = res['next_step'].first
  @opening_stats = res['opening_stats'].first
  @out_queue = res['out_queue'].first
  @recipients = res['recipients'].first
  @scheduled_for = res['scheduled_for'].first
  @scheduled_on = res['scheduled_on'].first
  @sender_name = res['sender_name'].first
  @status = res['status'].first
  @subject = res['subject'].first
  @sublist_id = res['sublist_id'].first
  @suspended = res['suspended'].first
  @text_message = res['text_message'].first
  @unsub_bottom_link = res['unsub_bottom_link'].first
end

Retrieves the links of a mailing.



124
125
126
127
128
129
# File 'lib/cakemail/mailing.rb', line 124

def get_links(status = nil)
  args = { :mailing_id => @id, :user_key  => @campaign.user.user_key }
  args[:status] = status unless status.nil?
  res = @campaign.user.session.request("CakeMail::API::ClassMailing", "GetLinks", args)
  res['link']
end

Retrieves statistics about the links of a mailing.



116
117
118
119
120
121
122
# File 'lib/cakemail/mailing.rb', line 116

def get_links_log(start_date = nil, end_date = nil)
  args = { :mailing_id => @id, :user_key  => @campaign.user.user_key }
  args[:start_date] = start_date unless start_date.nil?
  args[:end_date] = end_date unless end_date.nil?
  res = @campaign.user.session.request("CakeMail::API::ClassMailing", "GetLinksLog", args)
  res['link']
end

#get_log(args) ⇒ Object

Retrieves information about the log of a mailing.

Arguments :

  • args = { :action => optional, :record_id => optional, :start_date => optional, :end_date => optional, :date => optional, :extra => optional, :limit => optional, :offset => optional, :count => optional, :uniques => optional }



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/cakemail/mailing.rb', line 103

def get_log(args)
  options = { :mailing_id => @id, :user_key  => @campaign.user.user_key }
  options[:action] = args[:action] unless args[:action].nil?
  options[:record_id] = args[:record_id] unless args[:record_id].nil?
  options[:start_date] = args[:start_date] unless args[:start_date].nil?
  options[:end_date] = args[:end_date] unless args[:end_date].nil?
  options[:date] = args[:date] unless args[:date].nil?
  options[:extra] = args[:extra] unless args[:extra].nil?
  options[:limit] = args[:limit] unless args[:limit].nil?
  res = @campaign.user.session.request("CakeMail::API::ClassMailing", "GetLog", options)
  res['log']
end

#get_stats(information) ⇒ Object

Retrieves statistics about a mailing.



131
132
133
134
135
# File 'lib/cakemail/mailing.rb', line 131

def get_stats(information)
  res = @campaign.user.session.request("CakeMail::API::ClassMailing", "GetStats", { :information => information, :mailing_id => @id, 
    :user_key => @campaign.user.user_key })
  res[information].first
end

#get_text_messageObject

Retrieves the text message of a mailing.



64
65
66
67
68
# File 'lib/cakemail/mailing.rb', line 64

def get_text_message
  @campaign.user.session.request("CakeMail::API::ClassMailing", "GetTextMessage", { :mailing_id => @id, 
    :user_key => @campaign.user.user_key })
  @text_message = res['text_message'].first
end

#resumeObject

Resumes the delivery of a mailing.



137
138
139
140
# File 'lib/cakemail/mailing.rb', line 137

def resume
  res = @campaign.user.session.request("CakeMail::API::ClassMailing", "Resume", { :mailing_id => @id, 
    :user_key  => @campaign.user.user_key })
end

#saveObject



142
143
144
# File 'lib/cakemail/mailing.rb', line 142

def save
  self.set_info
end

#schedule(date = nil) ⇒ Object

Schedules a mailing for delivery.



146
147
148
149
150
# File 'lib/cakemail/mailing.rb', line 146

def schedule(date = nil)
  args = { :mailing_id => @id, :user_key  => @campaign.user.user_key }
  args[:date] = date unless date.nil?
  res = @campaign.user.session.request("CakeMail::API::ClassMailing", "Schedule", args)
end

#send_test_email(test_email, test_type) ⇒ Object

Sends the mailing as a test to an email.



152
153
154
155
# File 'lib/cakemail/mailing.rb', line 152

def send_test_email(test_email, test_type)
  res = @campaign.user.session.request("CakeMail::API::ClassMailing", "SendTestEmail", { :mailing_id => @id, 
    :user_key  => @campaign.user.user_key, :test_email => test_email, :test_type => test_type })
end

#set_infoObject

Modifies the settings of a mailing.



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/cakemail/mailing.rb', line 157

def set_info
  args = { :mailing_id => @id, :user_key => @campaign.user.user_key }
  args[:campaign_id] = @campaign_id unless @campaign_id.nil?
  args[:list_id] = @list_id unless @list_id.nil? or @list_id == '0'
  args[:sublist_id] = @sublist_id unless @sublist_id.nil? or @sublist_id == '0'
  args[:next_step] = @next_step unless @next_step.nil?
  args[:encoding] = @encoding unless @encoding.nil?
  args[:clickthru_html] = @clickthru_html unless @clickthru_html.nil?
  args[:clickthru_text] = @clickthru_text unless @clickthru_text.nil?
  args[:opening_stats] = @opening_stats unless @opening_stats.nil?
  args[:unsub_bottom_link] = @unsub_bottom_link unless @unsub_bottom_link.nil?
  args[:name] = @name unless @name.nil?
  args[:subject] = @subject unless @subject.nil?
  args[:sender_name]  = @sender_name unless @sender_name.nil?
  args[:sender_email] = @sender_email unless @sender_email.nil?
  args[:html_message] = @html_message unless @html_message.nil?
  args[:text_message] = @text_message unless @text_message.nil?
  args[:campaign_id] = @campaign_id unless @campaign_id.nil?
  res = @campaign.user.session.request("CakeMail::API::ClassMailing", "SetInfo", args)
end

#suspendObject

Suspends the delivery of a mailing.



178
179
180
181
# File 'lib/cakemail/mailing.rb', line 178

def suspend
  res = @campaign.user.session.request("CakeMail::API::ClassMailing", "Suspend", { :mailing_id => @id, 
    :user_key  => @campaign.user.user_key })
end

#unscheduleObject

Unschedules a mailing from delivery.



183
184
185
186
# File 'lib/cakemail/mailing.rb', line 183

def unschedule
  res = @campaign.user.session.request("CakeMail::API::ClassMailing", "Unschedule", { :mailing_id => @id, 
    :user_key  => @campaign.user.user_key })
end