devise_campaignable 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/devise_campaignable.gemspec +1 -1
- data/lib/devise_campaignable/adapters/mailchimp.rb +54 -44
- data/lib/devise_campaignable/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14a7a24f8cd973480789f970ba22350b78757432
|
4
|
+
data.tar.gz: ed115510d3be3239206b6aa0bb541fd31e6374c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3da5b3a6e930f9723e2a62ab4dbc45e67b8f4f16fd5460b6365a87d90d890f6785a8fbc3b9ff14973cf06bf113fdea38463a10b4776caa54d9e403710480f9f8
|
7
|
+
data.tar.gz: 70d51c5ba5f574011aebce55bfda71235e4e5cc42e7698f608c0d44d22a0f953eb04493c87376e96743b1e80bb264d699b22691bcaf4b077f32e006ab4503281
|
data/devise_campaignable.gemspec
CHANGED
@@ -7,30 +7,20 @@ module Devise
|
|
7
7
|
# Subscribe an email to the instantiated list.
|
8
8
|
def subscribe(email, merge_vars={})
|
9
9
|
# Logic for mailchimp subcription.
|
10
|
-
api.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
},
|
15
|
-
:double_optin => false, # Don't require email authorization.
|
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.
|
18
|
-
:merge_vars => merge_vars # Include additional variables to be stored.
|
10
|
+
api.lists(@campaignable_list_id).members(subscriber_hash(email)).upsert(body: {
|
11
|
+
:email_address => email,
|
12
|
+
:status => "subscribed",
|
13
|
+
:merge_fields => merge_vars # Include additional variables to be stored.
|
19
14
|
})
|
20
15
|
end
|
21
16
|
|
22
17
|
# Update an existing subscription.
|
23
18
|
def update_subscription(old_email, new_email, merge_vars={})
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
:id => @campaignable_list_id,
|
30
|
-
:email => {
|
31
|
-
:email => old_email
|
32
|
-
},
|
33
|
-
:merge_vars => merge_vars # Include additional variables to be stored, including new email
|
19
|
+
# Update the existing member details.
|
20
|
+
api.lists(@campaignable_list_id).members(subscriber_hash(old_email)).update(body: {
|
21
|
+
:email_address => new_email,
|
22
|
+
:status => "subscribed",
|
23
|
+
:merge_fields => merge_vars # Include additional variables to be stored.
|
34
24
|
})
|
35
25
|
end
|
36
26
|
|
@@ -38,46 +28,66 @@ module Devise
|
|
38
28
|
# This method is available for API Keys belonging to users with the following roles: manager, admin, owner
|
39
29
|
def unsubscribe(email)
|
40
30
|
# Logic for mailchimp unsubscription.
|
41
|
-
api.
|
42
|
-
|
43
|
-
:email => {
|
44
|
-
:email => email
|
45
|
-
},
|
46
|
-
:send_goodbye => false, # Don't send a goodbye email.
|
47
|
-
:send_notify => false # Don't notify the user of the unsubscription.
|
48
|
-
})
|
49
|
-
end
|
31
|
+
api.lists(@campaignable_list_id).members(subscriber_hash(email)).update(body: { status: "unsubscribed" })
|
32
|
+
end
|
50
33
|
|
51
34
|
# Subscribe all users as a batch.
|
52
35
|
def batch_subscribe(emails=[])
|
53
|
-
#
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
36
|
+
# Prepate the batch of subscribe operations to be called.
|
37
|
+
operations = []
|
38
|
+
|
39
|
+
# Create a upsert operations for each of the email addresses.
|
40
|
+
emails.each do |email|
|
41
|
+
# The operation is manually compiled as the Gibbon
|
42
|
+
# gem doesn't give us an easy way of doing this.
|
43
|
+
operations.append({
|
44
|
+
:method => "POST",
|
45
|
+
:path => "/lists/#{@campaignable_list_id}/members",
|
46
|
+
:body => {
|
47
|
+
:email_address => email,
|
48
|
+
:status => "subscribed"
|
49
|
+
}.to_json
|
50
|
+
})
|
51
|
+
end
|
52
|
+
|
53
|
+
# Make the request to process the batch of operations
|
54
|
+
api.batches.create(body: {:operations => operations})
|
61
55
|
end
|
62
56
|
|
63
57
|
# Unsubscribe all users as a batch.
|
64
58
|
def batch_unsubscribe(emails=[])
|
65
|
-
#
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
59
|
+
# Prepate the batch of subscribe operations to be called.
|
60
|
+
operations = []
|
61
|
+
|
62
|
+
# Create a upsert operations for each of the email addresses.
|
63
|
+
emails.each do |email|
|
64
|
+
# The operation is manually compiled as the Gibbon
|
65
|
+
# gem doesn't give us an easy way of doing this.
|
66
|
+
operations.append({
|
67
|
+
:method => "PATCH",
|
68
|
+
:path => "/lists/#{@campaignable_list_id}/members/#{subscriber_hash(email)}",
|
69
|
+
:body => { :status => "unsubscribed" }.to_json
|
70
|
+
})
|
71
|
+
end
|
72
|
+
|
73
|
+
# Make the request to process the batch of operations
|
74
|
+
api.batches.create(body: {:operations => operations})
|
72
75
|
end
|
73
76
|
|
74
77
|
private
|
75
78
|
|
79
|
+
# Convert the members email into a hash
|
80
|
+
# to be sent to mailchimp as part of the update calls.
|
81
|
+
def subscriber_hash(email)
|
82
|
+
# Simple hash of the email address.
|
83
|
+
Digest::MD5.hexdigest(email)
|
84
|
+
end
|
85
|
+
|
76
86
|
# Get an instance of the MailChimp API.
|
77
87
|
def api
|
78
88
|
# Instantiate an instance of Gibbon with the API key provided to this adapter.
|
79
89
|
# We only work with the lists api here, so namespace into that.
|
80
|
-
Gibbon::
|
90
|
+
Gibbon::Request.new(api_key: @campaignable_api_key)
|
81
91
|
end
|
82
92
|
|
83
93
|
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.
|
4
|
+
version: 0.2.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:
|
11
|
+
date: 2016-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -72,14 +72,14 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '2.0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '2.0'
|
83
83
|
description: Inspired by the now slightly out of date devise_mailchimp this gem works
|
84
84
|
in a similar fashion but with a focus on multi-vendor support, rather than exclusively
|
85
85
|
MailChimp.
|