devise_campaignable 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd1c9fd014e96dbf4770e89fcf7fb7e6b44db9fb
4
- data.tar.gz: bf3723b04a48b23e97b76c5ea52284caf2618637
3
+ metadata.gz: 16a3726859e1ff005cd22d5f4e1bae73022829be
4
+ data.tar.gz: 28bcc201d0c87e29fce85f5630fd320179901d40
5
5
  SHA512:
6
- metadata.gz: e35a3031a6e7ccaad329d47315e54462ef2525e5c231ccbff540212eab00415d5a24ef387efaf879109868ae5c19f0e72eaf32d9d76a07ba94b3ceea7b52fa8a
7
- data.tar.gz: 6e5b30a8272222b0aadc4a2ef7090b5d59c4d13c3f20aca2128cb5852ff305fc4937057686f500561c6419a6161120869997a445dbea13484b2b5919b1f590fc
6
+ metadata.gz: bd4f45df15abf3eaf73457330b88d457a44c5143b2fdd2fd22c1db8696e2d5ca70585e5d66d4d234fc91ba9cc6e6880ece49e8f145bf98c472221fa5ad89e677
7
+ data.tar.gz: 3d57d1c73508f9e3d65dc58c8be604c41e966f1fe28001fdde194d53825200c26992940e2020971ac6ac195271e22afb1300964e8c308d2023b7308db3b9d995
@@ -19,6 +19,15 @@ module Devise
19
19
  # Raise an error to warn it isn't implemented.
20
20
  raise NotImplementedError.new
21
21
  end
22
+
23
+ # Placeholder methods for the adapter, these should be implemented
24
+ # in the parent class but not on the base adapter.
25
+ #
26
+ # Update an existing subscription.
27
+ def update_subscription(old_email, new_email)
28
+ # Raise an error to warn it isn't implemented.
29
+ raise NotImplementedError.new
30
+ end
22
31
 
23
32
  # Placeholder methods for the adapter, these should be implemented
24
33
  # in the parent class but not on the base adapter.
@@ -18,13 +18,24 @@ module Devise
18
18
  })
19
19
  end
20
20
 
21
+ # Update an existing subscription.
22
+ def update_subscription(old_email, new_email)
23
+ # Mailchimp have a handy helper for updating an existing subscription.
24
+ api.update_member({
25
+ :id => @campaignable_list_id,
26
+ :email => {
27
+ :email => old_email
28
+ },
29
+ :merge_vars => {
30
+ :'new-email' => new_email
31
+ }
32
+ })
33
+ end
34
+
21
35
  # Method to unsubscribe the user from the configured mailing list.
22
36
  # This method is available for API Keys belonging to users with the following roles: manager, admin, owner
23
37
  def unsubscribe(email)
24
38
  # Logic for mailchimp unsubscription.
25
- # TODO: Move this into some form of adaptor for Mailchimp so this
26
- # TODO: Should this check they are subscribed before attemoting to delete?
27
- # class becomes more generic.
28
39
  api.unsubscribe({
29
40
  :id => @campaignable_list_id,
30
41
  :email => {
@@ -21,6 +21,8 @@ module Devise
21
21
  included do
22
22
  # Callback to subscribe the user whenever the record is created
23
23
  after_create :subscribe
24
+ # Callback to see if the subscription for this users needs updating.
25
+ after_update :update_subscription
24
26
  # Callback to unsubscribe the user when they are destroyed.
25
27
  after_destroy :unsubscribe
26
28
  end
@@ -31,6 +33,13 @@ module Devise
31
33
  self.class.list_manager.subscribe(self.email)
32
34
  end
33
35
 
36
+ # Method to update the subscription
37
+ def update_subscription
38
+ # Only change the subscription if the models email
39
+ # address has been changed.
40
+ self.class.list_manager.update_subscription(self.email_was, self.email) if self.email_changed?
41
+ end
42
+
34
43
  # Method to unsubscribe the user from the configured mailing list.
35
44
  def unsubscribe
36
45
  # Ask the list manager to unsubscribe this devise models email.
@@ -1,3 +1,3 @@
1
1
  module DeviseCampaignable
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise_campaignable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Rawlins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-04 00:00:00.000000000 Z
11
+ date: 2015-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler