Skip to content

Instantly share code, notes, and snippets.

@mataki
Last active December 19, 2015 09:19
Show Gist options
  • Save mataki/5932241 to your computer and use it in GitHub Desktop.
Save mataki/5932241 to your computer and use it in GitHub Desktop.
mailchimp sync sample
class User < ActiveRecord::Base
def subscribe_mailchimp_list(client = Gibbon.new)
if ENV["MAILCHIMP_LIST_ID"]
logger.info "add #{self.email} to list #{ENV["MAILCHIMP_LIST_ID"]}"
client.list_subscribe(id: ENV["MAILCHIMP_LIST_ID"],
email_address: self.email,
double_optin: false,
send_welcome: false,
update_existing: true,
merge_vers: {:FNAME => self.first_name,
:LNAME => self.last_name})
end
end
def after_save_subscribe_mailchimp_list
if finish_sign_up?
begin
subscribe_mailchimp_list
rescue => e
logger.info "[MAILCHIMP][ERROR] faield to add #{self.id}: #{e}"
Bugsnag.notify(e, { user_id: self.id })
end
end
end
after_save :after_save_subscribe_mailchimp_list
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment