mailup 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +79 -0
  6. data/Rakefile +7 -0
  7. data/lib/mailup.rb +206 -0
  8. data/lib/mailup/console/base.rb +115 -0
  9. data/lib/mailup/console/email.rb +35 -0
  10. data/lib/mailup/console/group.rb +111 -0
  11. data/lib/mailup/console/images.rb +69 -0
  12. data/lib/mailup/console/import.rb +38 -0
  13. data/lib/mailup/console/list.rb +863 -0
  14. data/lib/mailup/console/recipient.rb +69 -0
  15. data/lib/mailup/console/user.rb +77 -0
  16. data/lib/mailup/errors.rb +18 -0
  17. data/lib/mailup/public/base.rb +18 -0
  18. data/lib/mailup/public/console.rb +75 -0
  19. data/lib/mailup/stats/base.rb +41 -0
  20. data/lib/mailup/stats/message.rb +284 -0
  21. data/lib/mailup/stats/recipient.rb +303 -0
  22. data/lib/mailup/version.rb +4 -0
  23. data/mailup.gemspec +25 -0
  24. data/rails/init.rb +1 -0
  25. data/spec/mailup/console/base_spec.rb +33 -0
  26. data/spec/mailup/console/email_spec.rb +19 -0
  27. data/spec/mailup/console/group_spec.rb +42 -0
  28. data/spec/mailup/console/images_spec.rb +29 -0
  29. data/spec/mailup/console/import_spec.rb +17 -0
  30. data/spec/mailup/console/list_spec.rb +164 -0
  31. data/spec/mailup/console/recipient_spec.rb +11 -0
  32. data/spec/mailup/console/user_spec.rb +16 -0
  33. data/spec/mailup/mailup_spec.rb +36 -0
  34. data/spec/mailup/public/base_spec.rb +22 -0
  35. data/spec/mailup/public/console_spec.rb +24 -0
  36. data/spec/mailup/stats/base_spec.rb +22 -0
  37. data/spec/mailup/stats/message_spec.rb +35 -0
  38. data/spec/mailup/stats/recipient_spec.rb +40 -0
  39. data/spec/spec_helper.rb +37 -0
  40. metadata +138 -0
