app/models/kits/mailchimp_kit.rb in artfully_ose-1.2.0.pre.9 vs app/models/kits/mailchimp_kit.rb in artfully_ose-1.2.0.pre.10

- old
+ new

@@ -251,10 +251,20 @@ person.skip_sync_to_mailchimp = true person.save person end + def sync_mailchimp_webhook_cleaned(list_id, data) + person = organization.people.find_by_email(data["email"]) + return if person.nil? + + reason = (data["reason"] == "hard" ? "a hard bounce" : "abuse") + person.subscribed_lists.delete(list_id) + person.new_note("MailChimp cleaned #{person.email} from #{list_name(list_id)} because of #{reason}.", Time.now, nil, organization_id) + puts person.save + end + def sync_mailchimp_webhook_update_person_email(list_id, data) person = organization.people.find_by_email(data["old_email"]) return if person.nil? || person.do_not_email? person.update_attributes(:email => data["new_email"], :skip_sync_to_mailchimp => true) @@ -275,15 +285,10 @@ end def sync_mailchimp_webhook_member_unsubscribe(list_id, data) person = organization.people.find_by_email(data["email"]) return unless person - note = person.notes.build({ - :text => "Unsubscribed in MailChimp from #{list_name(list_id)}", - :occurred_at => Time.now - }) - note.organization_id = organization_id - note.save + person.new_note("Unsubscribed in MailChimp from #{list_name(list_id)}", Time.now, nil, organization_id) person.subscribed_lists.delete(list_id) person.save end def sync_mailchimp_webhook_campaign_sent(list_id, data)