effective_mailchimp 0.9.1 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/admin/mailchimp_controller.rb +14 -0
- data/app/jobs/effective_mailchimp_sync_users_job.rb +23 -0
- data/app/models/concerns/effective_mailchimp_user.rb +22 -6
- data/app/models/effective/mailchimp_list_member.rb +2 -1
- data/app/views/admin/mailchimp/_last_sync.html.haml +12 -0
- data/app/views/admin/mailchimp/_sync.html.haml +0 -13
- data/app/views/admin/mailchimp/_sync_users.html.haml +2 -0
- data/app/views/admin/mailchimp/index.html.haml +15 -2
- data/config/routes.rb +1 -0
- data/lib/effective_mailchimp/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e160d18a30ca7d423b2fa0bda06ee1c863a93c1c2e40845d5c4d7a295f61c0a
|
4
|
+
data.tar.gz: 72344d51bf42e59b48ac0f07652aa69d44261464e3d5ef50b27d2a3160d42241
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 417d2ff2930dcced75059bcd9c6d344dbad2132078c3267a058de9ff57c9c73490f63c91dcda306583039a0d41da7197d940cff8efdbcd27a91b2ecf4087859d
|
7
|
+
data.tar.gz: 3d1b326ab312e203e9f326c18398c08d4cd9db2dab4c3ef2c45245ddfc0dc20cb86947bb870cc5b8abe8b6c69a3a971d14d16a7014a63769d66c98ff35a0e71b
|
@@ -25,6 +25,20 @@ module Admin
|
|
25
25
|
redirect_back(fallback_location: effective_mailchimp.admin_mailchimp_path)
|
26
26
|
end
|
27
27
|
|
28
|
+
# Sync all users
|
29
|
+
def mailchimp_sync_users
|
30
|
+
EffectiveResources.authorize!(self, :admin, :mailchimp_sync_users)
|
31
|
+
|
32
|
+
user_class_name = current_user.class.name
|
33
|
+
|
34
|
+
# This calls user.mailchimp_sync! on all users
|
35
|
+
EffectiveMailchimpSyncUsersJob.perform_later(user_class_name)
|
36
|
+
|
37
|
+
flash[:success] = "Successfully started mailchimp sync all users background job. Please wait a few minutes for it to complete. Check the logs for progress."
|
38
|
+
|
39
|
+
redirect_back(fallback_location: effective_mailchimp.admin_mailchimp_path)
|
40
|
+
end
|
41
|
+
|
28
42
|
# Sync one user
|
29
43
|
def mailchimp_sync_user
|
30
44
|
resource = current_user.class.find(params[:id])
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class EffectiveMailchimpSyncUsersJob < ApplicationJob
|
2
|
+
def perform(user_class_name)
|
3
|
+
users = user_class_name.safe_constantize
|
4
|
+
raise('expected an effective_mailchimp_user class') unless users.try(:effective_mailchimp_user?)
|
5
|
+
raise('expected a mailchimp API key') unless EffectiveMailchimp.api_present?
|
6
|
+
|
7
|
+
api = EffectiveMailchimp.api
|
8
|
+
|
9
|
+
EffectiveLogger.info("Starting sync users from mailchimp job")
|
10
|
+
|
11
|
+
users.find_each do |user|
|
12
|
+
begin
|
13
|
+
puts "Mailchimp sync user #{user.id}"
|
14
|
+
user.mailchimp_sync!(api: api)
|
15
|
+
rescue => e
|
16
|
+
EffectiveLogger.error(e.message, associated: user) if defined?(EffectiveLogger)
|
17
|
+
ExceptionNotifier.notify_exception(e, data: { user_id: user.id }) if defined?(ExceptionNotifier)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
EffectiveLogger.info("Finished sync users from mailchimp job")
|
22
|
+
end
|
23
|
+
end
|
@@ -200,16 +200,18 @@ module EffectiveMailchimpUser
|
|
200
200
|
# Run before the mailchimp fields are displayed
|
201
201
|
# Only run in the background when a user or admin clicks sync now
|
202
202
|
def mailchimp_sync!(api: EffectiveMailchimp.api)
|
203
|
-
lists = Effective::MailchimpList.
|
203
|
+
lists = Effective::MailchimpList.sorted.to_a
|
204
204
|
|
205
205
|
assign_attributes(mailchimp_user_form_action: nil)
|
206
206
|
|
207
|
-
|
208
|
-
lists.
|
209
|
-
|
207
|
+
mailchimp_with_retries do
|
208
|
+
Timeout::timeout(lists.length * 3) do
|
209
|
+
lists.each do |mailchimp_list|
|
210
|
+
member = build_mailchimp_list_member(mailchimp_list: mailchimp_list)
|
210
211
|
|
211
|
-
|
212
|
-
|
212
|
+
list_member = api.list_member(mailchimp_list, email) || {}
|
213
|
+
member.assign_mailchimp_attributes(list_member)
|
214
|
+
end
|
213
215
|
end
|
214
216
|
end
|
215
217
|
|
@@ -252,6 +254,20 @@ module EffectiveMailchimpUser
|
|
252
254
|
|
253
255
|
private
|
254
256
|
|
257
|
+
def mailchimp_with_retries(retries: 3, wait: 2, &block)
|
258
|
+
raise('expected a block') unless block_given?
|
259
|
+
|
260
|
+
begin
|
261
|
+
return yield
|
262
|
+
rescue Exception => e
|
263
|
+
if (retries -= 1) > 0
|
264
|
+
sleep(wait); retry
|
265
|
+
else
|
266
|
+
raise
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
255
271
|
def mailchimp_member_update_required?
|
256
272
|
return false unless mailchimp_user_form_action
|
257
273
|
return false if self.class.respond_to?(:effective_memberships_user) && membership&.mailchimp_membership_update_required?
|
@@ -41,7 +41,7 @@ module Effective
|
|
41
41
|
scope :subscribed, -> { where(subscribed: true) }
|
42
42
|
|
43
43
|
def to_s
|
44
|
-
mailchimp_list
|
44
|
+
[mailchimp_list, user].compact.join(' - ').presence || model_name.human
|
45
45
|
end
|
46
46
|
|
47
47
|
def email
|
@@ -86,6 +86,7 @@ module Effective
|
|
86
86
|
email_address: atts['email_address'],
|
87
87
|
full_name: atts['full_name'],
|
88
88
|
subscribed: (atts['status'] == 'subscribed'),
|
89
|
+
cannot_be_subscribed: ['unsubscribed', 'cleaned', 'archived'].include?(atts['status']),
|
89
90
|
last_synced_at: Time.zone.now,
|
90
91
|
interests: Hash(atts['interests']).select { |_, subscribed| subscribed == true }.keys
|
91
92
|
)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
%p.text-muted
|
2
|
+
%small
|
3
|
+
- mailchimp_last_synced_at = Effective::MailchimpList.maximum(:updated_at)
|
4
|
+
|
5
|
+
last synced with
|
6
|
+
= link_to 'Mailchimp', EffectiveMailchimp.api.admin_url, target: '_blank'
|
7
|
+
|
8
|
+
- if mailchimp_last_synced_at.present?
|
9
|
+
= time_ago_in_words(mailchimp_last_synced_at)
|
10
|
+
ago.
|
11
|
+
- else
|
12
|
+
never.
|
@@ -1,15 +1,2 @@
|
|
1
1
|
- if EffectiveResources.authorized?(self, :admin, :mailchimp_sync)
|
2
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.
|
@@ -20,12 +20,25 @@
|
|
20
20
|
= link_to('campaigns', EffectiveMailchimp.api.campaigns_url, target: '_blank')
|
21
21
|
at anytime.
|
22
22
|
|
23
|
-
%
|
23
|
+
%hr
|
24
|
+
|
25
|
+
%p To change the names or display order of items below, visit the Mailchimp website and make any changes. Once done, return here and click Sync changes from Mailchimp.
|
24
26
|
|
25
27
|
= render('admin/mailchimp/sync')
|
26
28
|
|
27
29
|
%p.text-muted
|
28
|
-
%small This
|
30
|
+
%small This step also creates the audience merge fields and updates the member and subscriber counts below.
|
31
|
+
|
32
|
+
%hr
|
33
|
+
|
34
|
+
%p To assign user interests from Mailchimp, visit the Mailchimp website and import or update contacts info. Once done, return here and click Sync users from Mailchimp.
|
35
|
+
|
36
|
+
= render('admin/mailchimp/sync_users')
|
37
|
+
|
38
|
+
%p.text-muted
|
39
|
+
%small This step is only necessary after manually importing Contacts on the Mailchimp website. This will start a background job to mailchimp sync every user. You can sync individual users from their Edit screen.
|
40
|
+
|
41
|
+
%hr
|
29
42
|
|
30
43
|
= collapse('More settings') do
|
31
44
|
%p
|
data/config/routes.rb
CHANGED
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.9.
|
4
|
+
version: 0.9.2
|
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-
|
11
|
+
date: 2024-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -206,6 +206,7 @@ files:
|
|
206
206
|
- app/helpers/effective_mailchimp_helper.rb
|
207
207
|
- app/jobs/effective_mailchimp_subscribe_all_members_job.rb
|
208
208
|
- app/jobs/effective_mailchimp_subscribe_all_users_job.rb
|
209
|
+
- app/jobs/effective_mailchimp_sync_users_job.rb
|
209
210
|
- app/jobs/effective_mailchimp_update_job.rb
|
210
211
|
- app/models/concerns/effective_mailchimp_user.rb
|
211
212
|
- app/models/effective/mailchimp_api.rb
|
@@ -213,7 +214,9 @@ files:
|
|
213
214
|
- app/models/effective/mailchimp_interest.rb
|
214
215
|
- app/models/effective/mailchimp_list.rb
|
215
216
|
- app/models/effective/mailchimp_list_member.rb
|
217
|
+
- app/views/admin/mailchimp/_last_sync.html.haml
|
216
218
|
- app/views/admin/mailchimp/_sync.html.haml
|
219
|
+
- app/views/admin/mailchimp/_sync_users.html.haml
|
217
220
|
- app/views/admin/mailchimp/index.html.haml
|
218
221
|
- app/views/admin/mailchimp_interests/_form.html.haml
|
219
222
|
- app/views/admin/mailchimp_lists/_form.html.haml
|