Class: MailChimp

Inherits:
Object
  • Object
show all
Defined in:
lib/mail_chimp.rb

Overview

ruby-mailchimp

ruby-mailchimp is designed to allow you to use Ruby to subscribe or unsubscribe users to an existing MailChimp (www.mailchimp.com) account. You will need the following:

  • MailChimp Account: MailChimp is free to sign up for and only charges for sent messages

The API is basically a wrapper on MailChimp’s XML-RPC API. For more details on what variables mean, you can reference their API specification at: www.mailchimp.com/api/.

I’m leaving the subscribe/unsubscribe mail processor code in for now, but it is deprecated and will be removed in a future release. The ability to query MailChimp using their XML-RPC API has eliminated the need to process mails to keep the lists in sync.

Author
    1. Brown (mailto: [email protected])

Copyright

Copyright © 2007-8 One Percent Software/ProjectLocker

License

Apache Software License

Example Usage:

  • Logging In (required before all other functions): - bonobo = MailChimp.new uid = bonobo.login(“MailChimpUsername”, “MailChimpPassword”)

  • Obtaining a List - list = bonobo.getListByName(uid, “My List on MailChimp”) list_id = list

  • Subscribing a User: - bonobo.listSubscribe(uid, list_id, “[email protected]”, {})

  • Subscribing a User with Merge Data: - bonobo.listSubscribe(uid, list_id, “[email protected]”, “LNAME”=>‘Jones’)

  • Unsubscribing a User: - bonobo.listUnsubscribe(uid, list_id, “[email protected]”)

Defined Under Namespace

Classes: Processor

Constant Summary collapse

API_URL =
"http://api.mailchimp.com/1.1/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clientObject

Returns the value of attribute client.



46
47
48
# File 'lib/mail_chimp.rb', line 46

def client
  @client
end

#email_passwordObject

Returns the value of attribute email_password.



46
47
48
# File 'lib/mail_chimp.rb', line 46

def email_password
  @email_password
end

#email_serverObject

Returns the value of attribute email_server.



46
47
48
# File 'lib/mail_chimp.rb', line 46

def email_server
  @email_server
end

#email_userObject

Returns the value of attribute email_user.



46
47
48
# File 'lib/mail_chimp.rb', line 46

def email_user
  @email_user
end

Instance Method Details

#apikeyAdd(username, password, new_key) ⇒ Object



54
55
56
57
# File 'lib/mail_chimp.rb', line 54

def apikeyAdd(username, password, new_key)
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("apikeyAdd", username, password, new_key)
end

#apikeyExpire(username, password, new_key) ⇒ Object



59
60
61
62
# File 'lib/mail_chimp.rb', line 59

def apikeyExpire(username, password, new_key)
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("apikeyExpire", username, password, new_key)
end

#apikeys(username, password, uid, include_expired = false) ⇒ Object



64
65
66
67
# File 'lib/mail_chimp.rb', line 64

def apikeys(username, password, uid, include_expired=false)
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("apikeys", username, password, uid, include_expired)  
end

#campaignAbuseReports(uid, campaign_id, start, limit) ⇒ Object

CAMPAIGN STATS METHODS



239
240
241
242
243
# File 'lib/mail_chimp.rb', line 239

def campaignAbuseReports(uid, campaign_id, start, limit)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignAbuseReports", uid, campaign_id, start, limit)      
end

#campaignClickDetailAIM(uid, campaign_id, url, start, limit) ⇒ Object

CAMPAIGN AIM METHODS



205
206
207
208
209
# File 'lib/mail_chimp.rb', line 205

def campaignClickDetailAIM(uid, campaign_id, url, start, limit)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignClickDetailAIM", uid, campaign_id, url, start, limit)  
end

#campaignClickStats(uid, campaign_id) ⇒ Object



245
246
247
248
249
# File 'lib/mail_chimp.rb', line 245

def campaignClickStats(uid, campaign_id)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignClickStats", uid, campaign_id)      
end

#campaignContent(uid, campaign_id) ⇒ Object

CAMPAIGN METHODS



279
280
281
282
283
# File 'lib/mail_chimp.rb', line 279

def campaignContent(uid, campaign_id)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignContent", uid, campaign_id)      
end

