effective_mailchimp 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 214e9412954d0415e5263797289e58956f53b56828715aaf390e7c9d7db09f61
4
- data.tar.gz: 6a029f0bb604421755c58cfa5f988d581cc688f990de102901f2e5938a643980
3
+ metadata.gz: aeb420fedb9cb1cd9ef0454773d4daf4e1b738e472ad5154226bb3ba299f7010
4
+ data.tar.gz: 35faa4bdbd56036558bf3ebf5c3bce35a8eb37eb3eab17b123449fc56f60dd16
5
5
  SHA512:
6
- metadata.gz: 8e6b26604ad0d1c0e094706da41be5280f757073747a2203de09854990562f0a947022f3e05223c1e38bca818c77840d320a589d3bd1968f624a1dfd26b9e911
7
- data.tar.gz: 18513f661502df66716ddf9b293ae05fd1b5d14c6e2ff68678172b3b3d4d90b606238dfe98979f38cf85fefa8562e92e8fa0dbc9b85e1ce2dd08ce247ca8100d
6
+ metadata.gz: 6c888569b99ed7d9474706235698af874c54edca6a3b13a53e449f0a03ca9d2e64099b642b640959ad5100b5964ef06f873739c853f6e11daeb05a33b99ef93f
7
+ data.tar.gz: f50fc3d24091a2f58a2361b015e4329c21be5846081f9d660b9e6c00c017171952324a3e7f37c56b00f49b012e80ea97a1127f5ae7c26bd51c64d6cf7f6534e8
@@ -29,6 +29,10 @@ module EffectiveMailchimpUser
29
29
  has_many :mailchimp_lists, -> { Effective::MailchimpList.sorted }, through: :mailchimp_list_members, class_name: 'Effective::MailchimpList'
30
30
  accepts_nested_attributes_for :mailchimp_lists, allow_destroy: true
31
31
 
32
+ scope :deep_effective_mailchimp_user, -> {
33
+ includes(mailchimp_list_members: [:mailchimp_list])
34
+ }
35
+
32
36
  # The user updated the form
33
37
  after_commit(if: -> { mailchimp_member_update_required? }) do
34
38
  EffectiveMailchimpUpdateJob.perform_later(self)
@@ -184,12 +188,20 @@ module EffectiveMailchimpUser
184
188
  assign_attributes(mailchimp_user_form_action: nil)
185
189
 
186
190
  mailchimp_list_members.each do |member|
187
- if member.mailchimp_id.blank? && member.subscribed?
188
- list_member = api.list_member_add(member)
189
- member.assign_mailchimp_attributes(list_member) if list_member.present?
190
- elsif member.mailchimp_id.present?
191
- list_member = api.list_member_update(member)
191
+ begin
192
+ list_member = if member.mailchimp_id.blank? && member.subscribed?
193
+ api.list_member_add(member)
194
+ elsif member.mailchimp_id.present?
195
+ api.list_member_update(member)
196
+ end
197
+
192
198
  member.assign_mailchimp_attributes(list_member) if list_member.present?
199
+ rescue MailchimpMarketing::ApiError => e
200
+ if e.to_s.downcase.include?("cannot be subscribed")
201
+ member.assign_mailchimp_cannot_be_subscribed
202
+ else
203
+ raise(e)
204
+ end
193
205
  end
194
206
  end
195
207
 
@@ -94,13 +94,7 @@ module Effective
94
94
  merge_fields: merge_fields.delete_if { |k, v| v.blank? }
95
95
  }
96
96
 
97
- begin
98
- client.lists.add_list_member(member.mailchimp_list.mailchimp_id, payload)
99
- rescue MailchimpMarketing::ApiError => e
100
- return false if e.status == 400 && e.to_s.downcase.include?("member in compliance state")
101
- raise(e)
102
- end
103
-
97
+ client.lists.add_list_member(member.mailchimp_list.mailchimp_id, payload)
104
98
  end
105
99
 
106
100
  def list_member_update(member)
@@ -14,7 +14,12 @@ module Effective
14
14
  email_address :string
15
15
  full_name :string
16
16
 
17
- subscribed :boolean
17
+ # We set this on our side to update mailchimp and subscribe the user
18
+ subscribed :boolean
19
+
20
+ # This one is generated by the MailchimpMarketing::ApiError
21
+ # They unsubscribed and there's nothing we can do about it.
22
+ cannot_be_subscribed :boolean # Member is in Compliance State
18
23
 
19
24
  last_synced_at :datetime
20
25
 
@@ -45,6 +50,14 @@ module Effective
45
50
  )
46
51
  end
47
52
 
53
+ def assign_mailchimp_cannot_be_subscribed
54
+ assign_attributes(
55
+ subscribed: false,
56
+ cannot_be_subscribed: true,
57
+ last_synced_at: Time.zone.now
58
+ )
59
+ end
60
+
48
61
  def synced?
49
62
  last_synced_at.present?
50
63
  end
@@ -9,8 +9,11 @@
9
9
 
10
10
  - if mailchimp_list.force_subscribe?
11
11
  %p
12
- = fmlm.check_box :subscribed, label: fmlm.object.to_s, disabled: true, hint: 'required', checked: true
13
- = fmlm.hidden_field :subscribed, value: true
12
+ - if fmlm.object.cannot_be_subscribed?
13
+ = fmlm.check_box :subscribed, label: fmlm.object.to_s, disabled: true, hint: 'required but unsubscribed', checked: false
14
+ - else
15
+ = fmlm.check_box :subscribed, label: fmlm.object.to_s, disabled: true, hint: 'required', checked: true
16
+ = fmlm.hidden_field :subscribed, value: true
14
17
 
15
18
  - elsif mailchimp_list.can_subscribe?
16
19
  %p
@@ -23,7 +23,8 @@ class CreateEffectiveMailchimp < ActiveRecord::Migration[6.0]
23
23
  t.string :email_address
24
24
  t.string :full_name
25
25
 
26
- t.boolean :subscribed
26
+ t.boolean :subscribed, default: false
27
+ t.boolean :cannot_be_subscribed, default: false
27
28
 
28
29
  t.datetime :last_synced_at
29
30
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveMailchimp
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  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.0
4
+ version: 0.5.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: 2023-08-24 00:00:00.000000000 Z
11
+ date: 2024-02-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -238,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
238
  - !ruby/object:Gem::Version
239
239
  version: '0'
240
240
  requirements: []
241
- rubygems_version: 3.4.10
241
+ rubygems_version: 3.5.6
242
242
  signing_key:
243
243
  specification_version: 4
244
244
  summary: Subscribe and unsubscribe to mailchimp lists.