Sha256: 0eb1960286651b754eab81dd72e9c9fd021046c311a7d27bcd26c48ae18cbbf3
Contents?: true
Size: 1.11 KB
Versions: 3
Compression:
Stored size: 1.11 KB
Contents
class Spree::SubscriptionsController < Spree::BaseController def hominid @hominid ||= Hominid::Base.new({ :api_key => Spree::Config.get(:mailchimp_api_key) }) end def create @errors = [] if params[:email].blank? @errors << t('missing_email') elsif params[:email] !~ /[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/i @errors << t('invalid_email_address') else begin self.class.benchmark "Checking if address exists and/or is valid" do @mc_member = hominid.member_info(Spree::Config.get(:mailchimp_list_id), params[:email]) end rescue Hominid::ListError => e end if @mc_member @errors << t('that_address_is_already_subscribed') else begin self.class.benchmark "Adding mailchimp subscriber" do hominid.subscribe(Spree::Config.get(:mailchimp_list_id), params[:email], {}, MailChimpSync::Sync::mc_subscription_opts) end rescue Hominid::ValidationError => e @errors << t('invalid_email_address') end end end respond_to do |wants| wants.js end end end
Version data entries
3 entries across 3 versions & 1 rubygems