#campaignCreate(uid, campaign_type, options, content, segment_options, type_options) ⇒ Object



285
286
287
288
289
290
# File 'lib/mail_chimp.rb', line 285

def campaignCreate(uid, campaign_type, options, content, segment_options, type_options)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  raise StandardError("Unknown campaign type #{campaign_type}") unless %w(regular plaintext absplit rss trans).include?(campaign_type)
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignCreate", uid, campaign_type, options, content, segment_options, type_options)      
end

#campaignEcommAddOrder(uid, order_info, campaign_id, plugin_info) ⇒ Object



292
293
294
295
296
# File 'lib/mail_chimp.rb', line 292

def campaignEcommAddOrder(uid, order_info, campaign_id, plugin_info)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignEcommAddOrder", uid, order_info, campaign_id, plugin_info)    
end

#campaignEmailStatsAIM(uid, campaign_id, email_address) ⇒ Object



211
212
213
214
215
# File 'lib/mail_chimp.rb', line 211

def campaignEmailStatsAIM(uid, campaign_id, email_address)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignEmailStatsAIM", uid, campaign_id, email_address)      
end

#campaignEmailStatsAIMAll(uid, campaign_id, start, limit) ⇒ Object



217
218
219
220
221
# File 'lib/mail_chimp.rb', line 217

def campaignEmailStatsAIMAll(uid, campaign_id, start, limit)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignEmailStatsAIMAll", uid, campaign_id, start, limit)      
end

#campaignFolders(uid) ⇒ Object



298
299
300
301
302
# File 'lib/mail_chimp.rb', line 298

def campaignFolders(uid)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignFolders", uid)        
end

#campaignHardBounces(uid, campaign_id, start, limit) ⇒ Object



251
252
253
254
255
# File 'lib/mail_chimp.rb', line 251

def campaignHardBounces(uid, campaign_id, start, limit)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignHardBounces", uid, campaign_id, start, limit)      
end

#campaignNotOpenedAIM(uid, campaign_id, start, limit) ⇒ Object



223
224
225
226
227
# File 'lib/mail_chimp.rb', line 223

def campaignNotOpenedAIM(uid, campaign_id, start, limit)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignNotOpenedAIM", uid, campaign_id, start, limit)      
end

#campaignOpenedAIM(uid, campaign_id, start, limit) ⇒ Object



229
230
231
232
233
# File 'lib/mail_chimp.rb', line 229

def campaignOpenedAIM(uid, campaign_id, start, limit)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignOpenedAIM", uid, campaign_id, start, limit)      
end

#campaignPause(uid, campaign_id) ⇒ Object



304
305
306
307
308
# File 'lib/mail_chimp.rb', line 304

def campaignPause(uid, campaign_id)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignPause", uid, campaign_id)      
end

#campaignResume(uid, campaign_id) ⇒ Object



310
311
312
313
314
# File 'lib/mail_chimp.rb', line 310

def campaignResume(uid, campaign_id)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignResume", uid, campaign_id)      
end

#campaigns(uid, filter_id, filter_folder, filter_fromname, filter_fromemail, filter_title, filter_subject, filter_sendtimestart, filter_sendtimeend, filter_exact, start, limit) ⇒ Object



358
359
360
361
362
# File 'lib/mail_chimp.rb', line 358

def campaigns(uid, filter_id, filter_folder, filter_fromname, filter_fromemail, filter_title, filter_subject, filter_sendtimestart, filter_sendtimeend, filter_exact, start, limit)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaigns", uid, filter_id, filter_folder, filter_fromname, filter_fromemail, filter_title, filter_subject, filter_sendtimestart, filter_sendtimeend, filter_exact, start, limit)
end

#campaignSchedule(uid, campaign_id, schedule_time, schedule_time_b) ⇒ Object



316
317
318
319
320
# File 'lib/mail_chimp.rb', line 316

def campaignSchedule(uid, campaign_id, schedule_time, schedule_time_b)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignSchedule", uid, campaign_id, schedule_time, schedule_time_b)      
end

#campaignSegmentTest(uid, list_id, options) ⇒ Object



322
323
324
325
326
# File 'lib/mail_chimp.rb', line 322

