Class: CakeMail::List
- Inherits:
-
Object
- Object
- CakeMail::List
- Defined in:
- lib/cakemail/list.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#bounced ⇒ Object
readonly
Returns the value of attribute bounced.
-
#created_on ⇒ Object
readonly
Returns the value of attribute created_on.
-
#forward_page ⇒ Object
Returns the value of attribute forward_page.
-
#goto_di ⇒ Object
Returns the value of attribute goto_di.
-
#goto_oi ⇒ Object
Returns the value of attribute goto_oi.
-
#goto_oo ⇒ Object
Returns the value of attribute goto_oo.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#language ⇒ Object
Returns the value of attribute language.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pending ⇒ Object
readonly
Returns the value of attribute pending.
-
#policy ⇒ Object
Returns the value of attribute policy.
-
#query ⇒ Object
Returns the value of attribute query.
-
#sender_email ⇒ Object
Returns the value of attribute sender_email.
-
#sender_name ⇒ Object
Returns the value of attribute sender_name.
-
#status ⇒ Object
Returns the value of attribute status.
-
#sublist_id ⇒ Object
Returns the value of attribute sublist_id.
-
#unsubscribes ⇒ Object
readonly
Returns the value of attribute unsubscribes.
Class Method Summary collapse
-
.create(args) ⇒ Object
Creates a list.
-
.get_list(args) ⇒ Object
Retrieves the list of lists.
Instance Method Summary collapse
-
#add_test_email(email) ⇒ Object
Adds a test email to a list.
-
#create_sublist(data, sublist_name) ⇒ Object
Creates a sublist from list.
-
#delete ⇒ Object
Deletes a list.
-
#delete_email(email) ⇒ Object
Deletes an email from a list.
-
#delete_record(record_id) ⇒ Object
Deletes a record from a list using the record’s id.
-
#delete_sublist(sublist_id) ⇒ Object
Deletes a sublist.
-
#delete_test_email(test_email_id) ⇒ Object
Deletes a test email of a list.
-
#edit_structure(action, field, type = nil) ⇒ Object
Modifies the structure of a list.
-
#get_fields ⇒ Object
Returns the fields of the list.
-
#get_info(id = @id) ⇒ Object
Retrieves informations about a list.
-
#get_record(record_id, record_key = nil) ⇒ Object
Retrieves information for a record from a list.
-
#get_sublists ⇒ Object
Retrieves the sublists for a list.
-
#get_test_emails ⇒ Object
Retrieves the test emails for a list.
-
#import(record) ⇒ Object
Import a list of emails into the list.
-
#initialize(id, user) ⇒ List
constructor
A new instance of List.
- #save ⇒ Object
-
#search(args) ⇒ Object
Searches for one or more records matching a set of conditions.
-
#set_info ⇒ Object
Modifies the parameters of a list.
-
#show(args) ⇒ Object
Displays the list.
-
#subscribe_email(email, no_triggers = nil, data = nil) ⇒ Object
Subscribes an email into a list.
-
#test_sublist(data) ⇒ Object
Tests a sublist.
-
#unsubscribe_email(email) ⇒ Object
Unsubscribes an email from a list.
-
#update_record(record_id, data, record_key = nil) ⇒ Object
Modifies a record into a list.
Constructor Details
#initialize(id, user) ⇒ List
Returns a new instance of List.
109 110 111 112 113 |
# File 'lib/cakemail/list.rb', line 109 def initialize(id, user) @user = user @id = id get_info end |
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
105 106 107 |
# File 'lib/cakemail/list.rb', line 105 def active @active end |
#bounced ⇒ Object (readonly)
Returns the value of attribute bounced.
105 106 107 |
# File 'lib/cakemail/list.rb', line 105 def bounced @bounced end |
#created_on ⇒ Object (readonly)
Returns the value of attribute created_on.
105 106 107 |
# File 'lib/cakemail/list.rb', line 105 def created_on @created_on end |
#forward_page ⇒ Object
Returns the value of attribute forward_page.
106 107 108 |
# File 'lib/cakemail/list.rb', line 106 def forward_page @forward_page end |
#goto_di ⇒ Object
Returns the value of attribute goto_di.
106 107 108 |
# File 'lib/cakemail/list.rb', line 106 def goto_di @goto_di end |
#goto_oi ⇒ Object
Returns the value of attribute goto_oi.
106 107 108 |
# File 'lib/cakemail/list.rb', line 106 def goto_oi @goto_oi end |
#goto_oo ⇒ Object
Returns the value of attribute goto_oo.
106 107 108 |
# File 'lib/cakemail/list.rb', line 106 def goto_oo @goto_oo end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
105 106 107 |
# File 'lib/cakemail/list.rb', line 105 def id @id end |
#language ⇒ Object
Returns the value of attribute language.
106 107 108 |
# File 'lib/cakemail/list.rb', line 106 def language @language end |
#name ⇒ Object
Returns the value of attribute name.
106 107 108 |
# File 'lib/cakemail/list.rb', line 106 def name @name end |
#pending ⇒ Object (readonly)
Returns the value of attribute pending.
105 106 107 |
# File 'lib/cakemail/list.rb', line 105 def pending @pending end |
#policy ⇒ Object
Returns the value of attribute policy.
106 107 108 |
# File 'lib/cakemail/list.rb', line 106 def policy @policy end |
#query ⇒ Object
Returns the value of attribute query.
106 107 108 |
# File 'lib/cakemail/list.rb', line 106 def query @query end |
#sender_email ⇒ Object
Returns the value of attribute sender_email.
106 107 108 |
# File 'lib/cakemail/list.rb', line 106 def sender_email @sender_email end |
#sender_name ⇒ Object
Returns the value of attribute sender_name.
106 107 108 |
# File 'lib/cakemail/list.rb', line 106 def sender_name @sender_name end |
#status ⇒ Object
Returns the value of attribute status.
106 107 108 |
# File 'lib/cakemail/list.rb', line 106 def status @status end |
#sublist_id ⇒ Object
Returns the value of attribute sublist_id.
106 107 108 |
# File 'lib/cakemail/list.rb', line 106 def sublist_id @sublist_id end |
#unsubscribes ⇒ Object (readonly)
Returns the value of attribute unsubscribes.
105 106 107 |
# File 'lib/cakemail/list.rb', line 105 def unsubscribes @unsubscribes end |
Class Method Details
.create(args) ⇒ Object
Creates a list.
Arguments :
-
args = { user => required, :name => required, :sender_name => required, :sender_email, :data => optional/custom }
Custom argument:
-
:data => [ { :type => “text”, :value => “city” }, { :type => “integer”, :value => “age” }, … ]
309 310 311 312 313 314 315 316 |
# File 'lib/cakemail/list.rb', line 309 def create(args) raise ArgumentError if args.nil? or args[:user].nil? or args[:name].nil? or args[:sender_email].nil? or args[:sender_name].nil? = { :user_key => args[:user].user_key, :name => args[:name], :sender_name => args[:sender_name], :sender_email => args[:sender_email] } [:data] = args[:data] unless args[:data].empty? res = args[:user].session.request("CakeMail::API::ClassList", "Create", ) List.new(res['id'].first, args[:user]) end |
.get_list(args) ⇒ Object
Retrieves the list of lists.
Arguments :
-
args = { user => required, status => optional, :limit => optional, :offset => optional, :count => optional }
321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/cakemail/list.rb', line 321 def get_list(args) raise ArgumentError if args.nil? or args[:user].nil? = { :user_key => args[:user].user_key } [:status] = args[:status] unless args[:status].nil? [:limit] = args[:limit] unless args[:limit].nil? [:offset] = args[:offset] unless args[:offset].nil? [:count] = args[:count] unless args[:count].nil? res = args[:user].session.request("CakeMail::API::ClassList", "GetList", ) if !args[:count].nil? return res['count'].first end return res['list'] end |
Instance Method Details
#add_test_email(email) ⇒ Object
Adds a test email to a list.
253 254 255 256 |
# File 'lib/cakemail/list.rb', line 253 def add_test_email(email) res = @user.session.request("CakeMail::API::ClassList", "AddTestEmail", { :email => email, :list_id => @id, :user_key => @user.user_key }) end |
#create_sublist(data, sublist_name) ⇒ Object
Creates a sublist from list. It supports up to 5 conditions for creating the sublist. Each condition is defined by a field, a function and a value. To connect the conditions between them, a radio option of type AND/OR is used. If the radio option is not specified, the OR option will be used by default.
Custom argument:
-
data = [ { :type => “0_field”, :value => “email” }, { :type => “0_function”, :value => “LIKE” }, { :type => “0_value”, :value => “test” }, … ]
275 276 277 278 279 |
# File 'lib/cakemail/list.rb', line 275 def create_sublist(data, sublist_name) res = @user.session.request("CakeMail::API::ClassList", "CreateSublist", { :data => data, :list_id => @id, :user_key => @user.user_key, :sublist_name => sublist_name }) return res['sublist_id'] end |
#delete ⇒ Object
Deletes a list.
115 116 117 118 |
# File 'lib/cakemail/list.rb', line 115 def delete @user.session.request("CakeMail::API::ClassList", "Delete", { :list_id => @id, :user_key => @user.user_key }) self.freeze end |
#delete_email(email) ⇒ Object
Deletes an email from a list.
230 231 232 233 |
# File 'lib/cakemail/list.rb', line 230 def delete_email(email) res = @user.session.request("CakeMail::API::ClassList", "DeleteEmail", { :email => email, :list_id => @id, :user_key => @user.user_key }) end |
#delete_record(record_id) ⇒ Object
Deletes a record from a list using the record’s id.
235 236 237 238 |
# File 'lib/cakemail/list.rb', line 235 def delete_record(record_id) res = @user.session.request("CakeMail::API::ClassList", "DeleteRecord", { :record_id => record_id, :list_id => @id, :user_key => @user.user_key }) end |
#delete_sublist(sublist_id) ⇒ Object
Deletes a sublist.
281 282 283 284 |
# File 'lib/cakemail/list.rb', line 281 def delete_sublist(sublist_id) res = @user.session.request("CakeMail::API::ClassList", "DeleteSublist", { :sublist_id => sublist_id, :user_key => @user.user_key }) end |
#delete_test_email(test_email_id) ⇒ Object
Deletes a test email of a list.
264 265 266 267 |
# File 'lib/cakemail/list.rb', line 264 def delete_test_email(test_email_id) res = @user.session.request("CakeMail::API::ClassList", "DeleteTestEmail", { :test_email_id => test_email_id, :list_id => @id, :user_key => @user.user_key }) end |
#edit_structure(action, field, type = nil) ⇒ Object
Modifies the structure of a list.
163 164 165 166 167 |
# File 'lib/cakemail/list.rb', line 163 def edit_structure(action, field, type = nil) args = { :list_id => @id, :user_key => @user.user_key, :action => action, :field => field } args[:type] = type unless type.nil? res = @user.session.request("CakeMail::API::ClassList", "EditStructure", args) end |
#get_fields ⇒ Object
Returns the fields of the list.
169 170 171 172 |
# File 'lib/cakemail/list.rb', line 169 def get_fields res = @user.session.request("CakeMail::API::ClassList", "GetFields", { :list_id => @id, :user_key => @user.user_key }) res['data'] end |
#get_info(id = @id) ⇒ Object
Retrieves informations about a list.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/cakemail/list.rb', line 120 def get_info(id = @id) res = @user.session.request("CakeMail::API::ClassList", "GetInfo", { :list_id => id, :user_key => @user.user_key }) res = res['list'].first @active = res['active'].first @bounced = res['bounced'].first @created_on = res['created_on'].first @deleted = res['deleted'].first @forward_page = res['forward_page'].first @goto_di = res['goto_di'].first @goto_oi = res['goto_oi'].first @goto_oo = res['goto_oo'].first @langauge = res['language'].first @list_id = res['id'].first @name = res['name'].first @pending = res['pending'].first @policy = res['policy'].first @sender_email = res['sender_email'].first @sender_name = res['sender_name'].first @status = res['status'].first @unsubscribed = res['unsubscribed'].first end |
#get_record(record_id, record_key = nil) ⇒ Object
Retrieves information for a record from a list.
240 241 242 243 244 245 |
# File 'lib/cakemail/list.rb', line 240 def get_record(record_id, record_key = nil) args = { :record_id => record_id, :list_id => @id, :user_key => @user.user_key } args[:record_key] = record_key unless record_key.nil? res = @user.session.request("CakeMail::API::ClassList", "GetRecord", args) return { :id => res['id'].first, :status => res['status'].first, :email => res['email'].first, :data => res['data'] } end |
#get_sublists ⇒ Object
Retrieves the sublists for a list.
296 297 298 299 300 |
# File 'lib/cakemail/list.rb', line 296 def get_sublists res = @user.session.request("CakeMail::API::ClassList", "GetSublists", { :list_id => @id, :user_key => @user.user_key }) return res['sublist'] end |
#get_test_emails ⇒ Object
Retrieves the test emails for a list.
258 259 260 261 262 |
# File 'lib/cakemail/list.rb', line 258 def get_test_emails res = @user.session.request("CakeMail::API::ClassList", "GetTestEmails", { :list_id => @id, :user_key => @user.user_key }) return res['test_email'] end |
#import(record) ⇒ Object
Import a list of emails into the list.
Custom argument :
-
record = [ { :data => [ { :type => ‘type’, :value => ‘value’ }, { :type => ‘type’, :value => ‘value’ }, … ] }, { :data => [ { :type => ‘type’, :value => ‘value’ }, { :type => ‘type’, :value => ‘value’ }, … ] }, … ]
178 179 180 181 |
# File 'lib/cakemail/list.rb', line 178 def import(record) res = @user.session.request("CakeMail::API::ClassList", "Import", { :list_id => @id, :record => record, :user_key => @user.user_key }) return res['record'] end |
#save ⇒ Object
142 143 144 |
# File 'lib/cakemail/list.rb', line 142 def save self.set_info end |
#search(args) ⇒ Object
Searches for one or more records matching a set of conditions. The search is performed using the equivalent of LIKE ‘%text%’ in SQL.
200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/cakemail/list.rb', line 200 def search(args) raise ArgumentError if args.nil? or args[:data].nil? = { :data => args[:data], :list_id => @id, :user_key => @user.user_key } [:limit] = args[:limit] unless args[:limit].nil? [:offset] = args[:offset] unless args[:offset].nil? [:count] = args[:count] unless args[:count].nil? res = @user.session.request("CakeMail::API::ClassList", "Search", ) if !args[:count].nil? return res['count'] end return res['record'] end |
#set_info ⇒ Object
Modifies the parameters of a list.
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/cakemail/list.rb', line 146 def set_info args = { :list_id => @id, :user_key => @user.user_key } args[:sublist_id] = @sublist_id unless @sublist_id.nil? or @sublist_id == '0' args[:name] = @name unless name.nil? args[:query] = @query unless @query.nil? args[:language] = @language unless @language.nil? args[:status] = @status unless @status.nil? args[:policy] = @policy unless @policy.nil? args[:sender_name] = @sender_name unless @sender_name.nil? args[:sender_email] = @sender_email unless @sender_email.nil? args[:forward_page] = @forward_page unless @forward_page.nil? args[:goto_oi] = @goto_oi unless @goto_oi.nil? args[:goto_di] = @goto_di unless @goto_di.nil? args[:goto_oo] = @goto_oo unless @goto_oo.nil? res = @user.session.request("CakeMail::API::ClassList", "SetInfo", args) end |
#show(args) ⇒ Object
Displays the list.
Argument :
-
args = { :status => required, bounce_type => optional, limit => optional, offset => optional, count => optional }
186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/cakemail/list.rb', line 186 def show(args) raise ArgumentError if args.nil? or args[:status].nil? = { :list_id => @id, :status => args[:status], :user_key => @user.user_key } [:bounce_type] = args[:bounce_type] unless args[:bounce_type].nil? [:limit] = args[:limit] unless args[:limit].nil? [:offset] = args[:offset] unless args[:offset].nil? [:count] = args[:count] unless args[:count].nil? res = @user.session.request("CakeMail::API::ClassList", "Show", ) if !args[:count].nil? return res['count'] end return res['record'] end |
#subscribe_email(email, no_triggers = nil, data = nil) ⇒ Object
Subscribes an email into a list. This function, by default, activates the opt-in and douopt-in triggers. Important: before using this function, the list’s policy must be accepted otherwise an error will occur!
Custom argument:
-
data = [ { :type => “last_name, :value => ”Doe“ }, … ]
217 218 219 220 221 222 223 |
# File 'lib/cakemail/list.rb', line 217 def subscribe_email(email, no_triggers = nil, data = nil) args = { :email => email, :list_id => @id, :user_key => @user.user_key } args[:no_triggers] = no_triggers unless no_triggers.nil? args[:data] = data unless data.nil? res = @user.session.request("CakeMail::API::ClassList", "SubscribeEmail", args) return res['record_id'] end |
#test_sublist(data) ⇒ Object
Tests a sublist.
Custom argument:
-
data = [ { :type => “0_field”, :value => “email” }, { :type => “0_function”, :value => “LIKE” }, { :type => “0_value”, :value => “test” }, … ]
290 291 292 293 294 |
# File 'lib/cakemail/list.rb', line 290 def test_sublist(data) res = @user.session.request("CakeMail::API::ClassList", "TestSublist", { :data => data, :list_id => @id, :user_key => @user.user_key }) return res['record'] end |
#unsubscribe_email(email) ⇒ Object
Unsubscribes an email from a list. This function activates the opt-out triggers.
225 226 227 228 |
# File 'lib/cakemail/list.rb', line 225 def unsubscribe_email(email) res = @user.session.request("CakeMail::API::ClassList", "UnsubscribeEmail", { :email => email, :list_id => @id, :user_key => @user.user_key }) end |
#update_record(record_id, data, record_key = nil) ⇒ Object
Modifies a record into a list.
247 248 249 250 251 |
# File 'lib/cakemail/list.rb', line 247 def update_record(record_id, data, record_key = nil) args = { :data => data, :record_id => record_id, :list_id => @id, :user_key => @user.user_key } args[:record_key] = record_key unless record_key.nil? res = @user.session.request("CakeMail::API::ClassList", "UpdateRecord", args) end |