interface to import mails automatically

This commit is contained in:
2016-04-25 12:07:53 +02:00
parent fb01b5ca4f
commit 087b5b127d
3 changed files with 33 additions and 3 deletions
+3 -1
View File
@@ -44,6 +44,8 @@ gem 'rails_admin'
gem 'mongoid_paranoia' gem 'mongoid_paranoia'
gem 'mailchimp-api', require: 'mailchimp'
group :development, :test do group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console # Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug' gem 'byebug'
@@ -58,5 +60,5 @@ group :development do
gem 'web-console', '~> 2.0' gem 'web-console', '~> 2.0'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring' # gem 'spring'
end end
+5 -2
View File
@@ -67,6 +67,7 @@ GEM
debug_inspector (0.0.2) debug_inspector (0.0.2)
diff-lcs (1.2.5) diff-lcs (1.2.5)
erubis (2.7.0) erubis (2.7.0)
excon (0.49.0)
execjs (2.6.0) execjs (2.6.0)
font-awesome-rails (4.6.1.0) font-awesome-rails (4.6.1.0)
railties (>= 3.2, < 5.1) railties (>= 3.2, < 5.1)
@@ -93,6 +94,9 @@ GEM
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
mail (2.6.4) mail (2.6.4)
mime-types (>= 1.16, < 4) mime-types (>= 1.16, < 4)
mailchimp-api (2.0.6)
excon (>= 0.16.0)
json (>= 1.7.7)
method_source (0.8.2) method_source (0.8.2)
mime-types (3.0) mime-types (3.0)
mime-types-data (~> 3.2015) mime-types-data (~> 3.2015)
@@ -229,7 +233,6 @@ GEM
railties (>= 3.1, < 5.0) railties (>= 3.1, < 5.0)
slim (~> 3.0) slim (~> 3.0)
slop (3.6.0) slop (3.6.0)
spring (1.6.4)
sprockets (3.5.2) sprockets (3.5.2)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
rack (> 1, < 3) rack (> 1, < 3)
@@ -266,6 +269,7 @@ DEPENDENCIES
geocoder geocoder
jbuilder (~> 2.0) jbuilder (~> 2.0)
jquery-rails jquery-rails
mailchimp-api
mongoid (~> 5.0.0) mongoid (~> 5.0.0)
mongoid-rspec (= 3.0.0) mongoid-rspec (= 3.0.0)
mongoid_paranoia mongoid_paranoia
@@ -281,7 +285,6 @@ DEPENDENCIES
simple_form simple_form
slim slim
slim-rails slim-rails
spring
turbolinks turbolinks
uglifier (>= 1.3.0) uglifier (>= 1.3.0)
web-console (~> 2.0) web-console (~> 2.0)
+25
View File
@@ -0,0 +1,25 @@
class MailChimpBatchUpdate
def self.update_all(api_key, list_id)
subscribers = []
Supporter.each do |supporter|
subscriber = {
'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
}
}
subscribers.push(subscriber)
end
mailchimp = Mailchimp::API.new(api_key)
mailchimp.lists.batch_subscribe(list_id, subscribers, false, true, false)
end
end