def campaignSegmentTest(uid, list_id, options)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignSegmentTest", uid, campaign_id, options)      
end

#campaignSendNow(uid, campaign_id) ⇒ Object



328
329
330
331
332
# File 'lib/mail_chimp.rb', line 328

def campaignSendNow(uid, campaign_id)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignSendNow", uid, campaign_id)      
end

#campaignSoftBounces(uid, campaign_id, start, limit) ⇒ Object



257
258
259
260
261
# File 'lib/mail_chimp.rb', line 257

def campaignSoftBounces(uid, campaign_id, start, limit)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignSoftBounces", uid, campaign_id, start, limit)      
end

#campaignStats(uid, campaign_id) ⇒ Object



263
264
265
266
267
# File 'lib/mail_chimp.rb', line 263

def campaignStats(uid, campaign_id)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignStats", uid, campaign_id)      
end

#campaignTemplates(uid) ⇒ Object



340
341
342
343
344
# File 'lib/mail_chimp.rb', line 340

def campaignTemplates(uid) 
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignTemplates", uid)      
end

#campaignUnschedule(uid, campaign_id) ⇒ Object



346
347
348
349
350
# File 'lib/mail_chimp.rb', line 346

def campaignUnschedule(uid, campaign_id)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignUnschedule", uid, campaign_id)      
end

#campaignUnsubscribes(uid, campaign_id, start, limit) ⇒ Object



269
270
271
272
273
# File 'lib/mail_chimp.rb', line 269

def campaignUnsubscribes(uid, campaign_id, start, limit)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignUnsubscribes", uid, campaign_id, start, limit)      
end

#campaignUpdate(uid, campaign_id, name, value) ⇒ Object



352
353
354
355
356
# File 'lib/mail_chimp.rb', line 352

def campaignUpdate(uid, campaign_id, name, value) 
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("campaignUpdate", uid, campaign_id, name, value)      
end

#check_inbox(delete = nil, mode = nil, delete_skipped = nil) ⇒ Object

Reads IMAP mail from the mailbox initialized with initialize_inbox. Returns a subscribers array containing hashes of user data, and an unsubscriber’s array containing hashes of user data, as well as two integers indicating how many messages were found in the inbox and how many were processed successfully. Email, IP, and a string representation of the date.



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
# File 'lib/mail_chimp.rb', line 441

def check_inbox(delete=nil, mode=nil, delete_skipped=nil)
  delete = true if (delete.nil?)
  delete_skipped = false if delete_skipped.nil?
  if (!mode.nil? && mode.upcase != "IMAP")
    STDERR.write("Mode #{mode} not supported.  Only IMAP supported at this time.")
  elsif (email_server.nil? || email_user.nil? || email_password.nil?)
    STDERR.write("You must initialize the mailbox before checking it.  Try initialize_inbox.")
  else
    subscribes = Array::new
    unsubscribes = Array::new
    imap = Net::IMAP.new(email_server)
    imap.(email_user, email_password)
    imap.select('INBOX')
    messages_found = 0
    messages_processed = 0
    imap.search(['ALL']).each do |message_id|
      msg = imap.fetch(message_id,'RFC822')[0].attr['RFC822']
      messages_found += 1
      stored_value = Processor.receive(msg)
      if (!stored_value.nil? && stored_value[:type] == :subscription)
        subscribes << stored_value 
        imap.store(message_id, "+FLAGS", [:Deleted]) if (delete == true)
        messages_processed += 1
      elsif (!stored_value.nil? && stored_value[:type] == :unsubscription)
        unsubscribes << stored_value 
        imap.store(message_id, "+FLAGS", [:Deleted]) if (delete == true)
        messages_processed += 1
      else
        STDERR.write("Skipping message with raw data: #{msg}")
        imap.store(message_id, "+FLAGS", [:Deleted]) if (delete_skipped == true)          
      end
    end      
    imap.expunge if (delete == true)
    imap.disconnect
    return [subscribes, unsubscribes, messages_found, messages_processed]
  end
  return nil
end

#emails_to_hash_array(list_id, email_array) ⇒ Object

Convenience method - converts a list of e-mails into an array suitable for a single subscribe_users or unsubscribe_users call.



380
381
382
383
384
385
386
387
388
389
# File 'lib/mail_chimp.rb', line 380

