effective_mailchimp 0.4.1 → 0.5.1

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: 535f050cd4e6f5a4419ddecb931c864f2f0461b936a822db66631619ba1ed3f1
4
- data.tar.gz: 7410b8b797f397bdecbcad0bddb78fe43a7779f07aa858ec710a5489063c2ac7
3
+ metadata.gz: 42b138c379e2bef73c47ff7dfdf53ed004505b0e892ff407a16558cfa2deac4b
4
+ data.tar.gz: 199f1d58e6f32d182c80cfd5be9d4ca970bbf828944820563af7319126ce6ea0
5
5
  SHA512:
6
- metadata.gz: 59c142b817e13988549b669eb9c73419f090e751c106b6b50e9d0978e810161dcba11dffd0fdc22220de93754dd38e1bedf890905d640f988c8485b882749d2a
7
- data.tar.gz: 0643a72575207d3e4e0a5aa5f78e92c0e46386e617b3a2c400764b99f8a5a8f501891dc6ace45c373c702d18da5fad3af53b018ee0a314890457766e23bfb9d9
6
+ metadata.gz: 55ffa0423f7a02d94d3f74113b9139f44e71943b9748a82106d54c3ddf93abf26057c86755fec0a1a058e1706052aad79e4100066e7cc8fe0c3c9560331c61d5
7
+ data.tar.gz: 6306b88940c840bf58f099436362e0c386e440ac1e511e42c088a163f8cdc322b8597e30c9554b95f54e0a93fccf0f639c7b63f323475a7a19e7e6ca63aaa412
@@ -188,12 +188,20 @@ module EffectiveMailchimpUser
188
188
  assign_attributes(mailchimp_user_form_action: nil)
189
189
 
190
190
  mailchimp_list_members.each do |member|
191
- if member.mailchimp_id.blank? && member.subscribed?
192
- list_member = api.list_member_add(member)
193
- member.assign_mailchimp_attributes(list_member) if list_member.present?
194
- elsif member.mailchimp_id.present?
195
- 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
+
196
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") || e.to_s.downcase.include?('deleted')
201
+ member.assign_mailchimp_cannot_be_subscribed
202
+ else
203
+ raise(e)
204
+ end
197
205
  end
198
206
  end
199
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.1'.freeze
2
+ VERSION = '0.5.1'.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.1
4
+ version: 0.5.1
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-12-01 00:00:00.000000000 Z
11
+ date: 2024-03-18 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.