@@ -0,0 +1,35 @@
1
+ module MailUp
2
+ module Console
3
+ class Email
4
+ attr_accessor :api
5
+
6
+ def initialize(api)
7
+ @api = api
8
+ end
9
+
10
+ # Send single email message to specified recipient.
11
+ #
12
+ # @param [Integer] message_id The ID of the message to send.
13
+ # @param [String] email The email address of the recipient.
14
+ #
15
+ # @return [JSON] A Send object with the following attributes:
16
+ # * idMessage [Integer]
17
+ # * Sent [Integer]
18
+ # * UnprocessedRecipients [Array]
19
+ # * InvalidRecipients [Array]
20
+ #
21
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-SendMailMessageToRecipient
22
+ #
23
+ # @example
24
+ #
25
+ # send = mailup.console.email.send(5, 'joe@public.com')
26
+ # send['Sent']
27
+ # => 1
28
+ #
29
+ def send(message_id, email)
30
+ @api.post("#{@api.path}/Email/Send", body: {:idMessage => message_id, :Email => email})
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,111 @@
1
+ module MailUp
2
+ module Console
3
+ class Group
4
+ attr_accessor :api
5
+
6
+ def initialize(id, api)
7
+ @api = api
8
+ @id = id
9
+ end
10
+
11
+ # Async Import recipients to the specified group.
12
+ #
13
+ # @param [Array] recipients an array ConsoleRecipientItems (See http://help.mailup.com/display/mailupapi/Models+v1.1#Modelsv1.1-ConsoleRecipientItem).
14
+ #
15
+ # @return [Integer] Number of recipients added to the group.
16
+ #
17
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-AsyncImportRecipientsToGroup
18
+ #
19
+ def add_recipients(recipients)
20
+ @api.post("#{@api.path}/Group/#{@id}/Recipients", body: recipients)
21
+ end
22
+
23
+ # Retrieve the recipients in the specified group.
24
+ #
25
+ # @param [Hash] params Optional params or filters:
26
+ # @option params [Integer] :pageNumber The page number to return.
27
+ # @option params [Integer] :pageSize The number of results to per page.
28
+ # @option params [String] :filterby A filtering expression.
29
+ # @option params [String] :orderby The sorting condition for the results.
30
+ #
31
+ # @return [JSON] Results and data including:
32
+ # * IsPaginated [Boolean]
33
+ # * Items [Array<Hash>]
34
+ # * PageNumber [Integer]
35
+ # * PageSize [Integer]
36
+ # * Skipped [Integer]
37
+ # * TotalElementsCount [Integer]
38
+ #
39
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetRecipientsByGroup
40
+ #
41
+ # @example
42
+ #
43
+ # recipients = mailup.console.group(5).recipients
44
+ # recipients['TotalElementsCount']
45
+ # => 125
46
+ # recipients['Items'].first['Name']
47
+ # => "Joe Public"
48
+ #
49
+ def recipients(params = {})
50
+ @api.get("#{@api.path}/Group/#{@id}/Recipients", params: params)
51
+ end
52
+
53
+ # Subscribe the recipient with the related id to the specified group.
54
+ #
55
+ # @param [Integer] recipient_id The ID of the recipient.
56
+ #
57
+ # @return [Boolean] `true` if successful.
58
+ #
59
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-SubscribeRecipientToGroup
60
+ #
61
+ # @example
62
+ #
63
+ # susbcribe = mailup.console.group(5).subscribe(126)
64
+ # => true
65
+ #
66
+ def subscribe(recipient_id)
67
+ @api.post("#{@api.path}/Group/#{@id}/Subscribe/#{recipient_id}")
68
+ end
69
+
70
+ # Unsubscribe the recipient with the related id from the specified group.
71
+ #
72
+ # @param [Integer] recipient_id The ID of the recipient.
73
+ #
74
+ # @return [Boolean] `true` if successful.
75
+ #
76
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-UnsubscribeRecipientFromGroup
77
+ #
78
+ # @example
79
+ #
80
+ # unsusbcribe = mailup.console.group(5).unsubscribe(126)
81
+ # => true
82
+ #
83
+ def unsubscribe(recipient_id)
84
+ @api.delete("#{@api.path}/Group/#{@id}/Unsubscribe/#{recipient_id}")
85
+ end
86
+
87
+ # Send email message to all recipient in group.
88
+ #
89
+ # @param [Integer] message_id of the message.
90
+ #
91
+ # @return [JSON] A Send object with the following attributes:
92
+ # * idMessage [Integer]
93
+ # * Sent [Integer]
94
+ # * UnprocessedRecipients [Array]
95
+ # * InvalidRecipients [Array]
96
+ #
97
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-SendMailMessageToRecipientInGroup
98
+ #
99
+ # @example
100
+ #
101
+ # send = mailup.console.group(5).send_message(1340)
102
+ # send['Sent']
103
+ # => 1794
104
+ #
105
+ def send_message(message_id)
106
+ @api.post("#{@api.path}/Group/#{@id}/Email/#{message_id}/Send")
107
+ end
108
+
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,69 @@
1
+ module MailUp
2
+ module Console
3
+ class Images
4
+ attr_accessor :api
5
+
6
+ def initialize(api)
7
+ @api = api
8
+ end
9
+
10
+ # Get the list of all shared images for the current console.
11
+ #
12
+ # @return [Array<String>] An array of Image strings.
13
+ #
14
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetSharedImages
15
+ #
16
+ # @example
17
+ #
18
+ # images = mailup.console.images.list
19
+ # images.size
20
+ # => 50
21
+ #
22
+ def list
23
+ @api.get("#{@api.path}/Images")
24
+ end
25
+
26
+ # Add a new image to the shared images list.
27
+ #
28
+ # @param [Hash] image A hash of image attributes:
29
+ # @option image [String] Name of the image.
30
+ # @option image [String] Base64 data for the image.
31
+ #
32
+ # @return [Array] An array of Image strings.
33
+ #
34
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-AddSharedImage
35
+ #
36
+ # @example
37
+ #
38
+ # image = {
39
+ # Name: "TemplateHeader.jpg",
40
+ # Data: "..."
41
+ # }
42
+ # images = mailup.console.images.add_image(image)
43
+ # images.size
44
+ # => 51
45
+ #
46
+ def add_image(image)
47
+ @api.post("#{@api.path}/Images", body:image)
48
+ end
49
+
50
+ # Delete the image corresponding to the provided full path name.
51
+ #
52
+ # @param [String] path The path of the image to delete.
53
+ #
54
+ # @return [Boolean] `true` if successful.
55
+ #
56
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-DeleteImage
57
+ #
58
+ # @example
59
+ #
60
+ # delete = mailup.console.images.delete_image("#{image_path}")
61
+ # => true
62
+ #
63
+ def delete_image(path)
64
+ @api.delete("#{@api.path}/Images", body: path.to_s)
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,38 @@
1
+ module MailUp
2
+ module Console
3
+ class Import
4
+ attr_accessor :api
5
+
6
+ def initialize(id, api)
7
+ @api = api
8
+ @id = id
9
+ end
10
+
11
+ # Get import status.
12
+ #
13
+ # @return [JSON] A Status object with the following attributes:
14
+ # * idImport [Integer]
15
+ # * Completed [Boolean]
16
+ # * UpdatedRecipients [Integer]
17
+ # * ValidRecipients [Integer]
18
+ # * CreatedRecipients [Integer]
19
+ # * ImportedRecipients [Integer]
20
+ # * NotValidRecipients [Integer]
21
+ #
22
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetImportStatus
23
+ #
24
+ # @example
25
+ #
26
+ # status = mailup.console.import(9).status
27
+ # status['Completed']
28
+ # => true
29
+ # status['UpdatedRecipients']
30
+ # => 159
31
+ #
32
+ def status
33
+ @api.get("#{@api.path}/Import/#{@id}")
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,863 @@
1
+ module MailUp
2
+ module Console
3
+ class List
4
+ attr_accessor :api
5
+
6
+ def initialize(id, api)
7
+ @api = api
8
+ @id = id
9
+ end
10
+
11
+ # Retrieve groups for the specified list
12
+ #
13
+ # @param [Hash] params Optional params or filters:
14
+ # @option params [Integer] :pageNumber The page number to return.
15
+ # @option params [Integer] :pageSize The number of results to per page.
16
+ # @option params [String] :filterby A filtering expression.
17
+ # @option params [String] :orderby The sorting condition for the results.
18
+ #
19
+ # @return [JSON] Results and data including:
20
+ # * IsPaginated [Boolean]
21
+ # * Items [Array<Hash>]
22
+ # * PageNumber [Integer]
23
+ # * PageSize [Integer]
24
+ # * Skipped [Integer]
25
+ # * TotalElementsCount [Integer]
26
+ #
27
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetConsoleGroupsByList
28
+ #
29
+ # @example
30
+ #
31
+ # list = mailup.console.list(2)
32
+ # groups = list.groups
33
+ # groups['TotalElementsCount']
34
+ # => 10
35
+ #
36
+ # groups = mailup.console.list(2).groups(pageNumber: 0, pageSize: 1)
37
+ #
38
+ def groups(params = {})
39
+ @api.get("#{@api.path}/List/#{@id}/Groups", params: params)
40
+ end
41
+
42
+ # Create a new group for the specified list.
43
+ #
44
+ # @param [Hash] group A hash of group attributes.
45
+ # @option group [String] :Name of the group (required).
46
+ # @option group [String] :Notes to associate with the group (required).
47
+ # @option group [Boolean] :Deletable to flag whether the group can be deleted (required).
48
+ #
49
+ # @return [JSON] The new Group including:
50
+ # * idList [Integer]
51
+ # * idGroup [Integer]
52
+ # * Name [String]
53
+ # * Notes [String]
54
+ # * Deletable [Boolean]
55
+ #
56
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-CreateGroup
57
+ #
58
+ # @example
59
+ #
60
+ # group = {
61
+ # Name: "New Group",
62
+ # Notes: "Created with mailup-rest gem",
63
+ # Deletable: true
64
+ # }
65
+ # new_group = mailup.console.list(2).add_group(group)
66
+ # new_group['idGroup']
67
+ # => 18
68
+ #
69
+ def add_group(group)
70
+ @api.post("#{@api.path}/List/#{@id}/Group", body: group)
71
+ end
72
+
73
+ # Update a group for the specified list.
74
+ #
75
+ # @param [Hash] group A hash of group attributes.
76
+ # @option group [String] :Name of the group (required).
77
+ # @option group [String] :Notes to associate with the group (required).
78
+ # @option group [Boolean] :Deletable to flag whether the group can be deleted (required).
79
+ #
80
+ # @return [JSON] The updated Group including:
81
+ # * idList [Integer]
82
+ # * idGroup [Integer]
83
+ # * Name [String]
84
+ # * Notes [String]
85
+ # * Deletable [Boolean]
86
+ #
87
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-UpdateGroup
88
+ #
89
+ # @example
90
+ #
91
+ # group = {
92
+ # Name: "Updated Group",
93
+ # Notes: "Updated with mailup-rest gem",
94
+ # Deletable: true
95
+ # }
96
+ # update = mailup.console.list(2).update_group(50, group)
97
+ # update['idGroup']
98
+ # => "Updated Title"
99
+ #
100
+ def update_group(group_id, group)
101
+ @api.put("#{@api.path}/List/#{@id}/Group/#{group_id}", body: group)
102
+ end
103
+
104
+ # Delete a group from the specified list.
105
+ #
106
+ # @param [Integer] group_id The ID of the group to delete.
107
+ #
108
+ # @return [Boolean] `true` if successful
109
+ #
110
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-DeleteGroup
111
+ #
112
+ # Example:
113
+ #
114
+ # delete = mailup.console.list(2).delete_group(49)
115
+ # => true
116
+ #
117
+ def delete_group(group_id)
118
+ @api.delete("#{@api.path}/List/#{@id}/Group/#{group_id}")
119
+ end
120
+
121
+ # Retrieve the groups subscribed by the recipient in the specified list.
122
+ #
123
+ # @param [Integer] recipient_id The ID of the recipient.
124
+ # @param [Hash] params Optional params or filters:
125
+ # @option params [Integer] :pageNumber The page number to return.
126
+ # @option params [Integer] :pageSize The number of results to per page.
127
+ # @option params [String] :filterby A filtering expression.
128
+ # @option params [String] :orderby The sorting condition for the results.
129
+ #
130
+ # @return [JSON] Results and data including:
131
+ # * IsPaginated [Boolean]
132
+ # * Items [Array<Hash>]
133
+ # * PageNumber [Integer]
134
+ # * PageSize [Integer]
135
+ # * Skipped [Integer]
136
+ # * TotalElementsCount [Integer]
137
+ #
138
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetConsoleGroupsByRecipient
139
+ #
140
+ # @example
141
+ #
142
+ # groups = mailup.console.list(2).recipient_groups(5)
143
+ # groups['TotalElementsCount']
144
+ # => 3
145
+ # groups['Items'].first['Name']
146
+ # => "Group Name"
147
+ #
148
+ # groups = mailup.console.list(2).recipient_groups(5, pageNumber: 0, pageSize: 1)
149
+ #
150
+ def recipient_groups(recipient_id, params = {})
151
+ @api.get("#{@api.path}/List/#{@id}/Recipient/#{recipient_id}/Groups", params: params)
152
+ end
153
+
154
+ # Retrieve pending recipients in the specified list.
155
+ #
156
+ # @param [Hash] params Optional params or filters:
157
+ # @option params [Integer] :pageNumber The page number to return.
158
+ # @option params [Integer] :pageSize The number of results to per page.
159
+ # @option params [String] :filterby A filtering expression.
160
+ # @option params [String] :orderby The sorting condition for the results.
161
+ #
162
+ # @return [JSON] Results and data including:
163
+ # * IsPaginated [Boolean]
164
+ # * Items [Array<Hash>]
165
+ # * PageNumber [Integer]
166
+ # * PageSize [Integer]
167
+ # * Skipped [Integer]
168
+ # * TotalElementsCount [Integer]
169
+ #
170
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetPendingRecipientsByList
171
+ #
172
+ # @example
173
+ #
174
+ # pending = mailup.console.list(2).pending
175
+ # pending['TotalElementsCount']
176
+ # => 3
177
+ # pending['Items'].first['Name']
178
+ # => "Joe Public"
179
+ #
180
+ # pending = mailup.console.list(2).pending(pageNumber: 0, pageSize: 1)
181
+ #
182
+ def pending(params = {})
183
+ @api.get("#{@api.path}/List/#{@id}/Recipients/Pending", params: params)
184
+ end
185
+
186
+ # Retrieve subscribed recipients in the specified list.
187
+ #
188
+ # @param [Hash] params Optional params or filters:
189
+ # @option params [Integer] :pageNumber The page number to return.
190
+ # @option params [Integer] :pageSize The number of results to per page.
191
+ # @option params [String] :filterby A filtering expression.
192
+ # @option params [String] :orderby The sorting condition for the results.
193
+ #
194
+ # @return [JSON] Results and data including:
195
+ # * IsPaginated [Boolean]
196
+ # * Items [Array<Hash>]
197
+ # * PageNumber [Integer]
198
+ # * PageSize [Integer]
199
+ # * Skipped [Integer]
200
+ # * TotalElementsCount [Integer]
201
+ #
202
+ # @see http://help.mailup.com/display/mailupapi/Admin+Console+Methods#AdminConsoleMethods-GetSubscribedRecipientsByList
203
+ #
204
+ # @example
205
+ #
206
+ # subscribed = mailup.console.list(2).subscribed
207
+ # subscribed['TotalElementsCount']
208
+ # => 10
209
+ # subscribed['Items'].first['Name']
210
+ # => "Joe Public"
211
+ #
212
+ # subscribed = mailup.console.list(2).subscribed(pageNumber: 0, pageSize: 1)
213
+ #
214
+ def subscribed(params = {})
215
+ @api.get("#{@api.path}/List/#{@id}/Recipients/Subscribed", params: params)
216
+ end
217
+
218
+ # Retrieve unsubscribed recipients in the specified list.
219
+ #
220
+ # @param [Hash] params Optional params or filters:
221
+ # @option params [Integer] :pageNumber The page number to return.
222
+ # @option params [Integer] :pageSize The number of results to per page.
223
+ # @option params [String] :filterby A filtering expression.
224
+ # @option params [String] :orderby The sorting condition for the results.
225
+ #
226
+ # @return [JSON] Results and data including:
227
+ # * IsPaginated [Boolean]
228
+ # * Items [Array<Hash>]
229
+ # * PageNumber [Integer]
230
+ # * PageSize [Integer]
231
+ # * Skipped [Integer]
232
+ # * TotalElementsCount [Integer]
233
+ #
234
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetUnsubscribedRecipientsByList
235
+ #
236
+ # @example
237
+ #
238
+ # unsubscribed = mailup.console.list(2).unsusbcribed
239
+ # unsubscribed['TotalElementsCount']
240
+ # => 10
241
+ # unsubscribed['Items'].first['Name']
242
+ # => "Joe Public"
243
+ #
244
+ # unsubscribed = mailup.console.list(2).unsusbcribed(pageNumber: 0, pageSize: 1)
245
+ #
246
+ def unsubscribed(params = {})
247
+ @api.get("#{@api.path}/List/#{@id}/Recipients/Unsubscribed", params: params)
248
+ end
249
+
250
+ # Import multiple recipients to a list.
251
+ #
252
+ # @param [Array<Hash>] recipients An array of Recipients.
253
+ # * idRecipient [Integer] (optional)
254
+ # * Name [String]
255
+ # * Email [String]
256
+ # * MobilePrefix [String]
257
+ # * MobileNumber [String]
258
+ # * Fields [Array]
259
+ #
260
+ # @return [Integer] The number of imported recipients.
261
+ #
262
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-AsyncImportRecipientsToList
263
+ #
264
+ def import_recipients(recipients)
265
+ @api.post("#{@api.path}/List/#{@id}/Recipients", body: recipients)
266
+ end
267
+
268
+ # Subscribe a recipient from the specified list.
269
+ #
270
+ # @param [Integer] recipient_id The ID of the recipient.
271
+ #
272
+ # @return [Boolean] `true` if successful.
273
+ #
274
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-SubscribeRecipientToList
275
+ #
276
+ # @example
277
+ #
278
+ # susbcribe = mailup.console.list(2).subscribe(126)
279
+ # => true
280
+ #
281
+ def subscribe(recipient_id)
282
+ @api.post("#{@api.path}/List/#{@id}/Subscribe/#{recipient_id}")
283
+ end
284
+
285
+ # Unsubscribe a recipient in the specified list.
286
+ #
287
+ # @param [Integer] recipient_id The ID of the recipient.
288
+ #
289
+ # @return [Boolean] `true` if successful.
290
+ #
291
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-RemoveRecipientFromList
292
+ #
293
+ # @example
294
+ #
295
+ # unsusbcribe = mailup.console.list(2).unsubscribe(126)
296
+ # => true
297
+ #
298
+ def unsubscribe(recipient_id)
299
+ @api.delete("#{@api.path}/List/#{@id}/Unsubscribe/#{recipient_id}")
300
+ end
301
+
302
+ # Get the enabled tag list for the specified list id.
303
+ #
304
+ # @param [Hash] params Optional params or filters:
305
+ # @option params [Integer] :pageNumber The page number to return.
306
+ # @option params [Integer] :pageSize The number of results to per page.
307
+ # @option params [String] :filterby A filtering expression.
308
+ # @option params [String] :orderby The sorting condition for the results.
309
+ #
310
+ # @return [JSON] Results and data including:
311
+ # * IsPaginated [Boolean]
312
+ # * Items [Array<Hash>]
313
+ # * PageNumber [Integer]
314
+ # * PageSize [Integer]
315
+ # * Skipped [Integer]
316
+ # * TotalElementsCount [Integer]
317
+ #
318
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetTags
319
+ #
320
+ # @example
321
+ #
322
+ # tags = mailup.console.list(2).tags
323
+ # tags['TotalElementsCount']
324
+ # => 10
325
+ # tags['Items'].first['Enabled']
326
+ # => true
327
+ #
328
+ def tags(params = {})
329
+ @api.get("#{@api.path}/List/#{@id}/Tags", params: params)
330
+ end
331
+ alias_method :enabled_tags, :tags
332
+
333
+ # Add a new tag in the specified list.
334
+ #
335
+ # @param [String] name The name of the tag to create.
336
+ #
337
+ # @return [JSON] The created Tag with the following attributes:
338
+ # * Id [Integer]
339
+ # * Name [String]
340
+ # * Enabled [Boolean]
341
+ #
342
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-CreateTag
343
+ #
344
+ # @example
345
+ #
346
+ # new_tag = mailup.console.list(2).add_tag("My New Tag")
347
+ #
348
+ def add_tag(tag)
349
+ @api.post("#{@api.path}/List/#{@id}/Tag", body: tag)
350
+ end
351
+
352
+ # Update a tag in the specified list.
353
+ #
354
+ # @param [Hash] tag A hash of tag attributes:
355
+ # @option tag [String] :Name of the tag (required).
356
+ # @option tag [Boolean] :Enabled true if tag is enabled.
357
+ #
358
+ # @return [JSON] The updated Tag with the following attributes:
359
+ # * Id [Integer]
360
+ # * Name [String]
361
+ # * Enabled [Boolean]
362
+ #
363
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-UpdateTag
364
+ #
365
+ # @example
366
+ #
367
+ # tag = {
368
+ # Id: 1,
369
+ # Name: "Updated Tag",
370
+ # Enabled: false
371
+ # }
372
+ # updated_tag = mailup.console.list(2).update_tag(1, tag)
373
+ # updated_tag
374
+ # => false
375
+ #
376
+ def update_tag(tag_id, tag)
377
+ @api.put("#{@api.path}/List/#{@id}/Tag/#{tag_id}", body: tag)
378
+ end
379
+
380
+ # Delete a tag from the specified list.
381
+ #
382
+ # @param [Integer] idTag The ID of the tag to delete.
383
+ #
384
+ # @return [Boolean] `true` if successful.
385
+ #
386
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-DeleteTag
387
+ #
388
+ # Example:
389
+ #
390
+ # delete = mailup.console.list(2).delete_tag(1)
391
+ # => true
392
+ #
393
+ def delete_tag(tag_id)
394
+ @api.delete("#{@api.path}/List/#{@id}/Tag/#{tag_id}")
395
+ end
396
+
397
+ # Get the attachment list for the specific message.
398
+ #
399
+ # @param [Integer] message_id The ID of the message.
400
+ # @param [Hash] params Optional params or filters:
401
+ # @option params [Integer] :pageNumber The page number to return.
402
+ # @option params [Integer] :pageSize The number of results to per page.
403
+ # @option params [String] :filterby A filtering expression.
404
+ # @option params [String] :orderby The sorting condition for the results.
405
+ #
406
+ # @return [JSON] An array of Attachments with the following attributes:
407
+ # * Slot [Integer]
408
+ # * Name [String]
409
+ # * Path [String]
410
+ #
411
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetMessageAttachments
412
+ #
413
+ # @example
414
+ #
415
+ # attachments = mailup.console.list(2).attachments(34)
416
+ # attachments.size
417
+ # => 3
418
+ #
419
+ def attachments(message_id, params = {})
420
+ @api.get("#{@api.path}/List/#{@id}/Email/#{message_id}/Attachment", params: params)
421
+ end
422
+
423
+ # Add an attachment to the specified message.
424
+ #
425
+ # @param [Integer] message_id The ID of the message.
426
+ # @param [Integer] slot The slot for the attachment.
427
+ # @param [Hash] attachment A hash of recipient attributes:
428
+ # @option attachment [String] :Name of the attachment (required).
429
+ # @option attachment [String] :Path of the attachment (required).
430
+ #
431
+ # @return [JSON] The created Attachment with the following attributes:
432
+ # * Slot [Integer]
433
+ # * Name [String]
434
+ # * Path [String]
435
+ #
436
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-AddMessageAttachments
437
+ #
438
+ # @example
439
+ #
440
+ # attachment = {
441
+ # Name: "PDF Attachment",
442
+ # Path: "https://abc123.mailup.com/attachments/..."
443
+ # }
444
+ # attach = mailup.console.list(2).add_attachment(24, 1, attachment)
445
+ # attach.Name
446
+ # => "PDF Attachment"
447
+ #
448
+ def add_attachment(message_id, slot, attachment)
449
+ @api.post("#{@api.path}/List/#{@id}/Email/#{message_id}/Attachment/#{slot}", body: attachment)
450
+ end
451
+
452
+ # Delete an attachment from the specified message.
453
+ #
454
+ # @param [Integer] message_id The ID of the message.
455
+ # @param [Integer] slot The slot of the attachment.
456
+ #
457
+ # @return [Boolean] `true` if successful.
458
+ #
459
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-DeleteMessageAttachments
460
+ #
461
+ # Example:
462
+ #
463
+ # delete = mailup.console.list(2).delete_attachment(49, 3)
464
+ # => true
465
+ #
466
+ def delete_attachment(message_id, slot)
467
+ @api.delete("#{@api.path}/List/#{@id}/Email/#{message_id}/#{slot}")
468
+ end
469
+
470
+ # Get all the images for the specified list.
471
+ #
472
+ # @param [Hash] params Optional params or filters:
473
+ # @option params [Integer] :pageNumber The page number to return.
474
+ # @option params [Integer] :pageSize The number of results to per page.
475
+ # @option params [String] :filterby A filtering expression.
476
+ # @option params [String] :orderby The sorting condition for the results.
477
+ #
478
+ # @return [Array<String>] An array of Image strings.
479
+ #
480
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetListImages
481
+ #
482
+ # @example
483
+ #
484
+ # images = mailup.console.list(2).images
485
+ # images.size
486
+ # => 3
487
+ #
488
+ def images(params = {})
489
+ @api.get("#{@api.path}/List/#{@id}/Images", params: params)
490
+ end
491
+
492
+ # Add a new image to the specified mailing list.
493
+ #
494
+ # @param [Hash] image A hash of Image attributes.
495
+ # @option image [String] Name of the image (required).
496
+ # @option image [String] Data Base64 data for the image (required).
497
+ #
498
+ # @return [String] the created Image URL.
499
+ #
500
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-AddListImage
501
+ #
502
+ # @example
503
+ #
504
+ # image = {
505
+ # Name: "New Image",
506
+ # Data: "..."
507
+ # }
508
+ # new_image = mailup.console.list(2).add_image(image)
509
+ # => "https://mailup.com/images/..."
510
+ #
511
+ def add_image(image)
512
+ @api.post("#{@api.path}/List/#{@id}/Images", body: image)
513
+ end
514
+
515
+ # Create an email message in the specified list id from template.
516
+ #
517
+ # @param [Integer] template_id The ID of the template.
518
+ #
519
+ # @return [JSON] The created Message with the following attributes:
520
+ # * idList [Integer]
521
+ # * idMessage [Integer]
522
+ # * Subject [String]
523
+ #
524
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-CreateEmailMessageFromTemplate
525
+ #
526
+ # @example
527
+ #
528
+ # new_message = mailup.console.list(2).add_message_from_template(5)
529
+ # new_message['Subject']
530
+ # => "Subject From Template"
531
+ #
532
+ def add_message_from_template(template_id)
533
+ @api.post("#{@api.path}/List/#{@id}/Email/Template/#{template_id}")
534
+ end
535
+
536
+ # Create an email message in the specified list id.
537
+ #
538
+ # @param [Hash] message A hash of Message attributes:
539
+ # @option message [String] :Subject of the message (required).
540
+ # @option message [String] :Content of the message (required).
541
+ # @option message [String] :Notes of the message (required).
542
+ # @option message [Boolean] :IsConfirmation if it's a confirmation (required).
543
+ # @option message [Boolean] :Embed this message (required).
544
+ # @option message [Array] :Fields to include (See {MailUp::Console::Email#fields}).
545
+ # @option message [Array] :Tags to include (See {#enabled_tags}).
546
+ #
547
+ # @return [JSON] The created Message with the following attributes:
548
+ # * idList [Integer]
549
+ # * idMessage [Integer]
550
+ # * Subject [String]
551
+ #
552
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-CreateEmailMessage
553
+ #
554
+ # @example
555
+ #
556
+ # new_message = mailup.console.list(2).add_message(message)
557
+ # new_message['Subject']
558
+ # => "Message Subject"
559
+ #
560
+ def add_message(message)
561
+ @api.post("#{@api.path}/List/#{@id}/Email", body: message)
562
+ end
563
+
564
+ # Modify an email message in the specified list id.
565
+ #
566
+ # @param [Integer] message_id The ID of the message.
567
+ # @param [Hash] message A hash of message attributes:
568
+ # @option message [String] :Subject of the message (required).
569
+ # @option message [String] :Content of the message (required).
570
+ # @option message [String] :Notes of the message (required).
571
+ # @option message [Boolean] :IsConfirmation if it's a confirmation (required).
572
+ # @option message [Boolean] :Embed this message (required).
573
+ # @option message [Array] :Fields to include (See {MailUp::Console::Email#fields}).
574
+ # @option message [Array] :Tags to include (See {#enabled_tags}).
575
+ #
576
+ # @return [JSON] The updated Message with the following attributes:
577
+ # * idList [Integer]
578
+ # * idMessage [Integer]
579
+ # * Subject [String]
580
+ #
581
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-UpdateEmailMessage
582
+ #
583
+ # @example
584
+ #
585
+ # update = mailup.console.list(2).update_message(5, message)
586
+ # update['Subject']
587
+ # => "Updated Subject"
588
+ #
589
+ def update_message(message_id, message)
590
+ @api.put("#{@api.path}/List/#{@id}/Email/#{message_id}", body: message)
591
+ end
592
+
593
+ # Modify the email message online visibility.
594
+ #
595
+ # @param [Integer] message_id The ID of the message.
596
+ # @param [Boolean] visibility The visibility of the message.
597
+ #
598
+ # @return [Boolean] `true` if successful.
599
+ #
600
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-UpdateOnlineEmailMessageVisibility
601
+ #
602
+ # @example
603
+ #
604
+ # update = mailup.console.list(2).update_message_visibility(5, true)
605
+ # => true
606
+ #
607
+ def update_message_visibility(message_id, visibility)
608
+ @api.put("#{@api.path}/List/#{@id}/Email/#{message_id}/Online/Visibility", body: visibility)
609
+ end
610
+
611
+ # Delete an email message from the specified list id.
612
+ #
613
+ # @param [Integer] message_id The ID of the message.
614
+ #
615
+ # @return [Boolean] `true` if successful.
616
+ #
617
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-DeleteEmailMessage
618
+ #
619
+ # Example:
620
+ #
621
+ # delete = mailup.console.list(2).delete_message(49)
622
+ # => true
623
+ #
624
+ def delete_message(message_id)
625
+ @api.delete("#{@api.path}/List/#{@id}/Email/#{message_id}")
626
+ end
627
+
628
+ # Retrieve the email message details by specified id.
629
+ #
630
+ # @param [Integer] message_id The ID of the message.
631
+ #
632
+ # @return [JSON] The Message with the following attributes:
633
+ # * Attachments [Array]
634
+ # * Notes [String]
635
+ # * Content [String]
636
+ # * Fields [Array]
637
+ # * Tags [Array]
638
+ # * Embed [Boolean]
639
+ # * IsConfirmation [Boolean]
640
+ # * idList [Integer]
641
+ # * idMessage [Integer]
642
+ # * Subject [String]
643
+ #
644
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetMessageDetails
645
+ # Example:
646
+ #
647
+ # message = mailup.console.list(2).message_details(49)
648
+ # message['Subject']
649
+ # => "Message Subject"
650
+ #
651
+ def message_details(message_id)
652
+ @api.get("#{@api.path}/List/#{@id}/Email/#{message_id}")
653
+ end
654
+
655
+ # Retrieve email messages (cloned and uncloned) for this list.
656
+ #
657
+ # @param [Hash] params Optional params or filters:
658
+ # @option params [Integer] :pageNumber The page number to return.
659
+ # @option params [Integer] :pageSize The number of results to per page.
660
+ # @option params [String] :filterby A filtering expression.
661
+ # @option params [String] :orderby The sorting condition for the results.
662
+ #
663
+ # @return [JSON] Results and data including:
664
+ # * IsPaginated [Boolean]
665
+ # * Items [Array<Hash>]
666
+ # * PageNumber [Integer]
667
+ # * PageSize [Integer]
668
+ # * Skipped [Integer]
669
+ # * TotalElementsCount [Integer]
670
+ #
671
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetMailMessagesByList
672
+ #
673
+ # @example
674
+ #
675
+ # emails = mailup.console.list(2).emails
676
+ # emails['TotalElementsCount']
677
+ # => 10
678
+ # emails['Items'].first['Subject']
679
+ # => "Test Subject"
680
+ # emails['Items'].first['idList']
681
+ # => 2
682
+ #
683
+ def emails(params = {})
684
+ @api.get("#{@api.path}/List/#{@id}/Emails", params: params)
685
+ end
686
+
687
+ # Retrieve the email messages visible online through the website by the specified list id.
688
+ #
689
+ # @param [Hash] params Optional params or filters:
690
+ # @option params [Integer] :pageNumber The page number to return.
691
+ # @option params [Integer] :pageSize The number of results to per page.
692
+ # @option params [String] :filterby A filtering expression.
693
+ # @option params [String] :orderby The sorting condition for the results.
694
+ #
695
+ # @return [JSON] Results and data including:
696
+ # * IsPaginated [Boolean]
697
+ # * Items [Array<Hash>]
698
+ # * PageNumber [Integer]
699
+ # * PageSize [Integer]
700
+ # * Skipped [Integer]
701
+ # * TotalElementsCount [Integer]
702
+ #
703
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetPublishedMailMessagesByList
704
+ #
705
+ # @example
706
+ #
707
+ # emails = mailup.console.list(2).online_emails
708
+ # emails['TotalElementsCount']
709
+ # => 10
710
+ # emails['Items'].first['Subject']
711
+ # => "Test Subject"
712
+ # emails['Items'].first['idList']
713
+ # => 1
714
+ #
715
+ def online_emails(params = {})
716
+ @api.get("#{@api.path}/List/#{@id}/Online/Emails", params: params)
717
+ end
718
+ alias_method :visible_emails, :online_emails
719
+
720
+ # Retrieve the archived email messages by the specified list id.
721
+ #
722
+ # @param [Hash] params Optional params or filters:
723
+ # @option params [Integer] :pageNumber The page number to return.
724
+ # @option params [Integer] :pageSize The number of results to per page.
725
+ # @option params [String] :filterby A filtering expression.
726
+ # @option params [String] :orderby The sorting condition for the results.
727
+ #
728
+ # @return [JSON] Results and data including:
729
+ # * IsPaginated [Boolean]
730
+ # * Items [Array<Hash>]
731
+ # * PageNumber [Integer]
732
+ # * PageSize [Integer]
733
+ # * Skipped [Integer]
734
+ # * TotalElementsCount [Integer]
735
+ #
736
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetArchivedMailMessagesByList
737
+ #
738
+ # @example
739
+ #
740
+ # emails = mailup.console.list(2).archived_emails
741
+ # emails.size
742
+ # => 10
743
+ # emails['Items'].first['Subject']
744
+ # => "Test Subject"
745
+ # emails['Items'].first['idList']
746
+ # => 1
747
+ #
748
+ def archived_emails(params = {})
749
+ @api.get("#{@api.path}/List/#{@id}/Archived/Emails", params: params)
750
+ end
751
+
752
+ # Get email message send history.
753
+ #
754
+ # @param [Integer] message_id The ID of the message.
755
+ # @param [Hash] params Optional params or filters:
756
+ # @option params [Integer] :pageNumber The page number to return.
757
+ # @option params [Integer] :pageSize The number of results to per page.
758
+ # @option params [String] :filterby A filtering expression.
759
+ # @option params [String] :orderby The sorting condition for the results.
760
+ #
761
+ # @return [JSON] Results and data including:
762
+ # * IsPaginated [Boolean]
763
+ # * Items [Array<Hash>]
764
+ # * PageNumber [Integer]
765
+ # * PageSize [Integer]
766
+ # * Skipped [Integer]
767
+ # * TotalElementsCount [Integer]
768
+ #
769
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetMailMessageSendHistory
770
+ #
771
+ # @example
772
+ #
773
+ # history = mailup.console.list(2).send_history(5)
774
+ # history['TotalElementsCount']
775
+ # => 10
776
+ #
777
+ def send_history(message_id, params = {})
778
+ @api.get("#{@api.path}/List/#{@id}/Email/#{message_id}/SendHistory", params: params)
779
+ end
780
+
781
+ # Send an email message to the recipients in the specified list.
782
+ #
783
+ # @param [Integer] message_id The ID of the list.
784
+ #
785
+ # @return [JSON] A Send object with the following attributes:
786
+ # * idMessage [Integer]
787
+ # * Sent [Integer]
788
+ # * UnprocessedRecipients [Array]
789
+ # * InvalidRecipients [Array]
790
+ #
791
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-SendMailMessageToRecipientInList
792
+ #
793
+ # @example
794
+ #
795
+ # send = mailup.console.list(2).send_message(5)
796
+ # send['Sent']
797
+ # => 1794
798
+ #
799
+ def send_message(message_id)
800
+ @api.post("#{@api.path}/List/#{@id}/Email/#{message_id}/Send")
801
+ end
802
+
803
+ # Retrieve the list of the current defined message templates in the specified list.
804
+ #
805
+ # @param [Hash] params Optional params or filters:
806
+ # @option params [Integer] :pageNumber The page number to return.
807
+ # @option params [Integer] :pageSize The number of results to per page.
808
+ # @option params [String] :filterby A filtering expression.
809
+ # @option params [String] :orderby The sorting condition for the results.
810
+ #
811
+ # @return [JSON] Results and data including:
812
+ # * IsPaginated [Boolean]
813
+ # * Items [Array<Hash>]
814
+ # * PageNumber [Integer]
815
+ # * PageSize [Integer]
816
+ # * Skipped [Integer]
817
+ # * TotalElementsCount [Integer]
818
+ #
819
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetEmailTemplates
820
+ #
821
+ # @example
822
+ #
823
+ # templates = mailup.console.list(2).templates
824
+ # templates['TotalElementsCount']
825
+ # => 10
826
+ # templates['Items'].first['Id']
827
+ # => 278
828
+ #
829
+ def templates(params = {})
830
+ @api.get("#{@api.path}/List/#{@id}/Templates", params: params)
831
+ end
832
+
833
+ # Retrieve the details for the specified message template in the specified list.
834
+ #
835
+ # @param [Integer] template_id The ID of the template.
836
+ # @param [Hash] params Optional params or filters:
837
+ # @option params [Integer] :pageNumber The page number to return.
838
+ # @option params [Integer] :pageSize The number of results to per page.
839
+ # @option params [String] :filterby A filtering expression.
840
+ # @option params [String] :orderby The sorting condition for the results.
841
+ #
842
+ # @return [JSON>] A Template object with the following attributes:
843
+ # * Content [String]
844
+ # * Id [Integer]
845
+ # * Title [String]
846
+ # * Text [String]
847
+ # * Thumbnail [String]
848
+ #
849
+ # @see http://help.mailup.com/display/mailupapi/Console+methods+v1.1#Consolemethodsv1.1-GetEmailTemplateDetails
850
+ #
851
+ # @example
852
+ #
853
+ # template = mailup.console.list(2).template_details(15)
854
+ # template.Id
855
+ # => 15
856
+ #
857
+ def template_details(template_id)
858
+ @api.get("#{@api.path}/List/#{@id}/Templates/#{template_id}")
859
+ end
860
+
861
+ end
862
+ end
863
+ end