def emails_to_hash_array(list_id, email_array)
  output_array = Array::new
  email_array.each do |email|
    output_hash = Hash::new
    output_hash['EMAIL'] = email
    output_hash['id'] = list_id
    output_array << output_hash      
  end
  return output_array
end

#generateText(uid, mime_type, content) ⇒ Object

HELPER METHODS



178
179
180
181
182
# File 'lib/mail_chimp.rb', line 178

def generateText(uid, mime_type, content)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("generateText", uid, mime_type, content)  
end

#getAffiliateInfo(uid) ⇒ Object



184
185
186
187
188
# File 'lib/mail_chimp.rb', line 184

def getAffiliateInfo(uid)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("generateText", uid, mime_type, content)  
end

#getListByName(uid, listname) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/mail_chimp.rb', line 70

def getListByName(uid, listname)
  listinfo = lists(uid)
  listhash = {}
  listinfo.each {|list|
    listhash_key = list["name"]
    listhash[listhash_key] = list
  }
  return listhash[listname]
end

#getListIdByName(uid, listname) ⇒ Object



80
81
82
83
# File 'lib/mail_chimp.rb', line 80

def getListIdByName(uid, listname)
  list = getListByName(uid, listname)
  return list["id"]
end

#initialize_inbox(server, user, password) ⇒ Object

Stores the inbox attributes to allow connection by check_inbox



369
370
371
372
373
374
# File 'lib/mail_chimp.rb', line 369

def initialize_inbox(server, user, password)
  self.email_server = server
  self.email_user = user
  self.email_password = password
  return true
end

#inlineCss(uid, html, strip_css = false) ⇒ Object



190
191
192
193
194
# File 'lib/mail_chimp.rb', line 190

def inlineCss(uid, html, strip_css=false)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("inlineCss", uid, html, strip_css)  
end

#listBatchSubscribe(uid, list_id, email_array, double_optin = true, update_existing = true, replace_interests = true) ⇒ Object



85
86
87
88
89
# File 'lib/mail_chimp.rb', line 85

def listBatchSubscribe(uid, list_id, email_array, double_optin=true, update_existing=true, replace_interests=true) 
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("listBatchSubscribe", uid, list_id, email_array, double_optin, update_existing, replace_interests)
end

#listBatchUnsubscribe(uid, list_id, email_array, delete_member = false, send_goodbye = true, send_notify = true) ⇒ Object



91
92
93
94
95
# File 'lib/mail_chimp.rb', line 91

def listBatchUnsubscribe(uid, list_id, email_array, delete_member=false, send_goodbye=true, send_notify=true) 
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("listBatchSubscribe", uid, list_id, email_array, delete_member, send_goodbye, send_notify)
end

#listInterestGroupAdd(uid, list_id, group_name) ⇒ Object



97
98
99
100
101
# File 'lib/mail_chimp.rb', line 97

def listInterestGroupAdd(uid, list_id, group_name)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("listInterestGroupAdd", uid, list_id, group_name)
end

#listInterestGroupDel(uid, list_id, group_name) ⇒ Object



103
104
105
106
107
# File 'lib/mail_chimp.rb', line 103

def listInterestGroupDel(uid, list_id, group_name)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("listInterestGroupDel", uid, list_id, group_name)
end

#listInterestGroups(uid, list_id) ⇒ Object



109
110
111
112
113
# File 'lib/mail_chimp.rb', line 109

def listInterestGroups(uid, list_id)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("listInterests", uid, list_id)
end

#listMemberInfo(uid, list_id, email) ⇒ Object



115
116
117
118
119
# File 'lib/mail_chimp.rb', line 115

def listMemberInfo(uid, list_id, email)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("listMemberInfo", uid, list_id, email)        
end

#listMembers(uid, list_id, status, start = 0, limit = 100) ⇒ Object



121
122
123
124
125
# File 'lib/mail_chimp.rb', line 121

def listMembers(uid, list_id, status, start=0, limit=100)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("listMembers", uid, list_id, status, start, limit)    
end

#listMergeVarAdd(uid, list_id, merge_tag, description, required = false) ⇒ Object



127
128
129
130
131
# File 'lib/mail_chimp.rb', line 127

