ruby-cakemail 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -0,0 +1,215 @@
|
|
1
|
+
# A Mailing is specific email content (From Name, From Email, Subject, Body) sent to a specific list or a sub-list..
|
2
|
+
# Mailings may have the following status:
|
3
|
+
# * Incomplete => Mailing that is not fully prepared to be delivered
|
4
|
+
# * Scheduled => Mailing that is ready and scheduled to be delivered
|
5
|
+
# * Delivering => Mailing in process of being delivered
|
6
|
+
# * Delivered => Mailing has been delivered
|
7
|
+
# * Deleted => Please note: Only an Incomplete Mailing can be deleted
|
8
|
+
# A Mailing in process of being delivered can be suspended and resumed at any time.
|
9
|
+
module CakeMail
|
10
|
+
module API
|
11
|
+
class ClassMailing < CakeMail::ServiceClass
|
12
|
+
method :name => "Create", :requires => [ :campaign_id, :name, :user_key ], :optional => [ :encoding ]
|
13
|
+
method :name => "Delete", :requires => [ :mailing_id, :user_key ]
|
14
|
+
method :name => "GetEmailMessage", :requires => [ :mailing_id, :user_key ]
|
15
|
+
method :name => "GetHtmlMessage", :requires => [ :mailing_id, :user_key ]
|
16
|
+
method :name => "GetInfo", :requires => [ :mailing_id, :user_key ]
|
17
|
+
method :name => "GetLinksLog", :requires => [ :mailing_id, :user_key ], :optional => [ :start_date, :end_date ]
|
18
|
+
method :name => "GetList", :requires => [ :campaign_id, :user_key ],
|
19
|
+
:optional => [ :status, :campaign_id, :list_id, :limit, :offset, :count ]
|
20
|
+
method :name => "GetLog", :requires => [ :mailing_id, :user_key ], :optional => [ :action, :record_id, :start_date, :end_date,
|
21
|
+
:date, :extra, :limit, :offset, :count, :uniques ]
|
22
|
+
method :name => "GetStats", :requires => [ :mailing_id, :information, :user_key ]
|
23
|
+
method :name => "GetTextMessage", :requires => [ :mailing_id, :user_key ]
|
24
|
+
method :name => "Resume", :requires => [ :mailing_id, :user_key ]
|
25
|
+
method :name => "Schedule", :requires => [ :mailing_id, :user_key ], :optional => [ :date ]
|
26
|
+
method :name => "SendTestEmail", :requires => [ :mailing_id, :test_email, :test_type, :user_key ]
|
27
|
+
method :name => "SetInfo", :requires => [ :mailing_id, :user_key ], :optional => [ :campaign_id, :list_id, :sublist_id, :next_step,
|
28
|
+
:encoding, :clickthru_html, :clickthru_text, :opening_stats, :unsub_bottom_link, :name, :subject,
|
29
|
+
:sender_name, :sender_email, :html_message, :text_message, :campaign_id ]
|
30
|
+
method :name => "Suspend", :requires => [ :mailing_id, :user_key ]
|
31
|
+
method :name => "Unschedule", :requires => [ :mailing_id, :user_key ]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Mailing
|
36
|
+
attr_reader :id, :active_emails, :status, :suspended, :created_on, :scheduled_on, :scheduled_for, :in_queue, :out_queue, :recipients
|
37
|
+
attr_accessor :campaign_id, :list_id, :sublist_id, :next_step, :encoding, :clickthru_html, :clickthru_text, :opening_stats,
|
38
|
+
:unsub_bottom_link, :name, :subject, :sender_name, :sender_email, :html_message, :text_message, :campaign_id
|
39
|
+
|
40
|
+
def initialize(campaign, id)
|
41
|
+
@campaign = campaign
|
42
|
+
@id = id
|
43
|
+
get_info
|
44
|
+
end
|
45
|
+
# Deletes a mailing.
|
46
|
+
def delete
|
47
|
+
@campaign.user.session.request("CakeMail::API::ClassMailing", "Delete", { :mailing_id => @id, :user_key => @campaign.user.user_key })
|
48
|
+
self.freeze
|
49
|
+
end
|
50
|
+
# Returns the subject and the message of the mailing.
|
51
|
+
def get_email_message
|
52
|
+
@campaign.user.session.request("CakeMail::API::ClassMailing", "GetEmailMessage", { :mailing_id => @id,
|
53
|
+
:user_key => @campaign.user.user_key })
|
54
|
+
@subject = res['subject'].first
|
55
|
+
@message = res['message'].first
|
56
|
+
end
|
57
|
+
# Retrieves the html message of a mailing.
|
58
|
+
def get_html_message
|
59
|
+
@campaign.user.session.request("CakeMail::API::ClassMailing", "GetHtmlMessage", { :mailing_id => @id,
|
60
|
+
:user_key => @campaign.user.user_key })
|
61
|
+
@html_message = res['html_message'].first
|
62
|
+
end
|
63
|
+
# Retrieves the text message of a mailing.
|
64
|
+
def get_text_message
|
65
|
+
@campaign.user.session.request("CakeMail::API::ClassMailing", "GetTextMessage", { :mailing_id => @id,
|
66
|
+
:user_key => @campaign.user.user_key })
|
67
|
+
@text_message = res['text_message'].first
|
68
|
+
end
|
69
|
+
# Retrieves the setting for a mailing.
|
70
|
+
def get_info(id = @id)
|
71
|
+
res = @campaign.user.session.request("CakeMail::API::ClassMailing", "GetInfo", { :mailing_id => @id,
|
72
|
+
:user_key => @campaign.user.user_key })
|
73
|
+
@active_emails = res['active_emails'].first
|
74
|
+
@campaign_id = res['campaign_id'].first
|
75
|
+
@clickthru_html = res['clickthru_html'].first
|
76
|
+
@clickthru_text = res['clickthru_text'].first
|
77
|
+
@created_on = res['created_on'].first
|
78
|
+
@encoding = res['encoding'].first
|
79
|
+
@html_message = res['html_message'].first
|
80
|
+
@id = res['id'].first
|
81
|
+
@in_queue = res['in_queue'].first
|
82
|
+
@list_id = res['list_id'].first
|
83
|
+
@name = res['name'].first
|
84
|
+
@next_step = res['next_step'].first
|
85
|
+
@opening_stats = res['opening_stats'].first
|
86
|
+
@out_queue = res['out_queue'].first
|
87
|
+
@recipients = res['recipients'].first
|
88
|
+
@scheduled_for = res['scheduled_for'].first
|
89
|
+
@scheduled_on = res['scheduled_on'].first
|
90
|
+
@sender_name = res['sender_name'].first
|
91
|
+
@status = res['status'].first
|
92
|
+
@subject = res['subject'].first
|
93
|
+
@sublist_id = res['sublist_id'].first
|
94
|
+
@suspended = res['suspended'].first
|
95
|
+
@text_message = res['text_message'].first
|
96
|
+
@unsub_bottom_link = res['unsub_bottom_link'].first
|
97
|
+
end
|
98
|
+
# Retrieves information about the log of a mailing.
|
99
|
+
#
|
100
|
+
# Arguments :
|
101
|
+
# * args = { :action => optional, :record_id => optional, :start_date => optional, :end_date => optional, :date => optional,
|
102
|
+
# :extra => optional, :limit => optional, :offset => optional, :count => optional, :uniques => optional }
|
103
|
+
def get_log(args)
|
104
|
+
options = { :mailing_id => @id, :user_key => @campaign.user.user_key }
|
105
|
+
options[:action] = args[:action] unless args[:action].nil?
|
106
|
+
options[:record_id] = args[:record_id] unless args[:record_id].nil?
|
107
|
+
options[:start_date] = args[:start_date] unless args[:start_date].nil?
|
108
|
+
options[:end_date] = args[:end_date] unless args[:end_date].nil?
|
109
|
+
options[:date] = args[:date] unless args[:date].nil?
|
110
|
+
options[:extra] = args[:extra] unless args[:extra].nil?
|
111
|
+
options[:limit] = args[:limit] unless args[:limit].nil?
|
112
|
+
res = @campaign.user.session.request("CakeMail::API::ClassMailing", "GetLog", options)
|
113
|
+
res['log']
|
114
|
+
end
|
115
|
+
# Retrieves statistics about the links of a mailing.
|
116
|
+
def get_links_log(start_date = nil, end_date = nil)
|
117
|
+
args = { :mailing_id => @id, :user_key => @campaign.user.user_key }
|
118
|
+
args[:start_date] = start_date unless start_date.nil?
|
119
|
+
args[:end_date] = end_date unless end_date.nil?
|
120
|
+
res = @campaign.user.session.request("CakeMail::API::ClassMailing", "GetLinksLog", args)
|
121
|
+
res['link']
|
122
|
+
end
|
123
|
+
# Retrieves the links of a mailing.
|
124
|
+
def get_links(status = nil)
|
125
|
+
args = { :mailing_id => @id, :user_key => @campaign.user.user_key }
|
126
|
+
args[:status] = status unless status.nil?
|
127
|
+
res = @campaign.user.session.request("CakeMail::API::ClassMailing", "GetLinks", args)
|
128
|
+
res['link']
|
129
|
+
end
|
130
|
+
# Retrieves statistics about a mailing.
|
131
|
+
def get_stats(information)
|
132
|
+
res = @campaign.user.session.request("CakeMail::API::ClassMailing", "GetStats", { :information => information, :mailing_id => @id,
|
133
|
+
:user_key => @campaign.user.user_key })
|
134
|
+
res[information].first
|
135
|
+
end
|
136
|
+
# Resumes the delivery of a mailing.
|
137
|
+
def resume
|
138
|
+
res = @campaign.user.session.request("CakeMail::API::ClassMailing", "Resume", { :mailing_id => @id,
|
139
|
+
:user_key => @campaign.user.user_key })
|
140
|
+
end
|
141
|
+
|
142
|
+
def save
|
143
|
+
self.set_info
|
144
|
+
end
|
145
|
+
# Schedules a mailing for delivery.
|
146
|
+
def schedule(date = nil)
|
147
|
+
args = { :mailing_id => @id, :user_key => @campaign.user.user_key }
|
148
|
+
args[:date] = date unless date.nil?
|
149
|
+
res = @campaign.user.session.request("CakeMail::API::ClassMailing", "Schedule", args)
|
150
|
+
end
|
151
|
+
# Sends the mailing as a test to an email.
|
152
|
+
def send_test_email(test_email, test_type)
|
153
|
+
res = @campaign.user.session.request("CakeMail::API::ClassMailing", "SendTestEmail", { :mailing_id => @id,
|
154
|
+
:user_key => @campaign.user.user_key, :test_email => test_email, :test_type => test_type })
|
155
|
+
end
|
156
|
+
# Modifies the settings of a mailing.
|
157
|
+
def set_info
|
158
|
+
args = { :mailing_id => @id, :user_key => @campaign.user.user_key }
|
159
|
+
args[:campaign_id] = @campaign_id unless @campaign_id.nil?
|
160
|
+
args[:list_id] = @list_id unless @list_id.nil? or @list_id == '0'
|
161
|
+
args[:sublist_id] = @sublist_id unless @sublist_id.nil? or @sublist_id == '0'
|
162
|
+
args[:next_step] = @next_step unless @next_step.nil?
|
163
|
+
args[:encoding] = @encoding unless @encoding.nil?
|
164
|
+
args[:clickthru_html] = @clickthru_html unless @clickthru_html.nil?
|
165
|
+
args[:clickthru_text] = @clickthru_text unless @clickthru_text.nil?
|
166
|
+
args[:opening_stats] = @opening_stats unless @opening_stats.nil?
|
167
|
+
args[:unsub_bottom_link] = @unsub_bottom_link unless @unsub_bottom_link.nil?
|
168
|
+
args[:name] = @name unless @name.nil?
|
169
|
+
args[:subject] = @subject unless @subject.nil?
|
170
|
+
args[:sender_name] = @sender_name unless @sender_name.nil?
|
171
|
+
args[:sender_email] = @sender_email unless @sender_email.nil?
|
172
|
+
args[:html_message] = @html_message unless @html_message.nil?
|
173
|
+
args[:text_message] = @text_message unless @text_message.nil?
|
174
|
+
args[:campaign_id] = @campaign_id unless @campaign_id.nil?
|
175
|
+
res = @campaign.user.session.request("CakeMail::API::ClassMailing", "SetInfo", args)
|
176
|
+
end
|
177
|
+
# Suspends the delivery of a mailing.
|
178
|
+
def suspend
|
179
|
+
res = @campaign.user.session.request("CakeMail::API::ClassMailing", "Suspend", { :mailing_id => @id,
|
180
|
+
:user_key => @campaign.user.user_key })
|
181
|
+
end
|
182
|
+
# Unschedules a mailing from delivery.
|
183
|
+
def unschedule
|
184
|
+
res = @campaign.user.session.request("CakeMail::API::ClassMailing", "Unschedule", { :mailing_id => @id,
|
185
|
+
:user_key => @campaign.user.user_key })
|
186
|
+
end
|
187
|
+
|
188
|
+
class << self
|
189
|
+
# Creates a mailing.
|
190
|
+
def create(campaign, name, encoding = nil)
|
191
|
+
args = { :campaign_id => campaign.id, :name => name, :user_key => campaign.user.user_key }
|
192
|
+
args[:encoding] = encoding unless encoding.nil?
|
193
|
+
res = campaign.user.session.request("CakeMail::API::ClassMailing", "Create", args)
|
194
|
+
Mailing.new(campaign, res['id'].first)
|
195
|
+
end
|
196
|
+
# Returns the list of mailings.
|
197
|
+
#
|
198
|
+
# Arguments :
|
199
|
+
# * args = { :campaign => required, :status => optional, :campaign_id => optional, :list_id => optional, :limit => optional,
|
200
|
+
# :offset => optional, :count => optional }
|
201
|
+
def get_list(args)
|
202
|
+
raise ArgumentError if args.nil? or args[:campaign].nil?
|
203
|
+
options = { :user_key => args[:campaign].user.user_key }
|
204
|
+
options[:status] = args[:status] unless args[:status].nil?
|
205
|
+
options[:campaign_id] = args[:campaign_id] unless args[:campaign_id].nil?
|
206
|
+
options[:list_id] = args[:list_id] unless args[:list_id].nil?
|
207
|
+
options[:limit] = args[:limit] unless args[:limit].nil?
|
208
|
+
options[:offset] = args[:offset] unless args[:offset].nil?
|
209
|
+
options[:count] = args[:count] unless args[:count].nil?
|
210
|
+
res = args[:campaign].user.session.request("CakeMail::API::ClassMailing", "GetList", options)
|
211
|
+
res['mailing']
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# The Relay accepts an individual email in a single API call, and applies open and link tracking, performs sender-email authentication,
|
2
|
+
# delivers the email and logs recipient activity.
|
3
|
+
#
|
4
|
+
# Possible usage:
|
5
|
+
# * Password reminders
|
6
|
+
# * Email invoices
|
7
|
+
# * Automatic email notifications
|
8
|
+
# * Membership invitations
|
9
|
+
# * Confirmations
|
10
|
+
# * User to user messaging systems
|
11
|
+
# * SMTP to Relay
|
12
|
+
module CakeMail
|
13
|
+
module API
|
14
|
+
class ClassRelay < CakeMail::ServiceClass
|
15
|
+
method :name => "send", :requires => [ :user_key, :email, :sender_name, :sender_email, :subject ], :optional => [ :html_message,
|
16
|
+
:text_message, :encoding, :track_opening, :track_clicks_in_html, :track_clicks_in_text ], :custom_args_xml => [
|
17
|
+
Proc.new do |builder, args|
|
18
|
+
unless args[:data].nil?
|
19
|
+
args[:data].each { |r| builder.data({ :type => r[:type] }, r[:value]) }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
]
|
23
|
+
method :name => "GetLogs", :requires => [ :user_key, :log_type ], :optional => [ :start_time, :end_time ]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Relay
|
28
|
+
class << self
|
29
|
+
# Send an email using the Relay.
|
30
|
+
#
|
31
|
+
# Arguments :
|
32
|
+
# * args = { :user => required, :email => required, :sender_name => required, :sender_email => required, :subject => required,
|
33
|
+
# :html_message => optional, :text_message => optional, :encoding => optional, :track_opening => optional,
|
34
|
+
# :track_clicks_in_html => optional, :track_clicks_in_text => optional, :data => optional/custom }
|
35
|
+
# Custom format of :data :
|
36
|
+
# * [ { :type => "text", :name => "schedule" }, { :type => "text", :name => "schedule" }, ... ]
|
37
|
+
def send(args)
|
38
|
+
raise ArgumentError if args.nil? or args[:user] or args[:email].nil? or args[:sender_name] or args[:sender_email] or args[:subject]
|
39
|
+
options = { :user_key => args[:user].user_key, :email => args[:email], :sender_name => args[:sender_name],
|
40
|
+
:sender_email => args[:sender_email], :subject => args[:subject] }
|
41
|
+
options[:html_message] = args[:html_message] unless args[:html_message].nil?
|
42
|
+
options[:text_message] = args[:text_message] unless args[:text_message].nil?
|
43
|
+
options[:encoding] = args[:encoding] unless args[:encoding].nil?
|
44
|
+
options[:track_opening] = args[:track_opening] unless args[:track_opening].nil?
|
45
|
+
options[:track_clicks_in_html] = args[:track_clicks_in_html] unless args[:track_clicks_in_html].nil?
|
46
|
+
options[:track_clicks_in_text] = args[:track_clicks_in_text] unless args[:track_clicks_in_text].nil?
|
47
|
+
options[:data] = args[:data] unless args[:data].nil?
|
48
|
+
res = args[:user].session.request("CakeMail::API::ClassRelay", "Send", options)
|
49
|
+
end
|
50
|
+
# Retrieves logs from Relay.
|
51
|
+
#
|
52
|
+
# Arguments :
|
53
|
+
# * args = { :user => required, :log_type => required, :start_time => optional, :end_time => optional }
|
54
|
+
def get_logs(args)
|
55
|
+
raise ArgumentError if args.nil? or args[:user] or args[:log_type].nil?
|
56
|
+
options = { :user_key => args[:user].user_key, :log_type => args[:log_type] }
|
57
|
+
options[:start_time] = args[:start_time] unless args[:start_time].nil?
|
58
|
+
options[:end_time] = args[:end_time] unless args[:end_time].nil?
|
59
|
+
res = args[:user].session.request("CakeMail::API::ClassRelay", "Send", options)
|
60
|
+
return res['bounce_log']
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module CakeMail
|
2
|
+
class ServiceMethod
|
3
|
+
attr_reader :name, :requires, :optional
|
4
|
+
|
5
|
+
def initialize(name, requires, optional, custom_args_xml)
|
6
|
+
@name = name
|
7
|
+
@requires = requires
|
8
|
+
@optional = optional
|
9
|
+
@custom_args_xml = custom_args_xml
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_xml(builder, args)
|
13
|
+
@requires.each do |arg|
|
14
|
+
raise ArgumentError.new(arg.to_s) unless args.has_key?(arg)
|
15
|
+
builder.__send__(arg.to_s, args[arg])
|
16
|
+
end
|
17
|
+
@optional.each do |arg|
|
18
|
+
builder.__send__(arg.to_s, args[arg]) if args.has_key?(arg)
|
19
|
+
end
|
20
|
+
@custom_args_xml.each do |arg|
|
21
|
+
arg.call(builder, args)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class ServiceClass
|
27
|
+
class InvalidMethod < Exception; end
|
28
|
+
|
29
|
+
def self.method(args)
|
30
|
+
raise ArgumentError.new("args or name missing") if args.nil? or args[:name].nil?
|
31
|
+
@methods ||= { }
|
32
|
+
name = args[:name]
|
33
|
+
@methods[name] = ServiceMethod.new(name, args[:requires] || [ ], args[:optional] || [ ], args[:custom_args_xml] || [ ])
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.method_xml(builder, session, method, args)
|
37
|
+
raise ArgumentError.new("builder or session missing") if builder.nil? or session.nil?
|
38
|
+
raise InvalidMethod unless @methods.has_key?(method)
|
39
|
+
builder.class(:type => self.to_s.gsub(/.*::/, ''), :locale => session.class::API_LOCALE) do |klass|
|
40
|
+
klass.method(:type => method) do |meth|
|
41
|
+
@methods[method].to_xml(meth, args)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module CakeMail
|
2
|
+
class Session
|
3
|
+
class HttpRequestError < Exception; end
|
4
|
+
class ApiRequestError < Exception; end
|
5
|
+
|
6
|
+
API_SERVER_BASE_URL = "http://api.cakemail.com/"
|
7
|
+
API_VERSION = "1.0"
|
8
|
+
API_LOCALE = "en_US"
|
9
|
+
|
10
|
+
attr_reader :api_id, :api_key, :user_key
|
11
|
+
|
12
|
+
def initialize(api_id, api_key)
|
13
|
+
@api_id = api_id
|
14
|
+
@api_key = api_key
|
15
|
+
@crypto = Crypt::Blowfish.new(@api_key)
|
16
|
+
end
|
17
|
+
# Returns a logged in user.
|
18
|
+
def login(email, password)
|
19
|
+
user = CakeMail::User.login(self, email, password)
|
20
|
+
return user
|
21
|
+
end
|
22
|
+
# Recover password.
|
23
|
+
def password_recovery(email)
|
24
|
+
CakeMail::User.password_recovery(email)
|
25
|
+
end
|
26
|
+
|
27
|
+
def request(service_class, method, args)
|
28
|
+
builder = Builder::XmlMarkup.new(:indent => 1)
|
29
|
+
builder.instruct! :xml, :version => "1.0", :encoding => "utf-8"
|
30
|
+
req = builder.body(:version => API_VERSION) { |body| Object.module_eval(service_class).method_xml(body, self, method, args) }
|
31
|
+
res = Net::HTTP.post_form(URI.parse(API_SERVER_BASE_URL), {'alg' => 'blowfish', 'mode' => 'ecb', 'id' => @api_id, 'request' => encode(req)})
|
32
|
+
raise HttpRequestError if res.nil? || res.body.nil? || (res.code.to_i != 200)
|
33
|
+
r = XmlSimple.xml_in(decode(res.body))
|
34
|
+
raise ApiRequestError if r.nil? || !r.has_key?('class') || !r['class'].is_a?(Array)
|
35
|
+
r = r['class'].first
|
36
|
+
raise ApiRequestError if (r['type'] != service_class.gsub(/.*::/, '')) ||
|
37
|
+
!r['method'].is_a?(Array) || (r['method'].first['type'] != method)
|
38
|
+
r = r['method'].first
|
39
|
+
r = unescape_xmlsimple_result(r)
|
40
|
+
if r.has_key?('error_code')
|
41
|
+
error = "Error #{r['error_code'].first}"
|
42
|
+
error += ": #{CGI.unescape(r['error_message'].first)}" if r.has_key?('error_message')
|
43
|
+
error += " [#{service_class.to_s} :: #{method}]"
|
44
|
+
raise ApiRequestError.new(error)
|
45
|
+
end
|
46
|
+
return r
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def encode(req)
|
51
|
+
@crypto.encrypt_string(req).unpack("H*").first
|
52
|
+
end
|
53
|
+
|
54
|
+
def decode(req)
|
55
|
+
@crypto.decrypt_string([req].pack("H*"))
|
56
|
+
end
|
57
|
+
|
58
|
+
def unescape_xmlsimple_result(data)
|
59
|
+
if data.is_a?(Hash)
|
60
|
+
newdata = { }
|
61
|
+
data.each { |k,v| newdata[k] = unescape_xmlsimple_result(v) }
|
62
|
+
newdata
|
63
|
+
elsif data.is_a?(Array)
|
64
|
+
data.map { |elem| unescape_xmlsimple_result(elem) }
|
65
|
+
elsif data.is_a?(String)
|
66
|
+
CGI.unescape(data)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
module CakeMail
|
2
|
+
module API
|
3
|
+
class ClassSuppressionList < CakeMail::ServiceClass
|
4
|
+
method :name => "ImportEmails", :requires => [ :user_key ], :custom_args_xml => [
|
5
|
+
Proc.new do |builder, args|
|
6
|
+
unless args[:email].nil?
|
7
|
+
args[:email].each { |r| builder.email(r) }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
]
|
11
|
+
method :name => "ExportEmails", :requires => [ :user_key ], :optional => [ :source_type, :limit, :offset, :count ]
|
12
|
+
method :name => "DeleteEmails", :requires => [ :user_key ], :custom_args_xml => [
|
13
|
+
Proc.new do |builder, args|
|
14
|
+
unless args[:email].nil?
|
15
|
+
args[:email].each { |r| builder.email(r) }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
]
|
19
|
+
method :name => "ImportDomains", :requires => [ :user_key ], :custom_args_xml => [
|
20
|
+
Proc.new do |builder, args|
|
21
|
+
unless args[:domain].nil?
|
22
|
+
args[:domain].each { |r| builder.domain(r) }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
]
|
26
|
+
method :name => "ExportDomains", :requires => [ :user_key ], :optional => [ :limit, :offset, :count ]
|
27
|
+
method :name => "DeleteDomains", :requires => [ :user_key ], :custom_args_xml => [
|
28
|
+
Proc.new do |builder, args|
|
29
|
+
unless args[:domain].nil?
|
30
|
+
args[:domain].each { |r| builder.domain(r) }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class SuppressionList
|
38
|
+
class << self
|
39
|
+
# Imports one or more emails into the suppression list.
|
40
|
+
#
|
41
|
+
# Custom argument :
|
42
|
+
# emails = [ 'test@example.com', 'test2@example.com', ... ]
|
43
|
+
def import_emails(user, emails)
|
44
|
+
res = user.session.request("CakeMail::API::ClassSuppressionList", "ImportEmails", { :email => emails, :user_key => user.user_key })
|
45
|
+
end
|
46
|
+
# Exports the suppressed emails.
|
47
|
+
#
|
48
|
+
# Arguments :
|
49
|
+
# * args = { :user => required, :source_type => optional, :limit => optional, :count => optional, }
|
50
|
+
def export_emails(args)
|
51
|
+
raise ArgumentError if args.nil? or args[:user].nil?
|
52
|
+
options = { :user_key => args[:user].user_key }
|
53
|
+
options[:source_type] = arg[:source_type] unless arg[:source_type].nil?
|
54
|
+
options[:limit] = arg[:limit] unless arg[:limit].nil?
|
55
|
+
options[:offset] = arg[:offset] unless arg[:offset].nil?
|
56
|
+
options[:count] = arg[:count] unless arg[:count].nil?
|
57
|
+
res = arg[:user].session.request("CakeMail::API::ClassSuppressionList", "ExportEmails", options)
|
58
|
+
if !arg[:count].nil?
|
59
|
+
return res['count']
|
60
|
+
end
|
61
|
+
return res['record']
|
62
|
+
end
|
63
|
+
# Deletes one or more emails from the suppression list.
|
64
|
+
#
|
65
|
+
# Custom argument :
|
66
|
+
# emails = [ 'test@example.com', 'test2@example.com', ... ]
|
67
|
+
def delete_emails(user, emails)
|
68
|
+
res = user.session.request("CakeMail::API::ClassSuppressionList", "DeleteEmails", { :user_key => user.user_key, :email => emails })
|
69
|
+
end
|
70
|
+
# Imports one or more domains into the suppression list.
|
71
|
+
#
|
72
|
+
# Custom argument :
|
73
|
+
# * domains = [ 'domain1.com', 'domain2', ...]
|
74
|
+
def import_domains(user, domains)
|
75
|
+
res = user.session.request("CakeMail::API::ClassSuppressionList", "ImportDomains", { :domain => domains, :user_key => user.user_key })
|
76
|
+
end
|
77
|
+
# Exports the suppressed emails.
|
78
|
+
#
|
79
|
+
# Arguments :
|
80
|
+
# * args = { :user => required, :limit => optional, :offset => optional, :count => optional }
|
81
|
+
def export_domains(args)
|
82
|
+
raise ArgumentError if args.nil? or args[:user].nil?
|
83
|
+
options = { :user_key => args[:user].user_key }
|
84
|
+
options[:limit] = args[:limit] unless args[:limit].nil?
|
85
|
+
options[:offset] = args[:offset] unless args[:offset].nil?
|
86
|
+
options[:count] = args[:count] unless args[:count].nil?
|
87
|
+
res = args[:user].session.request("CakeMail::API::ClassSuppressionList", "ExportDomains", options)
|
88
|
+
if !args[:count].nil?
|
89
|
+
return res['count']
|
90
|
+
end
|
91
|
+
return res['record']
|
92
|
+
end
|
93
|
+
# Deletes one or more domains from the suppression list.
|
94
|
+
#
|
95
|
+
# Custom argument :
|
96
|
+
# * domains = [ 'domain1.com', 'domain2', ...]
|
97
|
+
def delete_domains(user, domains)
|
98
|
+
res = user.session.request("CakeMail::API::ClassSuppressionList", "DeleteDomains", { :user_key => user.user_key, :domain => domains })
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|