devise_campaignable 0.0.5 → 0.1.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
  SHA1:
3
- metadata.gz: 37e2f0f36b37d7f41f3a02e7ab940b1ac752c493
4
- data.tar.gz: 1cbef6baab371c3a9fce5f68f4fdaf15dad45eb5
3
+ metadata.gz: d49a6804ef7659a0234f0ae7b2c9eaa1f5411cb9
4
+ data.tar.gz: 71eba1a480d64f4cce9ee93ca3ddbce609c3e696
5
5
  SHA512:
6
- metadata.gz: b654b4e9b1df6b574d28d40471eadc161e660b1d3e779b98f6976868c8e0208d5b020c80900354471ee49e51af67d72c07f49f4759fc7ccc3887e03e06027f7b
7
- data.tar.gz: d3345a32fe22e62bb2b49c81fabde912a0b16b6226a2d08ecef8d7e716110a999c4658275d9751b40d82e18ed586410fdc9806f84ba28c843c54ffcb25b27465
6
+ metadata.gz: 7d1aa9bed23eba753db194a591a908e3c9a38aec87e85cf202b5b1a047ab038e92ad8f8aa8e3b9eee8b911dbda5992ba64106afb01a8a08f63ffbc590825771f
7
+ data.tar.gz: 5556fbae3e90a96cf9ee57e190f3294d7aecc9f5925936010810f9ef086df5574bc615338d46eeedc7bc86bde04ed575d3c3df278d01a8433b4c5909c6793228
data/README.md CHANGED
@@ -14,7 +14,6 @@ Simply add DeviseCampaignable and Gibbon to your application's Gemfile:
14
14
 
15
15
  gem 'devise'
16
16
  gem 'devise_campaignable'
17
- gem 'gibbon'
18
17
 
19
18
  ## Devise Configuration
20
19
 
@@ -26,6 +25,7 @@ Devise.setup do |config|
26
25
  config.campaignable_vendor = :vendor_name
27
26
  config.campaignable_api_key = 'your_service_api_key'
28
27
  config.campaignable_list_id = 'the_id_of_the_list_to_which_we_subscribe'
28
+ config.campaignable_additional_fields = [:array, :of, :additional, :fields]
29
29
  end
