Commit 7a9230f5

mo khan <mo@mokhan.ca>
2014-05-16 23:16:05
register new users in mailchimp mail list.
1 parent 984ca47
Changed files (2)
app/models/subscription.rb
@@ -0,0 +1,15 @@
+class Subscription
+  def self.subscribe(email:, first_name:, last_name:, list_id: ENV['MAILCHIMP_LIST_ID'])
+    return if Rails.env.test?
+
+    Gibbon::API.lists.subscribe({
+      id: list_id,
+      email: { email: email },
+      merge_vars: {
+        FNAME: first_name,
+        LNAME: last_name
+      },
+      double_optin: false
+    })
+  end
+end
app/models/user.rb
@@ -55,6 +55,7 @@ class User < ActiveRecord::Base
 
   def send_welcome_email
     UserMailer.delay.welcome_email(self)
+    Subscription.delay.subscribe(email: email, first_name: name, last_name: '')
   end
 
   def recent_activities(limit = 20)