hominid 2.2.0 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,476 +1,32 @@
1
1
  module Hominid
2
2
  module List
3
3
 
4
- # Get all the lists for this account.
5
- def lists
6
- call("lists")
7
- end
8
-
9
- # Find a mailing list by name
4
+ # Find a list by name
10
5
  def find_list_by_name(list_name)
11
- call("lists").find {|list| list["name"] == list_name}
6
+ lists['data'].find {|l| l["name"] == list_name}
12
7
  end
13
8
 
14
- # Find a mailing list ID by name, returns nil if no list found
9
+ # Find a list ID by name, returns nil if no list found
15
10
  def find_list_id_by_name(list_name)
16
11
  list = find_list_by_name(list_name)
17
12
  list && list["id"]
18
13
  end
19
14
 
20
- # Find a mailing list by ID
15
+ # Find a list by ID
21
16
  def find_list_by_id(list_id)
22
- call("lists").find {|list| list["id"] == list_id}
17
+ lists['data'].find {|l| l["id"] == list_id}
23
18
  end
24
19
 
25
- # Find a mailing list by web_id
20
+ # Find a list by web_id
26
21
  def find_list_by_web_id(list_web_id)
27
- call("lists").find {|list| list["web_id"] == list_web_id}
22
+ lists['data'].find {|l| l["web_id"] == list_web_id}
28
23
  end
29
24
 
30
- # Find a mailing list ID by web_id, returns nil if no list found
25
+ # Find a list ID by web_id, returns nil if no list found
31
26
  def find_list_id_by_web_id(list_web_id)
32
27
  list = find_list_by_web_id(list_web_id)
33
28
  list && list["id"]
34
29
  end
35
30
 