def listMergeVarAdd(uid, list_id, merge_tag, description, required=false)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("listMergeVarAdd", uid, list_id, merge_tag, description, required)      
end

#listMergeVarDel(uid, list_id, merge_tag) ⇒ Object



133
134
135
136
137
# File 'lib/mail_chimp.rb', line 133

def listMergeVarDel(uid, list_id, merge_tag)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("listMergeVarDel", uid, list_id, merge_tag)      
end

#listMergeVars(uid, list_id) ⇒ Object



139
140
141
142
143
# File 'lib/mail_chimp.rb', line 139

def listMergeVars(uid, list_id)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("listMergeVars", uid, list_id)    
end

#lists(uid) ⇒ Object



169
170
171
172
173
# File 'lib/mail_chimp.rb', line 169

def lists(uid)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("lists", uid)    
end

#listSubscribe(uid, list_id, email, merge_vars, email_type = "html", double_optin = true) ⇒ Object



151
152
153
154
155
# File 'lib/mail_chimp.rb', line 151

def listSubscribe(uid, list_id, email, merge_vars, email_type="html", double_optin=true)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("listSubscribe", uid, list_id, email, merge_vars, email_type, double_optin)    
end

#listUnsubscribe(uid, list_id, email, delete_member = false, send_goodbye = true, send_notify = true) ⇒ Object



157
158
159
160
161
# File 'lib/mail_chimp.rb', line 157

def listUnsubscribe(uid, list_id, email, delete_member=false, send_goodbye=true, send_notify=true)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("listUnsubscribe", uid, list_id, email, delete_member, send_goodbye, send_notify)    
end

#listUpdateMember(uid, list_id, email, merge_vars, email_type, replace_interests = true) ⇒ Object



163
164
165
166
167
# File 'lib/mail_chimp.rb', line 163

def listUpdateMember(uid, list_id, email, merge_vars, email_type, replace_interests=true)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("listUpdateMember", uid, list_id, email, merge_vars, email_type, replace_interests)    
end

#login(username, password) ⇒ Object



49
50
51
52
# File 'lib/mail_chimp.rb', line 49

def (username, password)
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("login", username, password)
end

#ping(uid) ⇒ Object



196
197
198
199
200
# File 'lib/mail_chimp.rb', line 196

def ping(uid)
  raise StandardError("Not Loggged in or invalid UID.") if (uid.nil?) 
  @client = XMLRPC::Client.new2(API_URL) if @client.nil?
  @client.call("ping", uid)
end

#subscribe_user(list_id, email, additional_fields = nil) ⇒ Object

Adds a user to the specified MailChimp list. list_id - The MailChimp List ID email - The user’s e-mail address additional_fields - An optional hash containing other fields to pass in.

The key for each field should be the name of the field as it would be specified in a form.



398
399
400
401
402
403
# File 'lib/mail_chimp.rb', line 398

def subscribe_user(list_id, email, additional_fields=nil)    
  additional_fields = Hash::new if (additional_fields.nil?)
  additional_fields['EMAIL'] = email   
  additional_fields['id'] = list_id
  return subscribe_users([additional_fields])
end

#subscribe_users(hash_array) ⇒ Object

Executes a batch subscribe of multiple users. hash_array - An array of hashes, each representing a user.



409
410
411
# File 'lib/mail_chimp.rb', line 409

def subscribe_users(hash_array)
  post_to_mailchimp(hash_array, "/subscribe.phtml")
end

#unsubscribe_user(list_id, email) ⇒ Object

Removes a user from the specified MailChimp list. list_id - The MailChimp List ID email - The user’s e-mail address



418
419
420
421
422
423
# File 'lib/mail_chimp.rb', line 418

def unsubscribe_user(list_id, email)
  additional_fields = Hash::new if (additional_fields.nil?)
  additional_fields['EMAIL'] = email   
  additional_fields['id'] = list_id
  return unsubscribe_users([additional_fields])    
end

#unsubscribe_users(hash_array) ⇒ Object

Executes a batch unsubscribe of multiple users. hash_array - An array of hash lines



429
430
431
# File 'lib/mail_chimp.rb', line 429

def unsubscribe_users(hash_array)
  post_to_mailchimp(hash_array, "/unsub.phtml")
end