devise_campaignable 0.2.2 → 0.2.3

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: 751ee1ed0076c925f82fc139434f15fa1009fa62
4
- data.tar.gz: db5d81fd9147d2433af34592eb97f6e1c7aa3f43
3
+ metadata.gz: b541e0a1dae4c14bde1a8a02ad5e461e1b2f6de2
4
+ data.tar.gz: 91813e958ac27a088fc7b24be4978e22785db627
5
5
  SHA512:
6
- metadata.gz: 6ece3bc3f9d0838d1773031451ca057490e1555db1493f0d80ac045e4ed89c3f56da4014b857e240ede1fe9408f289995e10c11c7212ab19dc75ac8e2eda467a
7
- data.tar.gz: 997614ebdc35e6f71e78116244210c1029fc9db83544d8e62b932f47c570f72c6b86c9001cfd00a01a52e06c70b525b2c4b528d528afb47fc4c472ee12514f24
6
+ metadata.gz: d232dec8510b38130393668ae4df4391b401cba9a3b3c124fc812558103f16ee520e4e79d41f5c11fe389204b00806cd3a7cc6ecca0df3714883fb6b2915dab5
7
+ data.tar.gz: 712b10cc75b1cde529ffa78cadbac9a6af6d7c7fcacbbf4bd12c16e57b4d212849d6e7bc0f9e4295004581630de00f6fef0c0e3d4e847389b615acf7c3e61f25
data/README.md CHANGED
@@ -43,7 +43,9 @@ The unique ID of the list to which you want your users to be subscribed. Again,
43
43
 
44
44
  #### config.campaignable_additional_fields (optional)
45
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.
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
+
48
+ **MailChimp Users: You need to have added merge fields with matching names to your MailChimp list before this will work, the merge fields should match the attribute on your user model, capitalized. i.e. an attribute such as 'name' should have a merge field on the list of 'NAME'.**
47
49
 
48
50
  ## Model Configuration
49
51
 
@@ -10,7 +10,7 @@ module Devise
10
10
  api.lists(@campaignable_list_id).members(subscriber_hash(email)).upsert(body: {
11
11
  :email_address => email,
12
12
  :status => "subscribed",
13
- :merge_fields => merge_vars # Include additional variables to be stored.
13
+ :merge_fields => prep_merge_fields(merge_vars) # Include additional variables to be stored.
14
14
  })
15
15
  end
16
16
 
@@ -20,7 +20,7 @@ module Devise
20
20
  api.lists(@campaignable_list_id).members(subscriber_hash(old_email)).update(body: {
21
21
  :email_address => new_email,
22
22
  :status => "subscribed",
23
- :merge_fields => merge_vars # Include additional variables to be stored.
23
+ :merge_fields => prep_merge_fields(merge_vars) # Include additional variables to be stored.
24
24
  })
25
25
  end
26
26
 
@@ -30,8 +30,10 @@ module Devise
30
30
  # Logic for mailchimp unsubscription.
31
31
  api.lists(@campaignable_list_id).members(subscriber_hash(email)).update(body: { status: "unsubscribed" })
32
32
  rescue Gibbon::MailChimpError => e
33
- raise unless e.status_code == 404
34
- Rails.logger.warn "unsubscribe: User #{email} not found!"
33
+ # Reraise any non 404 errors.
34
+ raise unless e.status_code == 404
35
+ # Log rails errors into the rails logger.
36
+ Rails.logger.warn "unsubscribe: User #{email} not found!"
35
37
  end
36
38
 
37
39
  # Subscribe all users as a batch.
@@ -79,6 +81,12 @@ module Devise
79
81
 
80
82
  private
81
83
 
84
+ # Prepare the merge fields to be sent to MailChimp.
85
+ def prep_merge_fields(merge_fields)
86
+ # Upper-case all the keys as this is how MC expect them.
87
+ merge_fields.map { |k, v| [k.upcase, v] }.to_h
88
+ end
89
+
82
90
  # Convert the members email into a hash
83
91
  # to be sent to mailchimp as part of the update calls.
84
92
  def subscriber_hash(email)
@@ -48,6 +48,7 @@ module Devise
48
48
 
49
49
  # Returns true if it's a valid email for subscribing
50
50
  def self.valid_campaign_email?(email)
51
+ # Check that the email is present, and that it's not an example domain.
51
52
  email.present? && /\@example\.(com|net|org|edu)$/ !~ email
52
53
  end
53
54
 
@@ -69,6 +70,7 @@ module Devise
69
70
  end
70
71
 
71
72
  def campaignable_user?
73
+ # Check the email is valid, so callbacks not fired for example domains.
72
74
  Campaignable.valid_campaign_email? self.email
73
75
  end
74
76
 
@@ -1,3 +1,3 @@
1
1
  module DeviseCampaignable
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.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.2.2
4
+ version: 0.2.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: 2017-03-03 00:00:00.000000000 Z
11
+ date: 2017-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  version: '0'
155
155
  requirements: []
156
156
  rubyforge_project:
157
- rubygems_version: 2.2.2
157
+ rubygems_version: 2.6.10
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: A multi-vendor mailing list extension for Devise. Have your users automatically