ahoy_email 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +24 -0
- data/app/controllers/ahoy/messages_controller.rb +13 -0
- data/lib/ahoy_email.rb +5 -2
- data/lib/ahoy_email/processor.rb +3 -1
- data/lib/ahoy_email/version.rb +1 -1
- data/lib/generators/ahoy_email/templates/install.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d7461d3588d651ab3d225a8a599d9d09fb04cec
|
4
|
+
data.tar.gz: d39ee0ffe62f926206113aa73fd3afe622fd535d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1fb90d1b9f2615095e6ece4c9228ca7ea37092844861aef591b45abea856885ba8a1304ab657b2fc8b5479ffa74f72fe9f94861a05d06e11b0c8c930fd7666b6
|
7
|
+
data.tar.gz: c34afcb5fff0ff0054e9c62b30a884f735b0aef4e7ce3aa7150c3d80469ff1bc5cb673de1e5c2c9a975ecb629b6448685c84115f7e000a1d47832fe41d5671cf
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -142,6 +142,30 @@ end
|
|
142
142
|
AhoyEmail.track open: false
|
143
143
|
```
|
144
144
|
|
145
|
+
## Events
|
146
|
+
|
147
|
+
Subscribe to open and click events. Create an initializer `config/initializers/ahoy_email.rb` with:
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
class EmailSubscriber
|
151
|
+
|
152
|
+
def open(event)
|
153
|
+
# :message and :controller keys
|
154
|
+
ahoy = event[:controller].ahoy
|
155
|
+
ahoy.track "Email opened", message_id: event[:message].id
|
156
|
+
end
|
157
|
+
|
158
|
+
def click(event)
|
159
|
+
# same keys as above, plus :url
|
160
|
+
ahoy = event[:controller].ahoy
|
161
|
+
ahoy.track "Email clicked", message_id: event[:message].id, url: event[:url]
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
|
166
|
+
AhoyEmail.subscribers << EmailSubscriber.new
|
167
|
+
```
|
168
|
+
|
145
169
|
## Reference
|
146
170
|
|
147
171
|
You can use a `Proc` for any option.
|
@@ -7,16 +7,19 @@ module Ahoy
|
|
7
7
|
@message.opened_at = Time.now
|
8
8
|
@message.save!
|
9
9
|
end
|
10
|
+
publish :open
|
10
11
|
send_data Base64.decode64("R0lGODlhAQABAPAAAAAAAAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="), type: "image/gif", disposition: "inline"
|
11
12
|
end
|
12
13
|
|
13
14
|
def click
|
14
15
|
if @message and !@message.clicked_at
|
15
16
|
@message.clicked_at = Time.now
|
17
|
+
@message.opened_at ||= @message.clicked_at
|
16
18
|
@message.save!
|
17
19
|
end
|
18
20
|
url = params[:url]
|
19
21
|
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha1"), AhoyEmail.secret_token, url)
|
22
|
+
publish :click, url: params[:url]
|
20
23
|
if secure_compare(params[:signature], signature)
|
21
24
|
redirect_to url
|
22
25
|
else
|
@@ -30,6 +33,16 @@ module Ahoy
|
|
30
33
|
@message = AhoyEmail.message_model.where(token: params[:id]).first
|
31
34
|
end
|
32
35
|
|
36
|
+
def publish(name, event = {})
|
37
|
+
AhoyEmail.subscribers.each do |subscriber|
|
38
|
+
if subscriber.respond_to?(name)
|
39
|
+
event[:message] = @message
|
40
|
+
event[:controller] = self
|
41
|
+
subscriber.send name, event
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
33
46
|
# from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/message_verifier.rb
|
34
47
|
# constant-time comparison algorithm to prevent timing attacks
|
35
48
|
def secure_compare(a, b)
|
data/lib/ahoy_email.rb
CHANGED
@@ -9,7 +9,7 @@ require "ahoy_email/mailer"
|
|
9
9
|
require "ahoy_email/engine"
|
10
10
|
|
11
11
|
module AhoyEmail
|
12
|
-
mattr_accessor :secret_token, :options
|
12
|
+
mattr_accessor :secret_token, :options, :subscribers
|
13
13
|
|
14
14
|
self.options = {
|
15
15
|
message: true,
|
@@ -21,9 +21,12 @@ module AhoyEmail
|
|
21
21
|
utm_term: nil,
|
22
22
|
utm_content: nil,
|
23
23
|
utm_campaign: proc {|message, mailer| mailer.action_name },
|
24
|
-
user: proc{|message, mailer| User.where(email: message.to.first).first rescue nil }
|
24
|
+
user: proc{|message, mailer| (message.to.size == 1 ? User.where(email: message.to.first).first : nil) rescue nil },
|
25
|
+
mailer: proc{|message, mailer| "#{mailer.class.name}##{mailer.action_name}" }
|
25
26
|
}
|
26
27
|
|
28
|
+
self.subscribers = []
|
29
|
+
|
27
30
|
def self.track(options)
|
28
31
|
self.options = self.options.merge(options)
|
29
32
|
end
|
data/lib/ahoy_email/processor.rb
CHANGED
@@ -13,14 +13,16 @@ module AhoyEmail
|
|
13
13
|
if options[:message]
|
14
14
|
@ahoy_message = AhoyEmail.message_model.new
|
15
15
|
ahoy_message.token = generate_token
|
16
|
+
ahoy_message.to = message.to.join(", ") if ahoy_message.respond_to?(:to=)
|
16
17
|
ahoy_message.user = options[:user]
|
17
18
|
|
18
19
|
track_open if options[:open]
|
19
20
|
track_links if options[:utm_params] or options[:click]
|
20
21
|
|
21
|
-
|
22
|
+
ahoy_message.mailer = options[:mailer] if ahoy_message.respond_to?(:mailer=)
|
22
23
|
ahoy_message.subject = message.subject if ahoy_message.respond_to?(:subject=)
|
23
24
|
ahoy_message.content = message.to_s if ahoy_message.respond_to?(:content=)
|
25
|
+
|
24
26
|
ahoy_message.save
|
25
27
|
message["Ahoy-Message-Id"] = ahoy_message.id
|
26
28
|
end
|
data/lib/ahoy_email/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ahoy_email
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|