diff --git a/Gemfile b/Gemfile index faea704..4d8bf4d 100644 --- a/Gemfile +++ b/Gemfile @@ -63,8 +63,6 @@ gem 'rails_admin' gem 'mongoid_paranoia' -gem 'mailchimp-api', require: 'mailchimp' - group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug' diff --git a/Gemfile.lock b/Gemfile.lock index ab79e5f..2184a78 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -92,7 +92,6 @@ GEM dotenv (= 2.2.0) railties (>= 3.2, < 5.1) erubis (2.7.0) - excon (0.55.0) execjs (2.7.0) faker (1.7.2) i18n (~> 0.5) @@ -131,9 +130,6 @@ GEM nokogiri (>= 1.5.9) mail (2.6.4) mime-types (>= 1.16, < 4) - mailchimp-api (2.0.6) - excon (>= 0.16.0) - json (>= 1.7.7) memory_profiler (0.9.8) method_source (0.8.2) mime-types (3.1) @@ -323,7 +319,6 @@ DEPENDENCIES jquery-rails kaminari-actionview kaminari-mongoid - mailchimp-api mongoid (~> 5.0.0) mongoid-rspec (= 3.0.0) mongoid_paranoia diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 97edce3..eee49ff 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -32,6 +32,6 @@ class ApplicationController < ActionController::Base protected def configure_permitted_parameters - devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, :street, :city, :zip, :support, :language, :age_category, :unsubscribed]) + devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, :street, :city, :zip, :support, :language, :age_category]) end end diff --git a/app/controllers/supporters_controller.rb b/app/controllers/supporters_controller.rb index d88da26..3ebdbee 100644 --- a/app/controllers/supporters_controller.rb +++ b/app/controllers/supporters_controller.rb @@ -10,7 +10,7 @@ class SupportersController < ApplicationController @supporter.password = random_password = SecureRandom.hex(5) if !input_to_fast? && @supporter.save SupporterMailer.welcome_email(@supporter, random_password).deliver_now - mailchimp_registration + sendy_registraion redirect_to thanks_path else flash.now[:danger] = input_to_fast? ? t('.timeout') : t('input_error') @@ -24,20 +24,11 @@ class SupportersController < ApplicationController params.require(:supporter).permit(:first_name, :last_name, :street, :zip, :email, :support, :li_membership, :age_category, :city, :comments) end - def mailchimp_registration - return unless Rails.env.production? - mailchimp = Mailchimp::API.new(ENV['MAILCHIMP_API']) - mailchimp.lists.subscribe(ENV['CH420_LIST_ID'], { 'email' => @supporter.email }, merge_vars, 'html', false) - end - - def merge_vars - { 'EMAIL' => @supporter.email, - 'FNAME' => @supporter.first_name, - 'LNAME' => @supporter.last_name, - 'SUPPORT' => @supporter.support, - 'MEMBERSHIP' => @supporter.li_membership.to_s, - 'AGE' => @supporter.age_category, - 'LANG' => @supporter.language, - 'ZIP' => @supporter.zip } + # We use sendy for newsletters atm + def sendy_registraion + uri = URI('http://newsletter.cannabis-initiative.ch/subscribe') + Net::HTTP.post_form(uri, list: ENV["SENDY_LIST_#{I18n.locale.upcase}"], + email: @supporter.email, + name: "#{@supporter.first_name} #{@supporter.last_name}") end end diff --git a/app/models/supporter.rb b/app/models/supporter.rb index 80070e6..f0e3a13 100644 --- a/app/models/supporter.rb +++ b/app/models/supporter.rb @@ -53,7 +53,6 @@ class Supporter field :coordinates, type: Array field :comments, type: String field :language, type: String - field :unsubscribed, type: Boolean, default: false field :duplicate, type: Boolean, default: false validates :first_name, presence: true diff --git a/app/views/supporters/new.slim b/app/views/supporters/new.slim index 7a937e3..29f4e68 100644 --- a/app/views/supporters/new.slim +++ b/app/views/supporters/new.slim @@ -23,8 +23,6 @@ dd == t("age_category.#{current_supporter.age_category}") dt = Supporter.human_attribute_name(:language) dd = t("languages.#{current_supporter.language}") - dt = Supporter.human_attribute_name(:unsubscribed) - dd = current_supporter.unsubscribed? ? t('shared.yes') : t('shared.no') p = link_to t('.edit'), edit_supporter_registration_path(), class: 'pull-right' diff --git a/app/views/supporters/registrations/edit.html.slim b/app/views/supporters/registrations/edit.html.slim index e6a1d47..d85ef28 100644 --- a/app/views/supporters/registrations/edit.html.slim +++ b/app/views/supporters/registrations/edit.html.slim @@ -19,7 +19,6 @@ = f.input :support, as: :radio_buttons, collection: t('support_type').map{ |x| [x.first, raw(x.last)]}, label_method: :last, value_method: :first = f.input :age_category, as: :radio_buttons, collection: t('age_category'), label_method: :last, value_method: :first = f.input :language, as: :radio_buttons, collection: t('languages').map{ |x| [x.first, raw(x.last)]}, label_method: :last, value_method: :first - = f.input :unsubscribed, as: :boolean .form-actions = f.button :submit, t("devise.registrations.edit.update"), class: 'btn btn-primary' p = link_to t("devise.shared.links.back"), :back diff --git a/config/locales/de.yml b/config/locales/de.yml index c3f5820..acaeddb 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -81,6 +81,5 @@ de: remember_me: Angemeldet bleiben password: Passwort language: Sprache - unsubscribed: Kein Newsletter password_confirmation: Passwort bestätigen current_password: Aktuelles Passwort diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 3ba4af8..f9e6c25 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -79,6 +79,5 @@ fr: remember_me: Se souvenir de moi password: mot de passe language: Langue - unsubscribed: pas de newslettre password_confirmation: confirmer le mot de passe current_password: Mot de passe actuel diff --git a/config/locales/it.yml b/config/locales/it.yml index a653ed4..52e98a3 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -79,6 +79,5 @@ it: remember_me: Ricordati di mel password: Password language: Lingua - unsubscribed: No Newsletter password_confirmation: conferma password current_password: Password corrente diff --git a/lib/mail_chimp_batch_update.rb b/lib/mail_chimp_batch_update.rb deleted file mode 100644 index ddbf367..0000000 --- a/lib/mail_chimp_batch_update.rb +++ /dev/null @@ -1,47 +0,0 @@ -class MailChimpBatchUpdate - def initialize(api_key, list_id) - @mailchimp = Mailchimp::API.new(api_key) - @list_id = list_id - end - - def update_all - subscribers = [] - - Supporter.each_with_index do |supporter, index| - subscribers.push(subscriber(supporter)) - if index.modulo(20).zero? - batch_subscribe(subscribers) - subscribers = [] - end - end - - batch_subscribe(subscribers) - end - - def batch_subscribe(subscribers) - @mailchimp.lists.batch_subscribe(@list_id, subscribers, false, true, false) - end - - def subscriber(supporter) - { 'EMAIL' => { 'email' => supporter.email }, 'language' => supporter.language, :EMAIL_TYPE => 'html', - :merge_vars => { - 'EMAIL' => supporter.email, - 'FNAME' => supporter.first_name, - 'LNAME' => supporter.last_name, - 'SUPPORT' => supporter.support, - 'MEMBERSHIP' => supporter.li_membership.to_s, - 'AGE' => supporter.age_category, - 'LANG' => supporter.language, - 'ZIP' => supporter.zip - } } - end - - def update_unsubscibed - unsubscribed_members = @mailchimp.lists.members(@list_id, 'unsubscribed', limit: 100) - unsubscribed_members['data'].each do |member| - Supporter.where(email: member['email']).each do |supporter| - supporter.update_attributes unsubscribed: true - end - end - end -end diff --git a/spec/features/support_spec.rb b/spec/features/support_spec.rb index c1bee31..4f10e19 100644 --- a/spec/features/support_spec.rb +++ b/spec/features/support_spec.rb @@ -21,7 +21,7 @@ feature 'Support announcement' do sleep 5 # Do a real sleep to have a real integration test expect(ActionMailer::Base.deliveries.count).to eq 0 - expect_any_instance_of(SupportersController).to receive(:mailchimp_registration).and_return(true) + expect_any_instance_of(SupportersController).to receive(:sendy_registraion).and_return(true) expect { click_button 'Unterstützung zusichern' }.to change { Supporter.count }.by(1) # expect(ActionMailer::Base.deliveries.count).to eq 1