devise_campaignable 0.2.0 → 0.2.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
  SHA1:
3
- metadata.gz: 14a7a24f8cd973480789f970ba22350b78757432
4
- data.tar.gz: ed115510d3be3239206b6aa0bb541fd31e6374c1
3
+ metadata.gz: b891f9af5294938099bb81b548b4bf083d0d4391
4
+ data.tar.gz: 1dc8cc8327eb474c83095f6911af9964e87f4eba
5
5
  SHA512:
6
- metadata.gz: 3da5b3a6e930f9723e2a62ab4dbc45e67b8f4f16fd5460b6365a87d90d890f6785a8fbc3b9ff14973cf06bf113fdea38463a10b4776caa54d9e403710480f9f8
7
- data.tar.gz: 70d51c5ba5f574011aebce55bfda71235e4e5cc42e7698f608c0d44d22a0f953eb04493c87376e96743b1e80bb264d699b22691bcaf4b077f32e006ab4503281
6
+ metadata.gz: e6c6a17ad66f69d46b826f18c7a88c8574134b6dbe682ddcab48d65861724551d6607ab97685bb0ae134b94ac52387c77f6fc741dbe3ecedea64deb2d05b87e3
7
+ data.tar.gz: 31f37646466a573a64079dfa9e6a1aa91f308f48bb3ca6a16e9c3feece096fd9e18a86d96ce1e8a0b5655116b9d08003f1abff231b3da27491f38359bcf9002f
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ - 2.2.0
5
+ - rbx-2
6
+ script: bundle exec rspec .
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # DeviseCampaignable
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/devise_campaignable.svg)](http://badge.fury.io/rb/devise_campaignable)
3
+ [![Build Status](https://travis-ci.org/sorry-app/devise_campaignable.svg?branch=master)](https://travis-ci.org/sorry-app/devise_campaignable) [![Gem Version](https://badge.fury.io/rb/devise_campaignable.svg)](http://badge.fury.io/rb/devise_campaignable)
4
4
 
5
5
  Have your users automatically added to and removed from your favourite mail campaign tool. Currently supports [MailChimp](http://mailchimp.com/).
6
6
 
@@ -21,7 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "rspec"
24
-
24
+ spec.add_development_dependency "activemodel"
25
+
25
26
  spec.add_runtime_dependency "devise", ">= 3.2.0"
26
27
  spec.add_runtime_dependency "gibbon", "~> 2.0"
27
28
  end
@@ -29,6 +29,9 @@ module Devise
29
29
  def unsubscribe(email)
30
30
  # Logic for mailchimp unsubscription.
31
31
  api.lists(@campaignable_list_id).members(subscriber_hash(email)).update(body: { status: "unsubscribed" })
32
+ rescue Gibbon::MailChimpError => e
33
+ raise unless e.status_code == 404
34
+ Rails.logger.warn "unsubscribe: User #{self.email} not found!"
32
35
  end
33
36
 
34
37
  # Subscribe all users as a batch.
@@ -20,11 +20,11 @@ module Devise
20
20
  # Add the callbacks to the user model.
21
21
  included do
22
22
  # Callback to subscribe the user whenever the record is created
23
- after_create :subscribe
23
+ after_create :subscribe, if: :campaignable_user?
24
24
  # Callback to see if the subscription for this users needs updating.
25
- after_update :update_subscription
25
+ after_update :update_subscription, if: :campaignable_user?
26
26
  # Callback to unsubscribe the user when they are destroyed.
27
- after_destroy :unsubscribe
27
+ after_destroy :unsubscribe, if: :campaignable_user?
28
28
  end
29
29
 
30
30
  # Method to subscibe the user to the configrued mailing list.
@@ -45,6 +45,11 @@ module Devise
45
45
  # Ask the list manager to unsubscribe this devise models email.
46
46
  self.class.list_manager.unsubscribe(self.email)
47
47
  end
48
+
49
+ # Returns true if it's a valid email for subscribing
50
+ def self.valid_campaign_email?(email)
51
+ email.present? && /\@example\.(com|net|org|edu)$/ !~ email
52
+ end
48
53
 
49
54
  private
50
55
 
@@ -62,6 +67,10 @@ module Devise
62
67
  # Compact to the hash to remove any empty data.
63
68
  additional_fields.compact
64
69
  end
70
+
71
+ def campaignable_user?
72
+ Campaignable.valid_campaign_email? self.email
73
+ end
65
74
 
66
75
  module ClassMethods
67
76
 
@@ -83,7 +92,7 @@ module Devise
83
92
  # Subscribe all users as a batch.
84
93
  def subscribe_all
85
94
  # Get an array of all the email addresses accociated with this devise class.
86
- emails = all.map(&:email)
95
+ emails = all.map(&:email).select {|e| Devise::Models::Campaignable.valid_campaign_email? e}
87
96
 
88
97
  # Ask the list managed to subscibe all of these emails.
89
98
  list_manager.batch_subscribe(emails)
@@ -92,12 +101,12 @@ module Devise
92
101
  # Unsubscribe all users as a batch.
93
102
  def unsubscribe_all
94
103
  # Get an array of all the email addresses accociated with this devise class.
95
- emails = all.map(&:email)
104
+ emails = all.map(&:email).select {|e| Devise::Models::Campaignable.valid_campaign_email? e}
96
105
 
97
106
  # Ask the list managed to subscibe all of these emails.
98
107
  list_manager.batch_unsubscribe(emails)
99
108
  end
100
-
109
+
101
110
  # Set the configuration variables for the modeule.
102
111
  Devise::Models.config(self, :campaignable_api_key, :campaignable_list_id, :campaignable_vendor, :campaignable_additional_fields)
103
112
  end
@@ -1,3 +1,3 @@
1
1
  module DeviseCampaignable
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Rawlins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-06 00:00:00.000000000 Z
11
+ date: 2016-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: activemodel
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: devise
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -91,6 +105,7 @@ extra_rdoc_files: []
91
105
  files:
92
106
  - ".gitignore"
93
107
  - ".rspec"
108
+ - ".travis.yml"
94
109
  - Gemfile
95
110
  - LICENSE
96
111
  - README.md