effective_mailchimp 0.6.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/admin/mailchimp_categories_controller.rb +15 -0
- data/app/controllers/admin/mailchimp_controller.rb +23 -0
- data/app/controllers/admin/mailchimp_interests_controller.rb +15 -0
- data/app/controllers/admin/mailchimp_list_members_controller.rb +15 -0
- data/app/controllers/admin/mailchimp_lists_controller.rb +0 -10
- data/app/datatables/admin/effective_mailchimp_categories_datatable.rb +32 -0
- data/app/datatables/admin/effective_mailchimp_interests_datatable.rb +47 -0
- data/app/datatables/admin/effective_mailchimp_list_members_datatable.rb +39 -0
- data/app/datatables/admin/effective_mailchimp_lists_datatable.rb +9 -3
- data/app/helpers/effective_mailchimp_helper.rb +10 -0
- data/app/jobs/effective_mailchimp_subscribe_all_members_job.rb +8 -0
- data/app/jobs/effective_mailchimp_subscribe_all_users_job.rb +8 -0
- data/app/models/concerns/effective_mailchimp_user.rb +15 -10
- data/app/models/effective/mailchimp_api.rb +70 -18
- data/app/models/effective/mailchimp_category.rb +74 -0
- data/app/models/effective/mailchimp_interest.rb +93 -0
- data/app/models/effective/mailchimp_list.rb +62 -32
- data/app/models/effective/mailchimp_list_member.rb +42 -1
- data/app/views/admin/mailchimp/_sync.html.haml +15 -0
- data/app/views/admin/mailchimp/index.html.haml +79 -0
- data/app/views/admin/mailchimp_interests/_form.html.haml +10 -0
- data/app/views/admin/mailchimp_lists/_form.html.haml +1 -0
- data/app/views/admin/mailchimp_user/_form.html.haml +10 -4
- data/app/views/effective/mailchimp_user/_fields.html.haml +36 -9
- data/config/effective_mailchimp.rb +6 -0
- data/config/locales/effective_mailchimp.en.yml +12 -0
- data/config/routes.rb +9 -7
- data/db/migrate/101_create_effective_mailchimp.rb +39 -0
- data/lib/effective_mailchimp/version.rb +1 -1
- data/lib/effective_mailchimp.rb +28 -3
- data/lib/tasks/effective_mailchimp_tasks.rake +0 -16
- metadata +16 -3
- data/app/views/admin/mailchimp_lists/index.html.haml +0 -20
@@ -3,6 +3,8 @@ module Effective
|
|
3
3
|
self.table_name = (EffectiveMailchimp.mailchimp_lists_table_name || :mailchimp_lists).to_s
|
4
4
|
|
5
5
|
has_many :mailchimp_list_members, dependent: :delete_all
|
6
|
+
has_many :mailchimp_categories, dependent: :delete_all
|
7
|
+
has_many :mailchimp_interests, dependent: :delete_all
|
6
8
|
|
7
9
|
effective_resource do
|
8
10
|
mailchimp_id :string
|
@@ -16,18 +18,16 @@ module Effective
|
|
16
18
|
timestamps
|
17
19
|
end
|
18
20
|
|
19
|
-
|
20
|
-
name.presence || model_name.human
|
21
|
-
end
|
22
|
-
|
23
|
-
scope :deep, -> { all }
|
21
|
+
scope :deep, -> { includes(:mailchimp_categories, :mailchimp_interests) }
|
24
22
|
scope :sorted, -> { order(:name) }
|
25
23
|
scope :subscribable, -> { where(can_subscribe: true) }
|
26
24
|
|
27
|
-
#
|
28
|
-
|
25
|
+
# Reads all the Lists from Mailchimp and creates local MailchimpList records
|
26
|
+
# Also writes our merge fields to Mailchimp if they don't exist
|
27
|
+
# This is part of the Sync changes from Mailchimp button
|
28
|
+
def self.sync!(api: EffectiveMailchimp.api)
|
29
29
|
# All the Lists from Mailchimp
|
30
|
-
lists =
|
30
|
+
lists = api.lists()
|
31
31
|
|
32
32
|
# Get all our existing Effective::MailchimpList records
|
33
33
|
mailchimp_lists = all()
|
@@ -35,11 +35,18 @@ module Effective
|
|
35
35
|
# Find or create Effective::Mailchimp based on existing lists
|
36
36
|
lists.each do |list|
|
37
37
|
mailchimp_id = list['id']
|
38
|
-
web_id = list['web_id']
|
39
|
-
name = list['name']
|
40
38
|
|
41
39
|
mailchimp_list = mailchimp_lists.find { |ml| ml.mailchimp_id == mailchimp_id } || new()
|
42
|
-
mailchimp_list.assign_attributes(
|
40
|
+
mailchimp_list.assign_attributes(
|
41
|
+
mailchimp_id: mailchimp_id,
|
42
|
+
|
43
|
+
web_id: list['web_id'],
|
44
|
+
name: list['name'],
|
45
|
+
member_count: (list.dig('stats', 'member_count') || 0),
|
46
|
+
updated_at: Time.zone.now
|
47
|
+
)
|
48
|
+
|
49
|
+
mailchimp_list.assign_attributes(can_subscribe: true) if mailchimp_list.new_record?
|
43
50
|
mailchimp_list.save!
|
44
51
|
end
|
45
52
|
|
@@ -49,18 +56,37 @@ module Effective
|
|
49
56
|
mailchimp_list.destroy! unless list.present?
|
50
57
|
end
|
51
58
|
|
59
|
+
# Sync merge fields
|
60
|
+
if (merge_fields = EffectiveMailchimp.merge_fields).present?
|
61
|
+
merge_field_keys = merge_fields.keys.map(&:to_s)
|
62
|
+
|
63
|
+
mailchimp_lists.reject(&:destroyed?).each do |mailchimp_list|
|
64
|
+
existing = api.list_merge_fields(mailchimp_list).map { |hash| hash['tag'] }
|
65
|
+
(merge_field_keys - existing).each { |name| api.add_merge_field(mailchimp_list, name: name) }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
52
69
|
true
|
53
70
|
end
|
54
71
|
|
55
|
-
|
56
|
-
|
57
|
-
|
72
|
+
def subscribe_all_users!(now: false)
|
73
|
+
if now
|
74
|
+
subscribe_all!(EffectiveMailchimp.User.all)
|
75
|
+
else
|
76
|
+
EffectiveMailchimpSubscribeAllUsersJob.perform_later(self)
|
77
|
+
end
|
78
|
+
end
|
58
79
|
|
59
|
-
|
60
|
-
|
80
|
+
def subscribe_all_members!(now: false)
|
81
|
+
if now
|
82
|
+
subscribe_all!(EffectiveMailchimp.User.all.members)
|
83
|
+
else
|
84
|
+
EffectiveMailchimpSubscribeAllMembersJob.perform_later(self)
|
61
85
|
end
|
86
|
+
end
|
62
87
|
|
63
|
-
|
88
|
+
def to_s
|
89
|
+
name.presence || model_name.human
|
64
90
|
end
|
65
91
|
|
66
92
|
def merge_fields
|
@@ -68,8 +94,12 @@ module Effective
|
|
68
94
|
EffectiveMailchimp.api.list_merge_fields(mailchimp_id).map { |hash| hash['tag'] }.sort
|
69
95
|
end
|
70
96
|
|
71
|
-
def
|
72
|
-
|
97
|
+
def grouped?
|
98
|
+
mailchimp_categories.present? && mailchimp_categories.any? { |category| category.mailchimp_interests.present? }
|
99
|
+
end
|
100
|
+
|
101
|
+
def ungrouped?
|
102
|
+
!grouped?
|
73
103
|
end
|
74
104
|
|
75
105
|
def members_url
|
@@ -80,20 +110,20 @@ module Effective
|
|
80
110
|
EffectiveMailchimp.api.admin_url + "/lists/settings/merge-tags?id=#{web_id}"
|
81
111
|
end
|
82
112
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
113
|
+
private
|
114
|
+
|
115
|
+
def subscribe_all!(users)
|
116
|
+
users.find_each do |user|
|
117
|
+
begin
|
118
|
+
user.mailchimp_subscribe!(self, subscribed: true, now: true)
|
119
|
+
rescue => e
|
120
|
+
EffectiveLogger.error(e.message, associated: user) if defined?(EffectiveLogger)
|
121
|
+
ExceptionNotifier.notify_exception(e, data: { user_id: user.id, mailchimp_list_id: id }) if defined?(ExceptionNotifier)
|
122
|
+
raise(e) if Rails.env.test? || Rails.env.development?
|
123
|
+
end
|
124
|
+
end
|
94
125
|
|
95
|
-
|
96
|
-
update!(force_subscribe: false)
|
126
|
+
true
|
97
127
|
end
|
98
128
|
|
99
129
|
end
|
@@ -14,6 +14,8 @@ module Effective
|
|
14
14
|
email_address :string
|
15
15
|
full_name :string
|
16
16
|
|
17
|
+
interests :text # Array of mailchimp_interest mailchimp_ids
|
18
|
+
|
17
19
|
# We set this on our side to update mailchimp and subscribe the user
|
18
20
|
subscribed :boolean
|
19
21
|
|
@@ -26,10 +28,17 @@ module Effective
|
|
26
28
|
timestamps
|
27
29
|
end
|
28
30
|
|
31
|
+
if EffectiveResources.serialize_with_coder?
|
32
|
+
serialize :interests, type: Array, coder: YAML
|
33
|
+
else
|
34
|
+
serialize :interests, Array
|
35
|
+
end
|
36
|
+
|
29
37
|
validates :mailchimp_list_id, uniqueness: { scope: [:user_type, :user_id] }
|
30
38
|
|
31
39
|
scope :deep, -> { includes(:mailchimp_list, :user) }
|
32
40
|
scope :sorted, -> { order(:id) }
|
41
|
+
scope :subscribed, -> { where(subscribed: true) }
|
33
42
|
|
34
43
|
def to_s
|
35
44
|
mailchimp_list&.to_s || model_name.human
|
@@ -39,6 +48,37 @@ module Effective
|
|
39
48
|
email_address.presence || user.email
|
40
49
|
end
|
41
50
|
|
51
|
+
# Array of MailchimpInterest mailchimp_ids
|
52
|
+
def interests
|
53
|
+
Array(self[:interests]) - [nil, '']
|
54
|
+
end
|
55
|
+
|
56
|
+
# Array of MailchimpInterests
|
57
|
+
def mailchimp_interests
|
58
|
+
all_mailchimp_interests.select { |interest| interests.include?(interest.mailchimp_id) }
|
59
|
+
end
|
60
|
+
|
61
|
+
# We use this to add the force_subscribed interests
|
62
|
+
def build_interests(mailchimp_interest)
|
63
|
+
mailchimp_ids = Array(mailchimp_interest).map { |interest| interest.try(:mailchimp_id) || interest }
|
64
|
+
raise('expected an array of MailchimpInterests or mailchimp_ids') unless mailchimp_ids.all? { |id| id.kind_of?(String) && id.length > 1 }
|
65
|
+
|
66
|
+
assign_attributes(interests: interests | mailchimp_ids)
|
67
|
+
end
|
68
|
+
|
69
|
+
# {"25a38426c9" => false, "9b826db370" => true }
|
70
|
+
def interests_hash
|
71
|
+
all_mailchimp_interests.each_with_object({}) do |interest, hash|
|
72
|
+
hash[interest.mailchimp_id] = interests.include?(interest.mailchimp_id)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# From the mailchimp list
|
77
|
+
def all_mailchimp_interests
|
78
|
+
return [] if mailchimp_list.blank?
|
79
|
+
mailchimp_list.mailchimp_categories.flat_map(&:mailchimp_interests)
|
80
|
+
end
|
81
|
+
|
42
82
|
def assign_mailchimp_attributes(atts)
|
43
83
|
assign_attributes(
|
44
84
|
mailchimp_id: atts['id'],
|
@@ -46,7 +86,8 @@ module Effective
|
|
46
86
|
email_address: atts['email_address'],
|
47
87
|
full_name: atts['full_name'],
|
48
88
|
subscribed: (atts['status'] == 'subscribed'),
|
49
|
-
last_synced_at: Time.zone.now
|
89
|
+
last_synced_at: Time.zone.now,
|
90
|
+
interests: Hash(atts['interests']).select { |_, subscribed| subscribed == true }.keys
|
50
91
|
)
|
51
92
|
end
|
52
93
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
- if EffectiveResources.authorized?(self, :admin, :mailchimp_sync)
|
2
|
+
%p= link_to 'Sync changes from Mailchimp', effective_mailchimp.mailchimp_sync_admin_mailchimp_index_path, 'data-method': :post, class: 'btn btn-primary'
|
3
|
+
|
4
|
+
%p.text-muted
|
5
|
+
%small
|
6
|
+
- mailchimp_last_synced_at = Effective::MailchimpList.maximum(:updated_at)
|
7
|
+
|
8
|
+
last synced with
|
9
|
+
= link_to 'Mailchimp', EffectiveMailchimp.api.admin_url, target: '_blank'
|
10
|
+
|
11
|
+
- if mailchimp_last_synced_at.present?
|
12
|
+
= time_ago_in_words(mailchimp_last_synced_at)
|
13
|
+
ago.
|
14
|
+
- else
|
15
|
+
never.
|
@@ -0,0 +1,79 @@
|
|
1
|
+
%h1.effective-admin-heading= @page_title
|
2
|
+
|
3
|
+
= card('Mailchimp Settings') do
|
4
|
+
- if EffectiveMailchimp.api_blank?
|
5
|
+
.alert.alert-danger You are not connected to Mailchimp. Please set your API key.
|
6
|
+
|
7
|
+
- if EffectiveMailchimp.api_present?
|
8
|
+
%p
|
9
|
+
= succeed('.') do
|
10
|
+
Please configure your
|
11
|
+
= link_to 'audiences', EffectiveMailchimp.api.audience_url, target: '_blank'
|
12
|
+
and
|
13
|
+
= link_to 'groups', EffectiveMailchimp.api.groups_url, target: '_blank'
|
14
|
+
on the Mailchimp website then sync the changes so they can be updated below
|
15
|
+
|
16
|
+
%p
|
17
|
+
You can also visit the
|
18
|
+
= link_to('contacts', EffectiveMailchimp.api.contacts_url, target: '_blank')
|
19
|
+
and
|
20
|
+
= link_to('campaigns', EffectiveMailchimp.api.campaigns_url, target: '_blank')
|
21
|
+
at anytime.
|
22
|
+
|
23
|
+
%p To change the names or display order of items below, please visit the Mailchimp website then sync changes.
|
24
|
+
|
25
|
+
= render('admin/mailchimp/sync')
|
26
|
+
|
27
|
+
%p.text-muted
|
28
|
+
%small This operation also creates the audience merge fields and updates the member and subscriber counts below.
|
29
|
+
|
30
|
+
= collapse('More settings') do
|
31
|
+
%p
|
32
|
+
For more information see
|
33
|
+
= succeed(',') do
|
34
|
+
= link_to(etsd(Effective::MailchimpList), effective_mailchimp.admin_mailchimp_lists_path, target: '_blank')
|
35
|
+
= succeed(',') do
|
36
|
+
= link_to(etsd(Effective::MailchimpListMember), effective_mailchimp.admin_mailchimp_list_members_path, target: '_blank')
|
37
|
+
= succeed(',') do
|
38
|
+
= link_to(etsd(Effective::MailchimpCategory), effective_mailchimp.admin_mailchimp_categories_path, target: '_blank')
|
39
|
+
and
|
40
|
+
= succeed('.') do
|
41
|
+
= link_to(etsd(Effective::MailchimpInterest), effective_mailchimp.admin_mailchimp_interests_path, target: '_blank')
|
42
|
+
|
43
|
+
%p The following merge fields are sent to Mailchimp when a user subscribes:
|
44
|
+
|
45
|
+
%ul
|
46
|
+
- EffectiveMailchimp.merge_fields.keys.sort.each do |key|
|
47
|
+
%li= key
|
48
|
+
|
49
|
+
.mb-4
|
50
|
+
|
51
|
+
= card(Effective::MailchimpList) do
|
52
|
+
%p
|
53
|
+
Audiences contain a list of your contacts.
|
54
|
+
View all #{link_to ets(Effective::MailchimpList), EffectiveMailchimp.api.audience_url, target: '_blank'}.
|
55
|
+
|
56
|
+
%p
|
57
|
+
%small
|
58
|
+
To change the name, please visit the Mailchimp website then sync changes.
|
59
|
+
Press the Edit button to change the Can Subscribe and Force Subscribe settings.
|
60
|
+
|
61
|
+
- datatable = Admin::EffectiveMailchimpListsDatatable.new
|
62
|
+
= render_datatable(datatable, inline: true, short: true, search: false, sort: false)
|
63
|
+
|
64
|
+
= card(Effective::MailchimpCategory) do
|
65
|
+
%p
|
66
|
+
The following groups are displayed to the user where they can opt-in to each interest.
|
67
|
+
View all #{link_to ets(Effective::MailchimpCategory), EffectiveMailchimp.api.groups_url, target: '_blank'}.
|
68
|
+
|
69
|
+
%p
|
70
|
+
%small
|
71
|
+
To change the name, please visit the Mailchimp website then sync changes.
|
72
|
+
Press the Edit button to change the Can Subscribe and Force Subscribe settings.
|
73
|
+
Sync changes to update the subscriber counts.
|
74
|
+
|
75
|
+
- Effective::MailchimpCategory.all.each do |mailchimp_category|
|
76
|
+
= card(mailchimp_category.to_s) do
|
77
|
+
- datatable = Admin::EffectiveMailchimpInterestsDatatable.new(mailchimp_category: mailchimp_category)
|
78
|
+
= render_datatable(datatable, inline: true, short: true, search: false, sort: false)
|
79
|
+
|
@@ -0,0 +1,10 @@
|
|
1
|
+
= effective_form_with(model: [:admin, mailchimp_interest], engine: true) do |f|
|
2
|
+
= f.static_field :name, label: EffectiveResources.et(mailchimp_interest)
|
3
|
+
|
4
|
+
= f.check_box :can_subscribe, label: "Yes, display this interest and allow them to subscribe"
|
5
|
+
|
6
|
+
= f.check_box :force_subscribe,
|
7
|
+
label: "Yes, force users to subscribe. Subscribe them automatically and do not allow unsubscribe from the website",
|
8
|
+
hint: "They can still unsubscribe from the email link to unsubscribe"
|
9
|
+
|
10
|
+
= effective_submit(f)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
= effective_form_with(model: [:admin, mailchimp_list], engine: true) do |f|
|
2
2
|
= f.static_field :name, label: EffectiveResources.et(mailchimp_list)
|
3
|
+
= f.static_field :merge_fields
|
3
4
|
|
4
5
|
= f.check_box :can_subscribe, label: "Yes, display users and allow them to subscribe"
|
5
6
|
|
@@ -1,13 +1,19 @@
|
|
1
|
-
= card(
|
2
|
-
%p.text-muted
|
1
|
+
= card('Mailchimp') do
|
2
|
+
%p.text-muted
|
3
|
+
= succeed('.') do
|
4
|
+
= user
|
5
|
+
is subscribed to
|
6
|
+
= pluralize(user.mailchimp_subscribed_lists.count, etd(Effective::MailchimpList))
|
7
|
+
and
|
8
|
+
= pluralize(user.mailchimp_subscribed_interests.count, etd(Effective::MailchimpInterest))
|
3
9
|
|
4
10
|
%p.text-muted
|
5
11
|
Please visit
|
6
|
-
= link_to '
|
12
|
+
= link_to 'Mailchimp Settings', effective_mailchimp.admin_mailchimp_path, target: '_blank'
|
7
13
|
to configure which are displayed.
|
8
14
|
|
9
15
|
%p
|
10
|
-
%strong Subscribed
|
16
|
+
%strong Subscribed to the following
|
11
17
|
|
12
18
|
= effective_form_with model: [:admin, user] do |f|
|
13
19
|
= f.hidden_field :id
|
@@ -7,14 +7,41 @@
|
|
7
7
|
= fmlm.hidden_field :id
|
8
8
|
= fmlm.hidden_field :mailchimp_list_id
|
9
9
|
|
10
|
-
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
- # With groups, probably single audience implementation
|
11
|
+
- if mailchimp_list.grouped?
|
12
|
+
= fmlm.hidden_field :subscribed, value: true
|
13
|
+
|
14
|
+
- # For each group / mailchimp_category
|
15
|
+
- mailchimp_list.mailchimp_categories.each do |mailchimp_category|
|
16
|
+
- mailchimp_interests = mailchimp_category.mailchimp_interests
|
17
|
+
|
18
|
+
- # Force subscription of each interest
|
19
|
+
- forced = mailchimp_interests.select { |mi| mi.force_subscribe? }
|
20
|
+
- fmlm.object.build_interests(forced)
|
21
|
+
|
22
|
+
- forced.each do |mailchimp_interest|
|
23
|
+
= fmlm.hidden_field :interests, name: "#{fmlm.object_name}[interests][]", value: mailchimp_interest.mailchimp_id
|
24
|
+
|
25
|
+
- # Add control for mailchimp interests
|
26
|
+
- mailchimp_interests_collection = mailchimp_list_member_interests_collection(mailchimp_interests)
|
27
|
+
|
28
|
+
- if mailchimp_category.display_type == 'select'
|
29
|
+
= fmlm.select :interests, mailchimp_interests_collection, label: mailchimp_category.to_s, name: "#{fmlm.object_name}[interests][]"
|
30
|
+
- elsif mailchimp_category.display_type == 'radio'
|
31
|
+
= fmlm.radios :interests, mailchimp_interests_collection, label: mailchimp_category.to_s, name: "#{fmlm.object_name}[interests][]"
|
14
32
|
- else
|
15
|
-
= fmlm.
|
16
|
-
|
33
|
+
= fmlm.checks :interests, mailchimp_interests_collection, label: mailchimp_category.to_s, name: "#{fmlm.object_name}[interests][]"
|
34
|
+
|
35
|
+
- # No groups, multiple audiences implementation
|
36
|
+
- if mailchimp_list.ungrouped?
|
37
|
+
- if mailchimp_list.force_subscribe?
|
38
|
+
%p
|
39
|
+
- if fmlm.object.cannot_be_subscribed?
|
40
|
+
= fmlm.check_box :subscribed, label: fmlm.object.to_s, disabled: true, hint: 'required but unsubscribed', checked: false
|
41
|
+
- else
|
42
|
+
= fmlm.check_box :subscribed, label: fmlm.object.to_s, disabled: true, hint: 'required', checked: true
|
43
|
+
= fmlm.hidden_field :subscribed, value: true
|
17
44
|
|
18
|
-
|
19
|
-
|
20
|
-
|
45
|
+
- elsif mailchimp_list.can_subscribe?
|
46
|
+
%p
|
47
|
+
= fmlm.check_box :subscribed, label: fmlm.object.to_s
|
@@ -5,4 +5,10 @@ EffectiveMailchimp.setup do |config|
|
|
5
5
|
|
6
6
|
# Mailchimp Settings
|
7
7
|
config.api_key = '' # From mailchimp's /account/api/ screen
|
8
|
+
|
9
|
+
# In Sandbox Mode you can only READ from Mailchimp not actually write to it
|
10
|
+
config.sandbox_mode = false
|
11
|
+
|
12
|
+
# Assign the User class name. For use in determining all merge_fields
|
13
|
+
# config.user_class_name = 'User'
|
8
14
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
en:
|
2
|
+
effective_mailchimp:
|
3
|
+
name: 'Effective Mailchimp'
|
4
|
+
acronym: 'Mailchimp'
|
5
|
+
|
6
|
+
activerecord:
|
7
|
+
models:
|
8
|
+
# These ones should stay effective
|
9
|
+
effective/mailchimp_list: 'Mailchimp Audience'
|
10
|
+
effective/mailchimp_list_member: 'Mailchimp Audience Member'
|
11
|
+
effective/mailchimp_category: 'Mailchimp Group'
|
12
|
+
effective/mailchimp_interest: 'Mailchimp Group Interest'
|
data/config/routes.rb
CHANGED
@@ -14,18 +14,20 @@ EffectiveMailchimp::Engine.routes.draw do
|
|
14
14
|
|
15
15
|
namespace :admin do
|
16
16
|
resources :mailchimp_lists, only: [:index, :edit, :update] do
|
17
|
-
post :
|
18
|
-
post :
|
19
|
-
|
20
|
-
post :force_subscribe, on: :member
|
21
|
-
post :unforce_subscribe, on: :member
|
22
|
-
|
23
|
-
get :mailchimp_sync, on: :collection
|
17
|
+
post :subscribe_all_users, on: :member
|
18
|
+
post :subscribe_all_members, on: :member
|
24
19
|
end
|
25
20
|
|
21
|
+
resources :mailchimp_interests, only: [:index, :edit, :update]
|
22
|
+
resources :mailchimp_categories, only: :index
|
23
|
+
resources :mailchimp_list_members, only: :index
|
24
|
+
|
26
25
|
resources :mailchimp, only: [] do
|
26
|
+
post :mailchimp_sync, on: :collection
|
27
27
|
post :mailchimp_sync_user, on: :member
|
28
28
|
end
|
29
|
+
|
30
|
+
get '/mailchimp', to: 'mailchimp#index', as: :mailchimp
|
29
31
|
end
|
30
32
|
|
31
33
|
end
|
@@ -5,6 +5,43 @@ class CreateEffectiveMailchimp < ActiveRecord::Migration[6.0]
|
|
5
5
|
t.string :web_id
|
6
6
|
t.string :name
|
7
7
|
|
8
|
+
t.integer :member_count
|
9
|
+
|
10
|
+
t.boolean :can_subscribe
|
11
|
+
t.boolean :force_subscribe
|
12
|
+
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
create_table :mailchimp_categories do |t|
|
17
|
+
t.integer :mailchimp_list_id
|
18
|
+
|
19
|
+
t.string :mailchimp_id
|
20
|
+
t.string :list_id
|
21
|
+
|
22
|
+
t.string :name
|
23
|
+
t.string :list_name
|
24
|
+
|
25
|
+
t.string :display_type
|
26
|
+
|
27
|
+
t.timestamps
|
28
|
+
end
|
29
|
+
|
30
|
+
create_table :mailchimp_interests do |t|
|
31
|
+
t.integer :mailchimp_list_id
|
32
|
+
t.integer :mailchimp_category_id
|
33
|
+
|
34
|
+
t.string :mailchimp_id
|
35
|
+
t.string :list_id
|
36
|
+
t.string :category_id
|
37
|
+
|
38
|
+
t.string :name
|
39
|
+
t.string :list_name
|
40
|
+
t.string :category_name
|
41
|
+
|
42
|
+
t.integer :display_order
|
43
|
+
t.integer :subscriber_count
|
44
|
+
|
8
45
|
t.boolean :can_subscribe
|
9
46
|
t.boolean :force_subscribe
|
10
47
|
|
@@ -26,6 +63,8 @@ class CreateEffectiveMailchimp < ActiveRecord::Migration[6.0]
|
|
26
63
|
t.boolean :subscribed, default: false
|
27
64
|
t.boolean :cannot_be_subscribed, default: false
|
28
65
|
|
66
|
+
t.text :interests
|
67
|
+
|
29
68
|
t.datetime :last_synced_at
|
30
69
|
|
31
70
|
t.timestamps
|
data/lib/effective_mailchimp.rb
CHANGED
@@ -7,9 +7,9 @@ module EffectiveMailchimp
|
|
7
7
|
|
8
8
|
def self.config_keys
|
9
9
|
[
|
10
|
-
:mailchimp_lists_table_name, :mailchimp_list_members_table_name,
|
10
|
+
:mailchimp_lists_table_name, :mailchimp_list_members_table_name, :mailchimp_categories_table_name, :mailchimp_interests_table_name,
|
11
11
|
:layout,
|
12
|
-
:api_key
|
12
|
+
:api_key, :sandbox_mode, :user_class_name
|
13
13
|
]
|
14
14
|
end
|
15
15
|
|
@@ -19,12 +19,37 @@ module EffectiveMailchimp
|
|
19
19
|
Effective::MailchimpApi.new(api_key: api_key)
|
20
20
|
end
|
21
21
|
|
22
|
+
def self.sandbox_mode?
|
23
|
+
!!sandbox_mode
|
24
|
+
end
|
25
|
+
|
22
26
|
def self.api_present?
|
23
27
|
api_key.present?
|
24
28
|
end
|
25
29
|
|
30
|
+
def self.api_blank?
|
31
|
+
api_key.blank?
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.User
|
35
|
+
klass = user_class_name.constantize if user_class_name.present?
|
36
|
+
klass ||= Tenant.User if defined?(Tenant)
|
37
|
+
klass ||= '::User'.safe_constantize
|
38
|
+
|
39
|
+
raise('unable to determine User klass. Please set config.user_class_name') unless klass.kind_of?(Class)
|
40
|
+
raise('expecting an effective_mailchimp_user User class') unless klass.respond_to?(:effective_mailchimp_user)
|
41
|
+
|
42
|
+
klass
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.merge_fields
|
46
|
+
merge_fields = self.User().new.mailchimp_merge_fields
|
47
|
+
raise('expected a Hash of merge fields') unless merge_fields.kind_of?(Hash)
|
48
|
+
merge_fields
|
49
|
+
end
|
50
|
+
|
26
51
|
def self.permitted_params
|
27
|
-
[ :mailchimp_user_form_action, mailchimp_list_members_attributes: [:id, :mailchimp_list_id, :subscribed] ]
|
52
|
+
[ :mailchimp_user_form_action, mailchimp_list_members_attributes: [:id, :mailchimp_list_id, :subscribed, interests: []] ]
|
28
53
|
end
|
29
54
|
|
30
55
|
end
|
@@ -5,20 +5,4 @@ namespace :effective_mailchimp do
|
|
5
5
|
load "#{__dir__}/../../db/seeds.rb"
|
6
6
|
end
|
7
7
|
|
8
|
-
# bundle exec rake effective_mailchimp:create_mailchimp_merge_fields
|
9
|
-
task create_mailchimp_merge_fields: :environment do
|
10
|
-
merge_fields = User.new.mailchimp_merge_fields()
|
11
|
-
|
12
|
-
Effective::MailchimpList.sync!
|
13
|
-
|
14
|
-
collection = Effective::MailchimpList.all
|
15
|
-
|
16
|
-
collection.find_each do |list|
|
17
|
-
puts "Creating #{list} merge fields"
|
18
|
-
list.create_mailchimp_merge_fields!(merge_fields)
|
19
|
-
end
|
20
|
-
|
21
|
-
puts 'All done'
|
22
|
-
end
|
23
|
-
|
24
8
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_mailchimp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -193,23 +193,36 @@ files:
|
|
193
193
|
- app/assets/javascripts/effective_mailchimp/base.js
|
194
194
|
- app/assets/stylesheets/effective_mailchimp.scss
|
195
195
|
- app/assets/stylesheets/effective_mailchimp/base.scss
|
196
|
+
- app/controllers/admin/mailchimp_categories_controller.rb
|
196
197
|
- app/controllers/admin/mailchimp_controller.rb
|
198
|
+
- app/controllers/admin/mailchimp_interests_controller.rb
|
199
|
+
- app/controllers/admin/mailchimp_list_members_controller.rb
|
197
200
|
- app/controllers/admin/mailchimp_lists_controller.rb
|
198
201
|
- app/controllers/effective/mailchimp_controller.rb
|
202
|
+
- app/datatables/admin/effective_mailchimp_categories_datatable.rb
|
203
|
+
- app/datatables/admin/effective_mailchimp_interests_datatable.rb
|
204
|
+
- app/datatables/admin/effective_mailchimp_list_members_datatable.rb
|
199
205
|
- app/datatables/admin/effective_mailchimp_lists_datatable.rb
|
200
206
|
- app/helpers/effective_mailchimp_helper.rb
|
207
|
+
- app/jobs/effective_mailchimp_subscribe_all_members_job.rb
|
208
|
+
- app/jobs/effective_mailchimp_subscribe_all_users_job.rb
|
201
209
|
- app/jobs/effective_mailchimp_update_job.rb
|
202
210
|
- app/models/concerns/effective_mailchimp_user.rb
|
203
211
|
- app/models/effective/mailchimp_api.rb
|
212
|
+
- app/models/effective/mailchimp_category.rb
|
213
|
+
- app/models/effective/mailchimp_interest.rb
|
204
214
|
- app/models/effective/mailchimp_list.rb
|
205
215
|
- app/models/effective/mailchimp_list_member.rb
|
216
|
+
- app/views/admin/mailchimp/_sync.html.haml
|
217
|
+
- app/views/admin/mailchimp/index.html.haml
|
218
|
+
- app/views/admin/mailchimp_interests/_form.html.haml
|
206
219
|
- app/views/admin/mailchimp_lists/_form.html.haml
|
207
|
-
- app/views/admin/mailchimp_lists/index.html.haml
|
208
220
|
- app/views/admin/mailchimp_user/_form.html.haml
|
209
221
|
- app/views/admin/mailchimp_user/_sync.html.haml
|
210
222
|
- app/views/effective/mailchimp_user/_fields.html.haml
|
211
223
|
- app/views/effective/mailchimp_user/_sync.html.haml
|
212
224
|
- config/effective_mailchimp.rb
|
225
|
+
- config/locales/effective_mailchimp.en.yml
|
213
226
|
- config/routes.rb
|
214
227
|
- db/migrate/101_create_effective_mailchimp.rb
|
215
228
|
- db/seeds.rb
|
@@ -1,20 +0,0 @@
|
|
1
|
-
%h1.effective-admin-heading= @page_title
|
2
|
-
|
3
|
-
- resource = (@_effective_resource || Effective::Resource.new(controller_path))
|
4
|
-
|
5
|
-
.resource-buttons
|
6
|
-
= render_resource_buttons(resource.klass, (action ||= :index) => false)
|
7
|
-
|
8
|
-
= card do
|
9
|
-
= collapse('Show merge field settings') do
|
10
|
-
%p The following Merge fields are sent to Mailchimp when a user subscribes:
|
11
|
-
|
12
|
-
%ul
|
13
|
-
- current_user.mailchimp_merge_fields.keys.each do |key|
|
14
|
-
%li= key
|
15
|
-
|
16
|
-
%p To have these fields displayed in Mailchimp, please configure each campaign with any of these merge fields.
|
17
|
-
|
18
|
-
.mb-4
|
19
|
-
|
20
|
-
= render_datatable @datatable
|