36
- # Find all the mailing lists IDs that an email address is subscribed to
37
- def find_list_ids_by_email(email)
38
- call("listsForEmail", email)
39
- end
40
-
41
- # Get all email addresses that complained about a given list.
42
- #
43
- # Parameters:
44
- # * list_id (String) = The mailing list ID value.
45
- # * list_id (String) = The mailing list ID value.
46
- # * start (Integer) = Page number to start at. Defaults to 0.
47
- # * limit (Integer) = Number of results to return. Defaults to 500. Upper limit is 1000.
48
- # * since (DateTime) = Only return email reports since this date. Must be in YYYY-MM-DD HH:II:SS format (GMT).
49
- #
50
- # Returns:
51
- # An array of abuse reports for this list including:
52
- # * date (String) = Date/time the abuse report was received and processed.
53
- # * email (String) = The email address that reported abuse.
54
- # * campaign_id (String) = The unique id for the campaign that report was made against.
55
- # * type (String) = An internal type generally specifying the orginating mail provider - may not be useful outside of filling report views.
56
- #
57
- def list_abuse_reports(list_id, start = 0, limit = 500, since = "2000-01-01 00:00:00")
58
- call("listAbuseReports", list_id, start, limit, since)
59
- end
60
-
61
- # Add a single Interest Group - if interest groups for the List are not yet
62
- # enabled, adding the first group will automatically turn them on.
63
- #
64
- # Parameters:
65
- # * list_id (String) = The mailing list ID value.
66
- # * group (String) = The interest group to add.
67
- # * grouping_id (String) = The grouping to add the new group to. If not supplied, the first grouping on the list is used.
68
- #
69
- # Returns:
70
- # True if successful, error code if not.
71
- #
72
- def create_group(list_id, group, grouping_id)
73
- call("listInterestGroupAdd", list_id, group, grouping_id)
74
- end
75
- alias :interest_group_add :create_group
76
-
77
- # Add a new Interest Grouping - if interest groups for the List are not yet
78
- # enabled, adding the first grouping will automatically turn them on.
79
- #
80
- # Parameters:
81
- # * list_id (String) = The mailing list ID value.
82
- # * name (String) = The interest grouping to add - grouping names must be unique
83
- # * type (String) = The type of the grouping to add - one of "checkboxes", "hidden", "dropdown", "radio"
84
- # * groups (Array) = The lists of initial group names to be added - at least 1 is required and the names must be unique within a grouping. If the number takes you over the 60 group limit, an error will be thrown.
85
- #
86
- # Returns:
87
- # The new grouping id if the request succeeds, otherwise an error will be thrown.
88
- #
89
- def create_grouping(list_id, name, type, groups)
90
- call("listInterestGroupingAdd", list_id, name, type, groups)
91
- end
92
- alias :interest_grouping_add :create_grouping
93
-
94
- # Add a new merge tag to a given list
95
- #
96
- # Parameters:
97
- # * list_id (String) = The mailing list ID value.
98
- # * tag (String) = The merge tag to add. Ex: FNAME
99
- # * name (String) = The long description of the tag being added, used for user displays.
100
- # * required (Boolean) = TODO: set this up to accept the options available.
101
- #
102
- # Returns:
103
- # True if successful, error code if not.
104
- #
105
- def create_tag(list_id, tag, name, required = false)
106
- call("listMergeVarAdd", list_id, tag, name, required)
107
- end
108
- alias :merge_var_add :create_tag
109
-
110
- # Add a new Webhook URL for the given list
111
- #
112
- # Parameters:
113
- # * list_id (String) = The mailing list ID value.
114
- # * url (String) = A valid URL for the Webhook - it will be validated.
115
- # * actions (Hash) = A hash of actions to fire this Webhook for including:
116
- # * :subscribe (Boolean) - defaults to true.
117
- # * :unsubscribe (Boolean) - defaults to true.
118
- # * :profile (Boolean) - defaults to true.
119
- # * :cleaned (Boolean) - defaults to true.
120
- # * :upemail (Boolean) - defaults to true.
121
- # * sources (Hash) = A hash of sources to fire this Webhook for including:
122
- # * :user (Boolean) - defaults to true.
123
- # * :admin (Boolean) - defaults to true.
124
- # * :api (Boolean) - defaults to false.
125
- #
126
- # See the Mailchimp API documentation for more information.
127
- #
128
- # Returns:
129
- # True if successful, error code if not.
130
- #
131
- def create_webhook(list_id, url, actions = {}, sources = {})
132
- call("listWebhookAdd", list_id, url, actions, sources)
133
- end
134
- alias :webhook_add :create_webhook
135
-
136
- # Delete a single Interest Group - if the last group for a list
137
- # is deleted, this will also turn groups for the list off.
138
- #
139
- # Parameters:
140
- # * list_id (String) = The mailing list ID value.
141
- # * group (String) = The interest group to delete.
142
- #
143
- # Returns:
144
- # True if successful, error code if not.
145
- #
146
- def delete_group(list_id, group)
147
- call("listInterestGroupDel", list_id, group)
148
- end
149
- alias :interest_group_del :delete_group
150
-
151
- # Delete an existing Interest Grouping - this will permanently delete
152
- # all contained interest groups and will remove those selections from all list members.
153
- #
154
- # Parameters:
155
- # * grouping_id (Integer) = The interest grouping id.
156
- #
157
- # Returns:
158
- # True if the request succeeds, otherwise an error will be thrown.
159
- #
160
- def delete_grouping(grouping_id)
161
- call("listInterestGroupingDel", grouping_id)
162
- end
163
- alias :interest_grouping_del :delete_grouping
164
-
165
- # Delete a merge tag from a given list and all its members.
166
- # Seriously - the data is removed from all members as well!
167
- # Note that on large lists this method may seem a bit slower
168
- # than calls you typically make.
169
- #
170
- # Parameters:
171
- # * list_id (String) = The mailing list ID value.
172
- # * tag (String) = The merge tag to delete.
173
- #
174
- # Returns:
175
- # True if successful, error code if not.
176
- #
177
- def delete_tag(list_id, tag)
178
- call("listMergeVarDel", list_id, tag)
179
- end
180
- alias :merge_var_del :delete_tag
181
-
182
- # Delete an existing Webhook URL from a given list.
183
- #
184
- # Parameters:
185
- # * list_id (String) = The mailing list ID value.
186
- # * url (String) = The URL of a Webhook on this list.
187
- #
188
- # Returns:
189
- # True if successful, error code if not.
190
- #
191
- def delete_webhook(list_id, url)
192
- call("listWebhookDel", list_id, url)
193
- end
194
- alias :webhook_del :delete_webhook
195
-
196
- # Get the list of interest groups for a given list, including
197
- # the label and form information.
198
- #
199
- # Parameters:
200
- # * list_id (String) = The mailing list ID value.
201
- #
202
- # Returns:
203
- # A struct of interest groups for this list:
204
- # * name (String) = Name for the Interest group.
205
- # * form_field (String) = Gives the type of interest group: checkbox, radio, select, etc.
206
- # * groups (Array) = Array of the group names
207
- #
208
- def groups(list_id)
209
- call("listInterestGroups", list_id)
210
- end
211
- alias :interest_groups :groups
212
-
213
- # Get the list of interest groupings for a given list, including
214
- # the label, form information, and included groups for each.
215
- #
216
- # Parameters:
217
- # * list_id (String) = The list id to connect to.
218
- #
219
- # Returns:
220
- # A struct of interest groupings for the list:
221
- # * id (String) = The id for the Grouping
222
- # * name (String) = Name for the Interest groups
223
- # * form_field (String) = Gives the type of interest group: checkbox,radio,select
224
- # * groups (Array) = Array of the grouping options including the "bit" value, "name", "display_order", and number of "subscribers" with the option selected.
225
- #
226
- def groupings(list_id)
227
- call("listInterestGroupings", list_id)
228
- end
229
- alias :interest_groupings :groupings
230
-
231
- # Access the Growth History by Month for a given list.
232
- #
233
- # Parameters:
234
- # * list_id (String) = The mailing list ID value.
235
- # * group (String) = The interest group to delete.
236
- #
237
- # Returns:
238
- # An array of months and growth with the following fields:
239
- # * month (String) = The Year and Month in question using YYYY-MM format.
240
- # * existing (Integer) = Number of existing subscribers to start the month.
241
- # * imports (Integer) = Number of subscribers imported during the month.
242
- # * optins (Integer) = Number of subscribers who opted-in during the month.
243
- #
244
- def growth_history(list_id)
245
- call("listGrowthHistory", list_id)
246
- end
247
-
248
- # Get all the information for a particular member of a list.
249
- #
250
- # Parameters:
251
- # * list_id (String) = The mailing list ID value.
252
- # * email (String) = the member email address to get information for OR the "id" for the member returned from listMemberInfo, Webhooks, and Campaigns
253
- #
254
- # Returns:
255
- # An array of list member info with the following fields:
256
- # * id (String) = The unique id for this email address on an account.
257
- # * email (String) = The email address associated with this record.
258
- # * email_type (String) = The type of emails this customer asked to get: html, text, or mobile.
259
- # * merges (Array) = An associative array of all the merge tags and the data for those tags for this email address. Note: Interest Groups are returned as comma delimited strings - if a group name contains a comma, it will be escaped with a backslash. ie, "," => "\,"
260
- # * status (String) = The subscription status for this email address, either subscribed, unsubscribed or cleaned.
261
- # * ip_opt (String) = IP Address this address opted in from.
262
- # * ip_signup (String) = IP Address this address signed up from.
263
- # * campaign_id (String) = If the user is unsubscribed and they unsubscribed from a specific campaign, that campaign_id will be listed, otherwise this is not returned.
264
- # * lists (Array) = An associative array of the other lists this member belongs to - the key is the list id and the value is their status in that list.
265
- # * timestamp (Date) = The time this email address was added to the list
266
- # * info_changed (Date) = The last time this record was changed. If the record is old enough, this may be blank.
267
- # * web_id (Integer) = The Member id used in our web app, allows you to create a link directly to it.
268
- #
269
- def member_info(list_id, email)
270
- call("listMemberInfo", list_id, email)
271
- end
272
-
273
- # Get all of the list members for a list that are of a particular status.
274
- #
275
- # Parameters:
276
- # * list_id (String) = The mailing list ID value.
277
- # * status (String) = One of subscribed, unsubscribed, cleaned, updated.
278
- # * since (Datetime) = Pull all members whose status (subscribed/unsubscribed/cleaned) has changed or whose profile (updated) has changed since this date/time (in GMT).
279
- # * start (Integer) = The page number to start at - defaults to 0.
280
- # * limit (integer) = The number of results to return - defaults to 100, upper limit set at 15000.
281
- #
282
- # Returns:
283
- # An array of list member structs:
284
- # * email (String) = Member email address.
285
- # * timestamp (DateTime) = timestamp of their associated status date in GMT.
286
- #
287
- def members(list_id, status = "subscribed", since = "2000-01-01 00:00:00", start = 0, limit = 100)
288
- call("listMembers", list_id, status, since, start, limit)
289
- end
290
-
291
- # Use the Mailchimp Export API to get all list members for a list
292
- #
293
- # Parameters:
294
- # * list_id (String) = The mailing list ID value.
295
- # * status (String) = One of subscribed, unsubscribed, cleaned, updated. Defaults to subscribed.
296
- #
297
- # Returns:
298
- # An array of user record structs, keyed by the merge field name
299
- #
300
- def export(list_id, status=nil)
301
- call_export(list_id, status)
302
- end
303
-
304
- # Get the list of merge tags for a given list, including their name, tag, and required setting.
305
- #
306
- # Parameters:
307
- # * list_id (String) = The mailing list ID value.
308
- #
309
- # Returns:
310
- # An array of merge tags for this list:
311
- # * name (String) = Name of the merge field.
312
- # * req (Char) = Denotes whether the field is required (Y) or not (N).
313
- # * tag (String) = The merge tag.
314
- def merge_tags(list_id)
315
- call("listMergeVars", list_id)
316
- end
317
- alias :merge_vars :merge_tags
318
-
319
- # Allows one to test their segmentation rules before creating a campaign using them.
320
- #
321
- # Parameters:
322
- # * list_id (String) = The mailing list ID value.
323
- # * options (Hash) = Please refer to the Mailchimp API documentation for more information.
324
- #
325
- # Returns:
326
- #
327
- #
328
- def segment_test(list_id, options = {})
329
- call("campaignSegmentTest", list_id, options)
330
- end
331
-
332
- # Subscribe the provided email to a list.
333
- #
334
- # Parameters:
335
- # * list_id (String) = The mailing list ID value.
336
- # * email (String) = The email address to subscribe.
337
- # * merge_vars (Hash) = A hash of the merge tags that you want to include.
338
- #
339
- # Returns:
340
- # True on success, false on failure.
341
- #
342
- def subscribe(list_id, email, merge_vars = {}, options = {})
343
- merge_tags = clean_merge_tags merge_vars
344
- options = apply_defaults_to({:email_type => "html"}.merge(options))
345
- call(
346
- "listSubscribe",
347
- list_id,
348
- email,
349
- merge_tags,
350
- *options.values_at(
351
- :email_type,
352
- :double_opt_in,
353
- :update_existing,
354
- :replace_interests,
355
- :send_welcome
356
- )
357
- )
358
- end
359
-
360
- # Subscribe a batch of email addresses to a list at once.
361
- #
362
- # Parameters:
363
- # * list_id (String) = The mailing list ID value.
364
- # * subscribers (Array) = An array of email addresses to subscribe.
365
- # * merge_vars (Hash) = A hash of subscription options. See the Mailchimp API documentation.
366
- #
367
- # Returns:
368
- # An array of result counts and errors:
369
- # * success_count (Integer) = Number of email addresses that were succesfully added/updated.
370
- # * error_count (Integer) = Number of email addresses that failed during addition/updating.
371
- # * errors (Array) = Array of error structs. Each error struct will contain "code", "message", and the full struct that failed.
372
- #
373
- def subscribe_many(list_id, subscribers, options = {})
374
- subscribers = subscribers.collect { |subscriber| clean_merge_tags(subscriber) }
375
- options = apply_defaults_to({:update_existing => true}.merge(options))
376
- call("listBatchSubscribe", list_id, subscribers, *options.values_at(:double_opt_in, :update_existing, :replace_interests))
377
- end
378
- alias :batch_subscribe :subscribe_many
379
-
380
- # Unsubscribe the given email address from the list.
381
- #
382
- # Parameters:
383
- # * list_id (String) = The mailing list ID value.
384
- # * current_email (String) = The email address to unsubscribe OR the email "id".
385
- # * options (Hash) = A hash of unsubscribe options including:
386
- # * :delete_member (defaults to true)
387
- # * :send_goodbye (defaults to false)
388
- # * :send_notify (defaults to false).
389
- #
390
- # Returns:
391
- # True on success, false on failure
392
- #
393
- def unsubscribe(list_id, current_email, options = {})
394
- options = apply_defaults_to({:delete_member => true}.merge(options))
395
- call("listUnsubscribe", list_id, current_email, *options.values_at(:delete_member, :send_goodbye, :send_notify))
396
- end
397
-
398
- # Unsubscribe a batch of email addresses to a list.
399
- #
400
- # Parameters:
401
- # * list_id (String) = The mailing list ID value.
402
- # * emails (Array) = An array of subscriber hashes with EMAIL and EMAIL_TYPE as keys.
403
- # * options (Hash) = A hash of unsubscribe options including:
404
- # * :delete_member (defaults to true)
405
- # * :send_goodbye (defaults to false)
406
- # * :send_notify (defaults to false)
407
- #
408
- # Returns:
409
- #
410
- def unsubscribe_many(list_id, emails, options = {})
411
- options = apply_defaults_to({:delete_member => true}.merge(options))
412
- call("listBatchUnsubscribe", list_id, emails, *options.values_at(:delete_member, :send_goodbye, :send_notify))
413
- end
414
- alias :batch_unsubscribe :unsubscribe_many
415
-
416
- # Change the name of an Interest Group.
417
- #
418
- # Parameters:
419
- # * list_id (String) = The mailing list ID value.
420
- # * old_name (String) = The interest group name to be changed.
421
- # * new_name (String) = The new interest group name to be set.
422
- #
423
- # Returns:
424
- # True if successful, error code if not.
425
- #
426
- def update_group(list_id, old_name, new_name)
427
- call("listInterestGroupUpdate", list_id, old_name, new_name)
428
- end
429
-
430
- # Update an existing Interest Grouping.
431
- #
432
- # Parameters:
433
- # * grouping_id (String) = The interest grouping ID.
434
- # * name (String) = The name of the field to update - either "name" or "type".
435
- # * value (String) = The new value of the field.
436
- #
437
- # Returns:
438
- # True if successful, error code if not.
439
- #
440
- def update_grouping(grouping_id, name, value)
441
- call("listInterestGroupingUpdate", grouping_id, name, value)
442
- end
443
-
444
- # Edit the email address, merge fields, and interest groups for a list member.
445
- #
446
- # Parameters:
447
- # * list_id (String) = The mailing list ID value.
448
- # * email (String) = The current email address of the member to update OR the "id" for the member.
449
- # * merge_tags (Hash) = Hash of new field values to update the member with. Ex: {FNAME => 'Bob', :LNAME => 'Smith'}
450
- # * email_type (String) = One of 'html', 'text', or 'mobile'.
451
- # * replace_interests (Boolean) = Whether or not to replace the interest groups with the updated groups provided.
452
- #
453
- # Returns:
454
- # True on success, false on failure
455
- #
456
- def update_member(list_id, email, merge_tags = {}, email_type = "html", replace_interests = true)
457
- call("listUpdateMember", list_id, email, merge_tags, email_type, replace_interests)
458
- end
459
-
460
- # Return the Webhooks configured for the given list.
461
- #
462
- # Parameters:
463
- # * list_id (String) = The mailing list ID value.
464
- #
465
- # Returns:
466
- # An array of webhooks for this list including:
467
- # * url (String) = The URL for this Webhook.
468
- # * action (Array) = The possible actions and whether they are enabled.
469
- # * sources (Array) = The possible sources and whether they are enabled.
470
- #
471
- def webhooks(list_id)
472
- call("listWebhooks", list_id)
473
- end
474
-
475
31
  end
476
32
  end