30
30
  ```
31
31
 
@@ -41,6 +41,10 @@ A API key for your chosen vendor. How you aqcuire this will depend from vendor t
41
41
 
42
42
  The unique ID of the list to which you want your users to be subscribed. Again, how you get this will vary from vendor to vendor.
43
43
 
44
+ #### config.campaignable_additional_fields (optional)
45
+
46
+ An array of symbols which denote attributes on the model you want sent to the campaign vendor. Can be things like Name, Age, Address. Defaults to no additional fields.
47
+
44
48
  ## Model Configuration
45
49
 
46
50
  Add :campaignable to the **devise** call in your model (we’re assuming here you already have a User model with some Devise modules):
@@ -34,11 +34,20 @@ module Devise
34
34
  # account tab in your MailChimp account and select API Keys & Authorized Apps, then add
35
35
  # a key. This defaults to 'your_api_key'
36
36
  #
37
- # Set subsribable_api_key in the Devise configuration file (config/initializers/devise.rb)
37
+ # Set campaignable_api_key in the Devise configuration file (config/initializers/devise.rb)
38
38
  #
39
- # Devise.subsribable_api_key = "your_api_key"
39
+ # Devise.campaignable_api_key = "your_api_key"
40
40
  mattr_accessor :campaignable_api_key
41
41
  @@campaignable_api_key = 'your_api_key'
42
+
43
+ # Public: The names of additional columns on your user model you want passed along to
44
+ # the campaign service provider, this may be things like names, address, plan etc.
45
+ #
46
+ # Set campaignable_additional_fields in the Devise configuration file (config/initializers/devise.rb)
47
+ #
48
+ # Devise.campaignable_additional_fields = [:first_name, :last_name, :favourite_colour]
49
+ mattr_accessor :campaignable_additional_fields
50
+ @@campaignable_additional_fields = []
42
51
  end
43
52
 
44
53
  Devise.add_module :campaignable, :model => 'devise_campaignable/model'
@@ -15,7 +15,7 @@ module Devise
15
15
  # in the parent class but not on the base adapter.
16
16
  #
17
17
  # Accepts single email address to subscribe.
18
- def subscribe(email)
18
+ def subscribe(email, merge_vars={})
19
19
  # Raise an error to warn it isn't implemented.
20
20
  raise NotImplementedError.new
21
21
  end
@@ -24,7 +24,7 @@ module Devise
24
24
  # in the parent class but not on the base adapter.
25
25
  #
26
26
  # Update an existing subscription.
27
- def update_subscription(old_email, new_email)
27
+ def update_subscription(old_email, new_email, merge_vars={})
28
28
  # Raise an error to warn it isn't implemented.
29
29
  raise NotImplementedError.new
30
30
  end
@@ -5,7 +5,7 @@ module Devise
5
5
  class Mailchimp < Adapter
6
6
 
7
7
  # Subscribe an email to the instantiated list.
8
- def subscribe(email)
8
+ def subscribe(email, merge_vars={})
9
9
  # Logic for mailchimp subcription.
10
10
  api.subscribe({
11
11
  :id => @campaignable_list_id,
@@ -14,21 +14,23 @@ module Devise
14
14
  },
15
15
  :double_optin => false, # Don't require email authorization.
16
16
  :update_existing => true, # Don't error if adding existing subscriber.
17
- :send_welcome => false # Don't send a welcome email when they're added to the list.
17
+ :send_welcome => false, # Don't send a welcome email when they're added to the list.
18
+ :merge_vars => merge_vars # Include additional variables to be stored.
18
19
  })
19
20
  end
20
21
 
21
22
  # Update an existing subscription.
22
- def update_subscription(old_email, new_email)
23
+ def update_subscription(old_email, new_email, merge_vars={})
24
+ # Append the new email address into the merge vars.
25
+ merge_vars[:new_email] = new_email
26
+
23
27
  # Mailchimp have a handy helper for updating an existing subscription.
24
28
  api.update_member({
25
29
  :id => @campaignable_list_id,
26
30
  :email => {
27
31
  :email => old_email
28
32
  },
29
- :merge_vars => {
30
- :'new-email' => new_email
31
- }
33
+ :merge_vars => merge_vars # Include additional variables to be stored, including new email
32
34
  })
33
35
  end
34
36
 
@@ -30,14 +30,14 @@ module Devise
30
30
  # Method to subscibe the user to the configrued mailing list.
31
31
  def subscribe
32
32
  # Ask the list manager to subscribe this devise models email.
33
- self.class.list_manager.subscribe(self.email)
33
+ self.class.list_manager.subscribe(self.email, campaignable_additional_fields)
34
34
  end
35
35
 
36
36
  # Method to update the subscription
37
37
  def update_subscription
38
38
  # Only change the subscription if the models email
39
39
  # address has been changed.
40
- self.class.list_manager.update_subscription(self.email_was, self.email) if self.email_changed?
40
+ self.class.list_manager.update_subscription(self.email_was, self.email, campaignable_additional_fields) if self.email_changed?
41
41
  end
42
42
 
43
43
  # Method to unsubscribe the user from the configured mailing list.
@@ -46,6 +46,23 @@ module Devise
46
46
  self.class.list_manager.unsubscribe(self.email)
47
47
  end
48
48
 
49
+ private
50
+
51
+ # Get a hash of the additional fields.
52
+ def campaignable_additional_fields
53
+ # Create an empty hash to store the fields.
54
+ additional_fields = {}
55
+
56
+ # Loop over the additional fields configured.
57
+ self.class.campaignable_additional_fields.each do |field_name|
58
+ # Create a new additional field using the key/value.
59
+ additional_fields[field_name] = self.send(field_name)
60
+ end
61
+
62
+ # Compact to the hash to remove any empty data.
63
+ additional_fields.compact
64
+ end
65
+
49
66
  module ClassMethods
50
67
 
51
68
  # Get the list subscriber library.
@@ -82,7 +99,7 @@ module Devise
82
99
  end
83
100
 
84
101
  # Set the configuration variables for the modeule.
85
- Devise::Models.config(self, :campaignable_api_key, :campaignable_list_id, :campaignable_vendor)
102
+ Devise::Models.config(self, :campaignable_api_key, :campaignable_list_id, :campaignable_vendor, :campaignable_additional_fields)
86
103
  end
87
104
  end
88
105
  end
@@ -1,3 +1,3 @@
1
1
  module DeviseCampaignable
2
- VERSION = "0.0.5"
2
+ VERSION = "0.1.0"
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.5
4
+ version: 0.1.0
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-07-06 00:00:00.000000000 Z
11
+ date: 2015-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler