lpgauth-ruby-cakemail 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +1 -0
- data/lib/cakemail/campaign.rb +83 -0
- data/lib/cakemail/client.rb +161 -0
- data/lib/cakemail/country.rb +23 -0
- data/lib/cakemail/group.rb +102 -0
- data/lib/cakemail/list.rb +336 -0
- data/lib/cakemail/mailing.rb +215 -0
- data/lib/cakemail/relay.rb +64 -0
- data/lib/cakemail/service.rb +46 -0
- data/lib/cakemail/session.rb +70 -0
- data/lib/cakemail/suppressionlist.rb +102 -0
- data/lib/cakemail/template.rb +81 -0
- data/lib/cakemail/trigger.rb +98 -0
- data/lib/cakemail/user.rb +179 -0
- data/lib/crypto/ecb_null_padded_blowfish.rb +89 -0
- data/lib/ruby-cakemail.rb +22 -0
- metadata +98 -0
data/README.rdoc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
== To be written.
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# A Campaign is a group of Mailings.
|
2
|
+
#
|
3
|
+
# A Campaign cannot be closed if any mailings are Incomplete, Scheduled or Delivering.
|
4
|
+
#
|
5
|
+
# A Campaign can be deleted only if it does not contain a Mailing.
|
6
|
+
module CakeMail
|
7
|
+
module API
|
8
|
+
class ClassCampaign < CakeMail::ServiceClass
|
9
|
+
method :name => "Create", :requires => [ :name, :user_key ]
|
10
|
+
method :name => "Delete", :requires => [ :campaign_id, :user_key ]
|
11
|
+
method :name => "GetInfo", :requires => [ :campaign_id, :user_key ]
|
12
|
+
method :name => "GetList", :requires => [ :user_key ], :optional => [ :count, :limti, :offset, :status ]
|
13
|
+
method :name => "SetInfo", :requires => [ :campaign_id, :user_key ], :optional => [ :name, :status ]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Campaign
|
18
|
+
attr_reader :client_id, :closed_on, :created_on, :id, :session, :user
|
19
|
+
attr_accessor :name, :status
|
20
|
+
|
21
|
+
def initialize(id, user)
|
22
|
+
@user = user
|
23
|
+
@id = id
|
24
|
+
get_info
|
25
|
+
end
|
26
|
+
# Deletes a campaign.
|
27
|
+
def delete
|
28
|
+
@user.session.request("CakeMail::API::ClassCampaign", "Delete", { :campaign_id => @id, :user_key => @user.user_key })
|
29
|
+
self.freeze
|
30
|
+
end
|
31
|
+
# Returns information about a campaign.
|
32
|
+
def get_info(id = @id)
|
33
|
+
res = @user.session.request("CakeMail::API::ClassCampaign", "GetInfo", { :campaign_id => id, :user_key => @user.user_key })
|
34
|
+
@client_id = res['client_id'].first
|
35
|
+
@closed_on = res['closed_on'].first
|
36
|
+
@created_on = res['created_on'].first
|
37
|
+
@id = res['id'].first
|
38
|
+
@name = res['name'].first
|
39
|
+
@status = res['status'].first
|
40
|
+
end
|
41
|
+
# Retreives a mailing by id.
|
42
|
+
def mailing(id)
|
43
|
+
return CakeMail::Mailing.new(self, id)
|
44
|
+
end
|
45
|
+
# Creates a new mailing.
|
46
|
+
def mailing_new(name)
|
47
|
+
return CakeMail::Mailing.create(self, name)
|
48
|
+
end
|
49
|
+
|
50
|
+
def save
|
51
|
+
self.setinfo
|
52
|
+
end
|
53
|
+
# Modifies a campaign.
|
54
|
+
def set_info
|
55
|
+
args = { :campaign_id => id, :user_key => @user.user_key }
|
56
|
+
args[:name] = @name unless @name.nil?
|
57
|
+
args[:status] = @status unless @status.nil?
|
58
|
+
res = @user.session.request("CakeMail::API::ClassCampaign", "SetInfo", args)
|
59
|
+
end
|
60
|
+
|
61
|
+
class << self
|
62
|
+
# Creates a new campaign.
|
63
|
+
def create(name, user)
|
64
|
+
res = user.session.request("CakeMail::API::ClassCampaign", "Create", { :name => name, :user_key => user.user_key })
|
65
|
+
Campaign.new(res['id'].first, user)
|
66
|
+
end
|
67
|
+
# Retrieves the list of campaigns.
|
68
|
+
#
|
69
|
+
# Arguments :
|
70
|
+
# * args = { :user => required, :limit => optional, :offset => optional, :status => optional }
|
71
|
+
def getlist(args)
|
72
|
+
raise ArgumentError if args.nil? or args[:user].nil?
|
73
|
+
options = { :user_key => args[:user].user_key }
|
74
|
+
options[:limit] = args[:limit] unless args[:limit].nil?
|
75
|
+
options[:offset] = args[:offset] unless args[:offset].nil?
|
76
|
+
options[:status] = args[:status] unless args[:status].nil?
|
77
|
+
res = args[:user].session.request("CakeMail::API::ClassCampaign", "GetList", options)
|
78
|
+
res['campaign']
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
@@ -0,0 +1,161 @@
|
|
1
|
+
# A Client is an account and is created for every Organization that uses CakeMail's services. An Admin User is created at the same time as
|
2
|
+
# the Client. Each Client (Account) may have as many Users as required. The Admin controls the permissions of each user within the Client
|
3
|
+
# account. Also, a Contact User may be created at the same time as the Admin User, upon creation of the Client Account. The Contact user is
|
4
|
+
# a secondary User. If no Contact User is entered, the Admin User is set as the default Contact User.
|
5
|
+
#
|
6
|
+
# Each Client has a Client ID. When creating a Child Client, use the Master Client ID as the "parent_id" upon creation of the new Client
|
7
|
+
# Account. The new Client Account will then be recognized as a Child Account of the Master.
|
8
|
+
module CakeMail
|
9
|
+
module API
|
10
|
+
class ClassClient < CakeMail::ServiceClass
|
11
|
+
method :name => "Create", :requires => [ :admin_email, :admin_first_name, :admin_last_name, :admin_password,
|
12
|
+
:admin_password_confirmation, :company_name, :contact_email, :contact_first_name, :contact_last_name, :contact_password,
|
13
|
+
:contact_password_confirmation ],
|
14
|
+
:optional => [ :parent_id, :currency, :address1, :address2, :city, :province_id, :postal_code, :country_id,
|
15
|
+
:website, :phone, :fax, :contact_same_as_admin, :admin_title, :admin_office_phone, :admin_mobile_phone,
|
16
|
+
:admin_language, :admin_timezone_id, :contact_title, :contact_language, :contact_timezone_id, :contact_office_phone,
|
17
|
+
:contact_mobile_phone ]
|
18
|
+
method :name => "Activate", :requires => [ :confirmation ]
|
19
|
+
method :name => "GetTimezones"
|
20
|
+
method :name => "GetInfo", :requires => [ :client_id, :user_key ]
|
21
|
+
method :name => "GetList", :optional => [ :status, :limit, :offset, :count, :user_key ]
|
22
|
+
method :name => "SetInfo", :requires => [ :user_key ], :optional => [ :client_id, :status, :manager_id, :parent_id, :contact_id,
|
23
|
+
:company_name, :address1, :address2, :city, :province_id, :postal_code, :country_id, :website, :phone, :fax, :user_key ]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Client
|
28
|
+
attr_reader :session, :id, :client_id, :manager_id, :parent_id, :province_id, :country_id, :contact_id, :contact_timezone_id,
|
29
|
+
:limit, :registered_date, :last_activity
|
30
|
+
attr_accessor :company_name, :admin_email, :admin_first_name, :admin_last_name, :admin_password, :contact_email,
|
31
|
+
:contact_first_name, :contact_last_name, :contact_password, :currency, :address1, :address2, :city,
|
32
|
+
:postal_code, :website, :phone, :fax, :admin_title, :admin_office_phone, :admin_mobile_phone,
|
33
|
+
:admin_language, :contact_title, :contact_language, :contact_office_phone, :contact_mobile_phone
|
34
|
+
|
35
|
+
def initialize(id, user)
|
36
|
+
@user = user
|
37
|
+
@id = id
|
38
|
+
get_info
|
39
|
+
end
|
40
|
+
# Returns information about a client.
|
41
|
+
def get_info(id = @id)
|
42
|
+
@user.session.request("CakeMail::API::ClassClient", "GetInfo", { :client_id => @id, :user_key => @user.user_key })
|
43
|
+
@registered_date = res['registered_date'].first
|
44
|
+
@last_activity = res['last_activity'].first
|
45
|
+
@manager_id = res['manager_id'].first
|
46
|
+
@parent_id = res['parent_id'].first
|
47
|
+
@contact_id = res['contact_id'].first
|
48
|
+
@province_id = res['province_id'].first
|
49
|
+
@country_id = res['country_id'].first
|
50
|
+
@limit = res['limit'].first
|
51
|
+
@status = res['status'].first
|
52
|
+
@currency = res['currency'].first
|
53
|
+
@company_name = res['company_name'].first
|
54
|
+
@address1 = res['address1'].first
|
55
|
+
@address2 = res['address2'].first
|
56
|
+
@city = res['city'].first
|
57
|
+
@postal_code = res['postal_code'].first
|
58
|
+
@website = res['website'].first
|
59
|
+
@phone = res['phone'].first
|
60
|
+
@fax = res['fax'].first
|
61
|
+
end
|
62
|
+
|
63
|
+
def save
|
64
|
+
set_info
|
65
|
+
end
|
66
|
+
# Modifies a client.
|
67
|
+
def set_info(client_id = nil)
|
68
|
+
args = { :user_key => @user.user_key }
|
69
|
+
if !client_id.nil?
|
70
|
+
args[:client_id] = client_id
|
71
|
+
else
|
72
|
+
args[:client_id] = @id unless @id.nil?
|
73
|
+
end
|
74
|
+
args[:status] = @status unless @status.nil?
|
75
|
+
args[:manager_id] = @manager_id unless @manager_id.nil?
|
76
|
+
args[:parent_id] = @parent_id unless @parent_id.nil?
|
77
|
+
args[:contact_id] = @contact_id unless @contact_id.nil?
|
78
|
+
args[:company_name] = @company_name unless @company_name.nil?
|
79
|
+
args[:address1] = @address1 unless @address1.nil?
|
80
|
+
args[:address2] = @address2 unless @address2.nil?
|
81
|
+
args[:city] = @city unless @city.nil?
|
82
|
+
args[:province_id] = @province_id unless @province_id.nil?
|
83
|
+
args[:postal_code] = @postal_code unless @postal_code.nil?
|
84
|
+
args[:country_id] = @country_id unless @country_id.nil?
|
85
|
+
args[:website] = @website unless @website.nil?
|
86
|
+
args[:phone] = @phone unless @phone.nil?
|
87
|
+
args[:fax] = @fax unless @fax.nil?
|
88
|
+
@user.session.request("CakeMail::API::ClassClient", "SetInfo", args)
|
89
|
+
end
|
90
|
+
|
91
|
+
class << self
|
92
|
+
# Creates a new client.
|
93
|
+
#
|
94
|
+
# Arguments :
|
95
|
+
# * args = { :user => required, :company_name => required, :admin_email => required, :admin_first_name => required,
|
96
|
+
# :admin_last_name => required, :admin_password => required, :contact_email => required, :contact_first_name => required,
|
97
|
+
# :contact_last_name => required, :contact_password => required, :parent_id => optional, :currency => optional, :address1 => optional,
|
98
|
+
# :address2 => optionall, :city => optional, :province_id => optional, :country_id => optional, :postal_code => optional,
|
99
|
+
# :website => optional, :phone => optional, :fax => optional, :admin_title => optional, :admin_office_phone => required,
|
100
|
+
# :admin_mobile_phone => optional, :admin_language => optional, :contact_title => optional, :contact_language => optional,
|
101
|
+
# :contact_timezone_id => optional, :contact_office_phone => optional, :contact_mobile_phone => optional }
|
102
|
+
def create(args)
|
103
|
+
raise ArgumentError if args.nil? or args[:user].nil? or args[:company_name].nil? or args[:admin_email].nil? or
|
104
|
+
args[:admin_first_name].nil? or args[:admin_last_name].nil? or args[:admin_password].nil? or args[:contact_email].nil? or
|
105
|
+
args[:contact_first_name].nil? or args[:contact_last_name].nil? or args[:contact_password].nil?
|
106
|
+
options = { :company_name => args[:company_name], :admin_email => args[:admin_email], :admin_first_name => args[:admin_first_name],
|
107
|
+
:admin_last_name => args[:admin_last_name], :admin_password => args[:admin_password],
|
108
|
+
:admin_password_confirmation => args[:admin_password_confirmation], :contact_email => args[:contact_email],
|
109
|
+
:contact_first_name => args[:contact_first_name], :contact_last_name => args[:contact_last_name],
|
110
|
+
:contact_password => args[:contact_password], :contact_password_confirmation => args[:contact_password_confirmation] }
|
111
|
+
options[:parent_id] = args[:parent_id] unless args[:parent_id].nil?
|
112
|
+
options[:currency] = args[:currency] unless args[:currency].nil?
|
113
|
+
options[:address1] = args[:address1] unless args[:address1].nil?
|
114
|
+
options[:address2] = args[:address2] unless args[:address2].nil?
|
115
|
+
options[:city] = args[:city] unless args[:city].nil?
|
116
|
+
options[:province_id] = args[:province_id] unless args[:province_id].nil?
|
117
|
+
options[:postal_code] = args[:postal_code] unless args[:postal_code].nil?
|
118
|
+
options[:country_id] = args[:country_id] unless args[:country_id].nil?
|
119
|
+
options[:website] = args[:website] unless args[:website].nil?
|
120
|
+
options[:phone] = args[:phone] unless args[:phone].nil?
|
121
|
+
options[:fax] = args[:fax] unless args[:fax].nil?
|
122
|
+
options[:admin_title] = args[:admin_title] unless args[:admin_title].nil?
|
123
|
+
options[:admin_office_phone] = args[:admin_office_phone] unless args[:admin_office_phone].nil?
|
124
|
+
options[:admin_mobile_phone] = args[:admin_mobile_phone] unless args[:admin_mobile_phone].nil?
|
125
|
+
options[:admin_language] = args[:admin_language] unless args[:admin_language].nil?
|
126
|
+
options[:admin_timezone_id] =args[:admin_timezone_id] unless args[:admin_timezone_id].nil?
|
127
|
+
options[:admin_language] = args[:admin_language] unless args[:admin_language].nil?
|
128
|
+
options[:contact_title] = args[:contact_title] unless args[:contact_title].nil?
|
129
|
+
options[:contact_language] = args[:contact_language] unless args[:contact_language].nil?
|
130
|
+
options[:contact_timezone_id] = args[:contact_timezone_id] unless args[:contact_timezone_id].nil?
|
131
|
+
options[:contact_office_phone] = args[:contact_office_phone] unless args[:contact_office_phone].nil?
|
132
|
+
options[:contact_mobile_phone] = args[:contact_mobile_phone] unless args[:contact_mobile_phone].nil?
|
133
|
+
res = args[:user].session.request("CakeMail::API::ClassClient", "Create", options)
|
134
|
+
res = args[:user].session.request("CakeMail::API::ClassClient", "Activate", { :confirmation => res['confirmation'].first })
|
135
|
+
return Client.new(id, args[:user])
|
136
|
+
end
|
137
|
+
# Retrieves the list of clients.
|
138
|
+
#
|
139
|
+
# Arguments :
|
140
|
+
# * args = { :user => required, :count => optional, :status => optional, :limit => optional, :offset => optional }
|
141
|
+
def get_list(args)
|
142
|
+
raise ArgumentError if args.nil? or args[:user].nil?
|
143
|
+
options = { :user_key => args[:user].user_key }
|
144
|
+
options[:count] = args[:count] unless args[:count].nil?
|
145
|
+
options[:status] = args[:status] unless args[:status].nil?
|
146
|
+
options[:limit] = args[:limit] unless args[:limit].nil?
|
147
|
+
options[:offset] = args[:offset] unless args[:offset].nil?
|
148
|
+
res = args[:user].session.request("CakeMail::API::ClassClient", "GetList", options)
|
149
|
+
if !args[:count].nil?
|
150
|
+
return res['count'].first
|
151
|
+
end
|
152
|
+
return res['client']
|
153
|
+
end
|
154
|
+
# Returns the list with the supported timezones.
|
155
|
+
def get_timezones(user)
|
156
|
+
res = user.session.request("CakeMail::API::ClassClient", "GetTimezones", {})
|
157
|
+
res['timezone']
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module CakeMail
|
2
|
+
module API
|
3
|
+
class ClassCountry < CakeMail::ServiceClass
|
4
|
+
method :name => "GetList"
|
5
|
+
method :name => "GetProvinces", :requires => [ :country_id, :user_key ]
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Country
|
10
|
+
class << self
|
11
|
+
# Retrieves the list of countries.
|
12
|
+
def get_list(session)
|
13
|
+
res = session.request("CakeMail::API::ClassCountry", "GetList", { })
|
14
|
+
return res['country']
|
15
|
+
end
|
16
|
+
# Retrieves the list of provinces for a country (only us and ca for the moment).
|
17
|
+
def get_provinces(country_id, user)
|
18
|
+
res = session.request("CakeMail::API::ClassCountry", "GetProvinces", { :country_id => country_id, :user_key => user.user_key })
|
19
|
+
return res['province']
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# Permission Groups are a set of permissions which allow the Administrator to define User permission profiles.
|
2
|
+
#
|
3
|
+
# A single User may be assigned to multiple Permission Groups, and is assigned the cumulative permissions of all groups.
|
4
|
+
module CakeMail
|
5
|
+
module API
|
6
|
+
class ClassGroup < CakeMail::ServiceClass
|
7
|
+
method :name => "Create", :requires => [ :name, :user_key ], :optional => [ :client_id ]
|
8
|
+
method :name => "Delete", :requires => [ :group_id, :user_key ]
|
9
|
+
method :name => "GetInfo", :requires => [ :group_id, :user_key ], :optional => [ :client_id ]
|
10
|
+
method :name => "SetInfo", :requires => [ :group_id, :user_key ], :optional => [ :client_id, :name ], :custom_args_xml => [
|
11
|
+
Proc.new do |builder, args|
|
12
|
+
unless args[:data].nil?
|
13
|
+
args[:data].each { |r| builder.data({ :type => r[:type] }, r[:value]) }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
]
|
17
|
+
method :name => "GetList", :requires => [ :user_key ], :optional => [ :client_id, :limit, :offset, :count ]
|
18
|
+
method :name => "AddUser", :requires => [ :group_id, :user_id ], :optional => [ :client_id ]
|
19
|
+
method :name => "RemoveUser", :requires => [ :group_id, :user_id, :user_key ], :optional => [ :client_id ]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Group
|
24
|
+
attr_reader :permission
|
25
|
+
attr_accessor :id, :client_id, :name
|
26
|
+
|
27
|
+
def initialize(id, user)
|
28
|
+
@user = user
|
29
|
+
@id = id
|
30
|
+
get_info
|
31
|
+
end
|
32
|
+
# Adds a user into a group.
|
33
|
+
def add_user(user_id, client_id = nil)
|
34
|
+
args = { :user_id => user_id, :group_id => @id, :user_key => @user.user_key }
|
35
|
+
args[:client_id] = client_id unless client_id.nil?
|
36
|
+
@user.session.request("CakeMail::API::ClassGroup", "AddUser", args)
|
37
|
+
end
|
38
|
+
# Removes a user from a group.
|
39
|
+
def remove_user(user_id, client_id = nil)
|
40
|
+
args = { :user_id => user_id, :group_id => @id, :user_key => @user.user_key }
|
41
|
+
args[:client_id] = client_id unless client_id.nil?
|
42
|
+
@user.session.request("CakeMail::API::ClassGroup", "RemoveUser", args)
|
43
|
+
end
|
44
|
+
# Deletes a group.
|
45
|
+
def delete(client_id = nil)
|
46
|
+
args = { :group_id => @id, :user_key => @user.user_key }
|
47
|
+
args[:client_id] = client_id unless client_id.nil?
|
48
|
+
@user.session.request("CakeMail::API::ClassGroup", "Delete", args)
|
49
|
+
self.freeze
|
50
|
+
end
|
51
|
+
# Returns information about a group.
|
52
|
+
def get_info(id = @id, client_id = nil)
|
53
|
+
args = { :group_id => @id, :user_key => @user.user_key }
|
54
|
+
args[:client_id] = client_id unless client_id.nil?
|
55
|
+
res = @user.session.request("CakeMail::API::ClassCampaign", "GetInfo", args)
|
56
|
+
@id = res['id'].first
|
57
|
+
@name = res['name'].first
|
58
|
+
@permission = res['permission']
|
59
|
+
end
|
60
|
+
|
61
|
+
def save
|
62
|
+
self.setinfo
|
63
|
+
end
|
64
|
+
# Modifies a group.
|
65
|
+
#
|
66
|
+
# Custom argument:
|
67
|
+
# * data = [ { :type => "CLASS_USER_CREATE", :value => "1" }, { :type => "CLASS_USER_SET_INFO", :value => "0" }, ... ]
|
68
|
+
def set_info(data = nil)
|
69
|
+
args = { :group_id => @id, :user_key => @user.user_key }
|
70
|
+
args[:client_id] = client_id unless client_id.nil?
|
71
|
+
args[:name] = name unless name.nil?
|
72
|
+
args[:data] = date unless data.nil?
|
73
|
+
res = @user.session.request("CakeMail::API::ClassCampaign", "SetInfo", args)
|
74
|
+
end
|
75
|
+
|
76
|
+
class << self
|
77
|
+
# Creates a group.
|
78
|
+
def create(user, name, client_id = nil)
|
79
|
+
args = { :name => name, :user_key => user.user_key }
|
80
|
+
args[:client_id] = client_id unless client_id.nil?
|
81
|
+
res = user.session.request("CakeMail::API::ClassGroup", "Create", args)
|
82
|
+
Group.new(user, { :id => res['id'].first })
|
83
|
+
end
|
84
|
+
# Retrieves the list of groups.
|
85
|
+
#
|
86
|
+
# Arguments :
|
87
|
+
# * args = { :user => required, :client_id => optional, :count => optional, :limit => optional, :offset => optional }
|
88
|
+
def get_list(args)
|
89
|
+
options = { :user_key => args[:user].user_key }
|
90
|
+
options[:count] = args[:count] unless args[:count].nil?
|
91
|
+
options[:client_id] = args[:client_id] unless args[:client_id].nil?
|
92
|
+
options[:limit] = args[:limit] unless args[:limit].nil?
|
93
|
+
options[:offset] = args[:offset] unless args[:offset].nil?
|
94
|
+
res = args[:user].session.request("CakeMail::API::ClassCampaign", "GetList", options)
|
95
|
+
if !args[:count].nil?
|
96
|
+
return res['count'].first
|
97
|
+
end
|
98
|
+
return res['campaign']
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,336 @@
|
|
1
|
+
# A List is a collection of subscribers (or List Members, or Records). Each subscriber or List Member is uniquely identified by their email
|
2
|
+
# address, and may include an unlimited amount of Fields containing demographic information associated to each email address.
|
3
|
+
#
|
4
|
+
# A Contact List may have the following status:
|
5
|
+
#
|
6
|
+
# * Active => Displayed on the main page of the Contact Lists tab and is available for Mailings
|
7
|
+
# * Archived => Displayed on the Archived page of the Contact Lists tab and unavailable for Mailings
|
8
|
+
#
|
9
|
+
# List Member or Subscriber
|
10
|
+
#
|
11
|
+
# A List Member is an individual included in a Contact List. List Member is uniquely identified by their email address, and may include an
|
12
|
+
# unlimited amount of Fields containing demographic information associated to each email address. Any individual email address may only be
|
13
|
+
# included once in a Contact List. An individual email address may be included in an unlimited number of Contact Lists.
|
14
|
+
#
|
15
|
+
# A List Member my have the following status:
|
16
|
+
#
|
17
|
+
# * Active => Members who are available to receive Mailings
|
18
|
+
# * Unsubscribed => Members that have requested not to be sent future Mailings
|
19
|
+
# * Bounced => Members whose email was identified as invalid
|
20
|
+
# * Deleted => Members removed by a User
|
21
|
+
# * Pending => Members who subscribed to a Double Opt-In List, and that have yet to confirm their Active subscription status
|
22
|
+
#
|
23
|
+
# Segmentation and Sub-lists
|
24
|
+
#
|
25
|
+
# Segmentation is the process of dividing a Contact List into Sub-Lists (Segments). Segments can be defined by any criteria within Contact
|
26
|
+
# List Field values. Segments can be defined by a Field starting or ending with, containing, equal or not equal to, greater or less than,
|
27
|
+
# any given value.
|
28
|
+
module CakeMail
|
29
|
+
module API
|
30
|
+
class ClassList < CakeMail::ServiceClass
|
31
|
+
method :name => "AddTestEmail", :requires => [ :list_id, :email, :user_key ]
|
32
|
+
method :name => "Create", :requires => [ :name, :sender_name, :sender_email, :user_key ], :custom_args_xml => [
|
33
|
+
Proc.new do |builder, args|
|
34
|
+
unless args[:data].nil?
|
35
|
+
args[:data].each { |r| builder.data({ :type => r[:type] }, r[:name]) }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
]
|
39
|
+
method :name => "CreateSublist", :requires => [ :sublist_name, :list_id, :user_key ], :custom_args_xml => [
|
40
|
+
Proc.new do |builder, args|
|
41
|
+
unless args[:data].nil?
|
42
|
+
args[:data].each { |r| builder.data({ :type => r[:type] }, r[:value]) }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
]
|
46
|
+
method :name => "Delete", :requires => [ :list_id, :user_key ]
|
47
|
+
method :name => "DeleteEmail", :requires => [ :list_id, :email, :user_key ]
|
48
|
+
method :name => "DeleteRecord", :requires => [ :list_id, :record_id, :user_key ]
|
49
|
+
method :name => "DeleteSublist", :requires => [ :sublist_id, :user_key ]
|
50
|
+
method :name => "DeleteTestEmail", :requires => [ :list_id, :test_email_id, :user_key]
|
51
|
+
method :name => "EditStructure", :requires => [ :list_id, :action, :field, :user_key ], :optional => [ :type ]
|
52
|
+
method :name => "GetFields", :requires => [ :list_id, :user_key ]
|
53
|
+
method :name => "GetInfo", :requires => [ :list_id, :user_key ]
|
54
|
+
method :name => "GetList", :requires => [ :user_key ], :optional => [ :status, :limit, :offset, :count ]
|
55
|
+
method :name => "GetRecord", :requires => [ :list_id, :record_id, :user_key ], :optional => [ :record_key ]
|
56
|
+
method :name => "GetSublists", :requires => [ :list_id, :user_key ]
|
57
|
+
method :name => "GetTestEmails", :requires => [ :list_id, :user_key ]
|
58
|
+
method :name => "Import", :requires => [ :list_id, :user_key ], :custom_args_xml => [
|
59
|
+
Proc.new do |builder, args|
|
60
|
+
unless args[:record].nil?
|
61
|
+
args[:record].each do |r|
|
62
|
+
builder.record do |rec_builder|
|
63
|
+
r[:data].each { |d| rec_builder.data({ :type => d[:type] }, d[:value]) }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
]
|
69
|
+
method :name => "Search", :requires => [ :list_id, :user_key ], :optional => [ :limit, :offset, :count ], :custom_args_xml => [
|
70
|
+
Proc.new do |builder, args|
|
71
|
+
unless args[:data].nil?
|
72
|
+
args[:data].each { |r| builder.data({ :type => r[:type] }, r[:value]) }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
]
|
76
|
+
method :name => "SetInfo", :requires => [ :list_id, :user_key ], :optional => [ :sublist_id, :name, :query, :language, :status,
|
77
|
+
:policy, :sender_name, :sender_email, :forward_page, :goto_oi, :goto_di, :goto_oo ]
|
78
|
+
method :name => "Show", :requires => [ :list_id, :status, :user_key ], :optional => [ :bounce_type, :limit, :offset, :count ]
|
79
|
+
method :name => "SubscribeEmail", :requires => [ :list_id, :email, :user_key ], :optional => [ :no_triggers ], :custom_args_xml => [
|
80
|
+
Proc.new do |builder, args|
|
81
|
+
unless args[:data].nil?
|
82
|
+
args[:data].each { |r| builder.data({ :type => r[:type] }, r[:value]) }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
]
|
86
|
+
method :name => "TestSublist", :requires => [ :list_id, :user_key ], :custom_args_xml => [
|
87
|
+
Proc.new do |builder, args|
|
88
|
+
unless args[:data].nil?
|
89
|
+
args[:data].each { |r| builder.data({ :type => r[:type] }, r[:value]) }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
]
|
93
|
+
method :name => "UnsubscribeEmail", :requires => [ :list_id, :email, :user_key ]
|
94
|
+
method :name => "UpdateRecord", :requires => [ :list_id, :record_id, :user_key ], :custom_args_xml => [
|
95
|
+
Proc.new do |builder, args|
|
96
|
+
unless args[:data].nil?
|
97
|
+
args[:data].each { |r| builder.data({ :type => r[:type] }, r[:value]) }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
class List
|
105
|
+
attr_reader :created_on, :pending, :active, :bounced, :unsubscribes, :id
|
106
|
+
attr_accessor :sublist_id, :name, :query, :language, :status, :policy, :sender_name, :sender_email, :forward_page, :goto_oi,
|
107
|
+
:goto_di, :goto_oo
|
108
|
+
|
109
|
+
def initialize(id, user)
|
110
|
+
@user = user
|
111
|
+
@id = id
|
112
|
+
get_info
|
113
|
+
end
|
114
|
+
# Deletes a list.
|
115
|
+
def delete
|
116
|
+
@user.session.request("CakeMail::API::ClassList", "Delete", { :list_id => @id, :user_key => @user.user_key })
|
117
|
+
self.freeze
|
118
|
+
end
|
119
|
+
# Retrieves informations about a list.
|
120
|
+
def get_info(id = @id)
|
121
|
+
res = @user.session.request("CakeMail::API::ClassList", "GetInfo", { :list_id => id, :user_key => @user.user_key })
|
122
|
+
res = res['list'].first
|
123
|
+
@active = res['active'].first
|
124
|
+
@bounced = res['bounced'].first
|
125
|
+
@created_on = res['created_on'].first
|
126
|
+
@deleted = res['deleted'].first
|
127
|
+
@forward_page = res['forward_page'].first
|
128
|
+
@goto_di = res['goto_di'].first
|
129
|
+
@goto_oi = res['goto_oi'].first
|
130
|
+
@goto_oo = res['goto_oo'].first
|
131
|
+
@langauge = res['language'].first
|
132
|
+
@list_id = res['id'].first
|
133
|
+
@name = res['name'].first
|
134
|
+
@pending = res['pending'].first
|
135
|
+
@policy = res['policy'].first
|
136
|
+
@sender_email = res['sender_email'].first
|
137
|
+
@sender_name = res['sender_name'].first
|
138
|
+
@status = res['status'].first
|
139
|
+
@unsubscribed = res['unsubscribed'].first
|
140
|
+
end
|
141
|
+
|
142
|
+
def save
|
143
|
+
self.set_info
|
144
|
+
end
|
145
|
+
# Modifies the parameters of a list.
|
146
|
+
def set_info
|
147
|
+
args = { :list_id => @id, :user_key => @user.user_key }
|
148
|
+
args[:sublist_id] = @sublist_id unless @sublist_id.nil? or @sublist_id == '0'
|
149
|
+
args[:name] = @name unless name.nil?
|
150
|
+
args[:query] = @query unless @query.nil?
|
151
|
+
args[:language] = @language unless @language.nil?
|
152
|
+
args[:status] = @status unless @status.nil?
|
153
|
+
args[:policy] = @policy unless @policy.nil?
|
154
|
+
args[:sender_name] = @sender_name unless @sender_name.nil?
|
155
|
+
args[:sender_email] = @sender_email unless @sender_email.nil?
|
156
|
+
args[:forward_page] = @forward_page unless @forward_page.nil?
|
157
|
+
args[:goto_oi] = @goto_oi unless @goto_oi.nil?
|
158
|
+
args[:goto_di] = @goto_di unless @goto_di.nil?
|
159
|
+
args[:goto_oo] = @goto_oo unless @goto_oo.nil?
|
160
|
+
res = @user.session.request("CakeMail::API::ClassList", "SetInfo", args)
|
161
|
+
end
|
162
|
+
# Modifies the structure of a list.
|
163
|
+
def edit_structure(action, field, type = nil)
|
164
|
+
args = { :list_id => @id, :user_key => @user.user_key, :action => action, :field => field }
|
165
|
+
args[:type] = type unless type.nil?
|
166
|
+
res = @user.session.request("CakeMail::API::ClassList", "EditStructure", args)
|
167
|
+
end
|
168
|
+
# Returns the fields of the list.
|
169
|
+
def get_fields
|
170
|
+
res = @user.session.request("CakeMail::API::ClassList", "GetFields", { :list_id => @id, :user_key => @user.user_key })
|
171
|
+
res['data']
|
172
|
+
end
|
173
|
+
# Import a list of emails into the list.
|
174
|
+
#
|
175
|
+
# Custom argument :
|
176
|
+
# * record = [ { :data => [ { :type => 'type', :value => 'value' }, { :type => 'type', :value => 'value' }, ... ] },
|
177
|
+
# { :data => [ { :type => 'type', :value => 'value' }, { :type => 'type', :value => 'value' }, ... ] }, ... ]
|
178
|
+
def import(record)
|
179
|
+
res = @user.session.request("CakeMail::API::ClassList", "Import", { :list_id => @id, :record => record, :user_key => @user.user_key })
|
180
|
+
return res['record']
|
181
|
+
end
|
182
|
+
# Displays the list.
|
183
|
+
#
|
184
|
+
# Argument :
|
185
|
+
# * args = { :status => required, bounce_type => optional, limit => optional, offset => optional, count => optional }
|
186
|
+
def show(args)
|
187
|
+
raise ArgumentError if args.nil? or args[:status].nil?
|
188
|
+
options = { :list_id => @id, :status => args[:status], :user_key => @user.user_key }
|
189
|
+
options[:bounce_type] = args[:bounce_type] unless args[:bounce_type].nil?
|
190
|
+
options[:limit] = args[:limit] unless args[:limit].nil?
|
191
|
+
options[:offset] = args[:offset] unless args[:offset].nil?
|
192
|
+
options[:count] = args[:count] unless args[:count].nil?
|
193
|
+
res = @user.session.request("CakeMail::API::ClassList", "Show", options)
|
194
|
+
if !args[:count].nil?
|
195
|
+
return res['count']
|
196
|
+
end
|
197
|
+
return res['record']
|
198
|
+
end
|
199
|
+
# Searches for one or more records matching a set of conditions. The search is performed using the equivalent of LIKE '%text%' in SQL.
|
200
|
+
def search(args)
|
201
|
+
raise ArgumentError if args.nil? or args[:data].nil?
|
202
|
+
options = { :data => args[:data], :list_id => @id, :user_key => @user.user_key }
|
203
|
+
options[:limit] = args[:limit] unless args[:limit].nil?
|
204
|
+
options[:offset] = args[:offset] unless args[:offset].nil?
|
205
|
+
options[:count] = args[:count] unless args[:count].nil?
|
206
|
+
res = @user.session.request("CakeMail::API::ClassList", "Search", options)
|
207
|
+
if !args[:count].nil?
|
208
|
+
return res['count']
|
209
|
+
end
|
210
|
+
return res['record']
|
211
|
+
end
|
212
|
+
# Subscribes an email into a list. This function, by default, activates the opt-in and douopt-in triggers. Important: before using this
|
213
|
+
# function, the list's policy must be accepted otherwise an error will occur!
|
214
|
+
#
|
215
|
+
# Custom argument:
|
216
|
+
# * data = [ { :type => "last_name, :value => "Doe" }, ... ]
|
217
|
+
def subscribe_email(email, no_triggers = nil, data = nil)
|
218
|
+
args = { :email => email, :list_id => @id, :user_key => @user.user_key }
|
219
|
+
args[:no_triggers] = no_triggers unless no_triggers.nil?
|
220
|
+
args[:data] = data unless data.nil?
|
221
|
+
res = @user.session.request("CakeMail::API::ClassList", "SubscribeEmail", args)
|
222
|
+
return res['record_id']
|
223
|
+
end
|
224
|
+
# Unsubscribes an email from a list. This function activates the opt-out triggers.
|
225
|
+
def unsubscribe_email(email)
|
226
|
+
res = @user.session.request("CakeMail::API::ClassList", "UnsubscribeEmail", { :email => email, :list_id => @id,
|
227
|
+
:user_key => @user.user_key })
|
228
|
+
end
|
229
|
+
# Deletes an email from a list.
|
230
|
+
def delete_email(email)
|
231
|
+
res = @user.session.request("CakeMail::API::ClassList", "DeleteEmail", { :email => email, :list_id => @id,
|
232
|
+
:user_key => @user.user_key })
|
233
|
+
end
|
234
|
+
# Deletes a record from a list using the record's id.
|
235
|
+
def delete_record(record_id)
|
236
|
+
res = @user.session.request("CakeMail::API::ClassList", "DeleteRecord", { :record_id => record_id, :list_id => @id,
|
237
|
+
:user_key => @user.user_key })
|
238
|
+
end
|
239
|
+
# Retrieves information for a record from a list.
|
240
|
+
def get_record(record_id, record_key = nil)
|
241
|
+
args = { :record_id => record_id, :list_id => @id, :user_key => @user.user_key }
|
242
|
+
args[:record_key] = record_key unless record_key.nil?
|
243
|
+
res = @user.session.request("CakeMail::API::ClassList", "GetRecord", args)
|
244
|
+
return { :id => res['id'].first, :status => res['status'].first, :email => res['email'].first, :data => res['data'] }
|
245
|
+
end
|
246
|
+
# Modifies a record into a list.
|
247
|
+
def update_record(record_id, data, record_key = nil)
|
248
|
+
args = { :data => data, :record_id => record_id, :list_id => @id, :user_key => @user.user_key }
|
249
|
+
args[:record_key] = record_key unless record_key.nil?
|
250
|
+
res = @user.session.request("CakeMail::API::ClassList", "UpdateRecord", args)
|
251
|
+
end
|
252
|
+
# Adds a test email to a list.
|
253
|
+
def add_test_email(email)
|
254
|
+
res = @user.session.request("CakeMail::API::ClassList", "AddTestEmail", { :email => email, :list_id => @id,
|
255
|
+
:user_key => @user.user_key })
|
256
|
+
end
|
257
|
+
# Retrieves the test emails for a list.
|
258
|
+
def get_test_emails
|
259
|
+
res = @user.session.request("CakeMail::API::ClassList", "GetTestEmails", { :list_id => @id,
|
260
|
+
:user_key => @user.user_key })
|
261
|
+
return res['test_email']
|
262
|
+
end
|
263
|
+
# Deletes a test email of a list.
|
264
|
+
def delete_test_email(test_email_id)
|
265
|
+
res = @user.session.request("CakeMail::API::ClassList", "DeleteTestEmail", { :test_email_id => test_email_id, :list_id => @id,
|
266
|
+
:user_key => @user.user_key })
|
267
|
+
end
|
268
|
+
# Creates a sublist from list. It supports up to 5 conditions for creating the sublist. Each condition is defined by a field, a
|
269
|
+
# 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
|
270
|
+
# specified, the OR option will be used by default.
|
271
|
+
#
|
272
|
+
# Custom argument:
|
273
|
+
# * data = [ { :type => "0_field", :value => "email" }, { :type => "0_function", :value => "LIKE" },
|
274
|
+
# { :type => "0_value", :value => "test" }, ... ]
|
275
|
+
def create_sublist(data, sublist_name)
|
276
|
+
res = @user.session.request("CakeMail::API::ClassList", "CreateSublist", { :data => data, :list_id => @id,
|
277
|
+
:user_key => @user.user_key, :sublist_name => sublist_name })
|
278
|
+
return res['sublist_id']
|
279
|
+
end
|
280
|
+
# Deletes a sublist.
|
281
|
+
def delete_sublist(sublist_id)
|
282
|
+
res = @user.session.request("CakeMail::API::ClassList", "DeleteSublist", { :sublist_id => sublist_id,
|
283
|
+
:user_key => @user.user_key })
|
284
|
+
end
|
285
|
+
# Tests a sublist.
|
286
|
+
#
|
287
|
+
# Custom argument:
|
288
|
+
# * data = [ { :type => "0_field", :value => "email" }, { :type => "0_function", :value => "LIKE" },
|
289
|
+
# { :type => "0_value", :value => "test" }, ... ]
|
290
|
+
def test_sublist(data)
|
291
|
+
res = @user.session.request("CakeMail::API::ClassList", "TestSublist", { :data => data, :list_id => @id,
|
292
|
+
:user_key => @user.user_key })
|
293
|
+
return res['record']
|
294
|
+
end
|
295
|
+
# Retrieves the sublists for a list.
|
296
|
+
def get_sublists
|
297
|
+
res = @user.session.request("CakeMail::API::ClassList", "GetSublists", { :list_id => @id,
|
298
|
+
:user_key => @user.user_key })
|
299
|
+
return res['sublist']
|
300
|
+
end
|
301
|
+
|
302
|
+
class << self
|
303
|
+
# Creates a list.
|
304
|
+
#
|
305
|
+
# Arguments :
|
306
|
+
# * args = { user => required, :name => required, :sender_name => required, :sender_email, :data => optional/custom }
|
307
|
+
# Custom argument:
|
308
|
+
# * :data => [ { :type => "text", :value => "city" }, { :type => "integer", :value => "age" }, ... ]
|
309
|
+
def create(args)
|
310
|
+
raise ArgumentError if args.nil? or args[:user].nil? or args[:name].nil? or args[:sender_email].nil? or args[:sender_name].nil?
|
311
|
+
options = { :user_key => args[:user].user_key, :name => args[:name], :sender_name => args[:sender_name],
|
312
|
+
:sender_email => args[:sender_email] }
|
313
|
+
options[:data] = args[:data] unless args[:data].empty?
|
314
|
+
res = args[:user].session.request("CakeMail::API::ClassList", "Create", options)
|
315
|
+
List.new(res['id'].first, args[:user])
|
316
|
+
end
|
317
|
+
# Retrieves the list of lists.
|
318
|
+
#
|
319
|
+
# Arguments :
|
320
|
+
# * args = { user => required, status => optional, :limit => optional, :offset => optional, :count => optional }
|
321
|
+
def get_list(args)
|
322
|
+
raise ArgumentError if args.nil? or args[:user].nil?
|
323
|
+
options = { :user_key => args[:user].user_key }
|
324
|
+
options[:status] = args[:status] unless args[:status].nil?
|
325
|
+
options[:limit] = args[:limit] unless args[:limit].nil?
|
326
|
+
options[:offset] = args[:offset] unless args[:offset].nil?
|
327
|
+
options[:count] = args[:count] unless args[:count].nil?
|
328
|
+
res = args[:user].session.request("CakeMail::API::ClassList", "GetList", options)
|
329
|
+
if !args[:count].nil?
|
330
|
+
return res['count'].first
|
331
|
+
end
|
332
|
+
return res['list']
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
336
|
+
end
|