ahoy_email 0.5.1 → 0.5.2

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
  SHA256:
3
- metadata.gz: bc1f584255e88dbcda182347224e0e30cbd43684cf5e9bf1ba71007cd8470d25
4
- data.tar.gz: 7143c167fa888441510b1eaa67edd74c0285efa50a1a4e6fa5b0b4770b7afcb7
3
+ metadata.gz: 1bd419ac1420c0d404b6137e3804545193969ecd8aab0444c919e9f7b5e5fae4
4
+ data.tar.gz: 3cce5d71d203a287992fc6560910f596f3cf74b0ef24861df8f5ed27ad9bd3b1
5
5
  SHA512:
6
- metadata.gz: 648078aac8c79119c4caa1ecd42ff624d58e5b898cf6eb2231d14fc0aaece937a2a76020931fbc8c22f730dcdfa27068fc1fc62f9b80ea30ef766c69ea8ddffc
7
- data.tar.gz: f529c4de18d3ffbd5b2ef4d4b2122409d521fca920d200eaad337c0bc984de31ef3b6d7c6c0642a7120446cf759055a9f84b0f9bdda44bdafb654708994cef4a
6
+ metadata.gz: b163a83c5a2f78e7a2576940f1d7d0bb25bb38fec0203571adf387ffa2e380c5ed164fff92ba12c00f81a30d7b43b39e41d7a68a1d94b86f2dfc27c48139eb16
7
+ data.tar.gz: 816a961760e8fedf55efa9b5b59f38decdf0fdd12531dc5a52f83c09178bddf820e93eb375c47100e10bd4e9f2aba7b4c2efabde952ebfc589cf20d2d0418537
@@ -1,3 +1,8 @@
1
+ ## 0.5.2
2
+
3
+ - Fixed secret token for Rails 5.2
4
+ - Added `heuristic_parse` option
5
+
1
6
  ## 0.5.1
2
7
 
3
8
  - Fixed deprecation warning in Rails 5.2
data/README.md CHANGED
@@ -99,13 +99,13 @@ Use `track open: false` to skip this.
99
99
  A redirect is added to links to track clicks in HTML emails.
100
100
 
101
101
  ```
102
- http://chartkick.com
102
+ https://chartkick.com
103
103
  ```
104
104
 
105
105
  becomes
106
106
 
107
107
  ```
108
- http://you.io/ahoy/messages/rAnDoMtOkEn/click?url=http%3A%2F%2Fchartkick.com&signature=...
108
+ https://yoursite.com/ahoy/messages/rAnDoMtOkEn/click?url=https%3A%2F%2Fchartkick.com&signature=...
109
109
  ```
110
110
 
111
111
  A signature is added to prevent [open redirects](https://www.owasp.org/index.php/Open_redirect).
@@ -251,7 +251,7 @@ track unsubscribe_links: true
251
251
  Use a different model
252
252
 
253
253
  ```ruby
254
- AhoyEmail.message_model = UserMessage
254
+ AhoyEmail.message_model = -> { UserMessage }
255
255
  ```
256
256
 
257
257
  ## Upgrading
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.required_ruby_version = ">= 2.0.0"
20
+ spec.required_ruby_version = ">= 2.2.0"
21
21
 
22
22
  spec.add_runtime_dependency "railties"
23
23
  spec.add_runtime_dependency "actionmailer"
@@ -17,14 +17,15 @@ module AhoyEmail
17
17
  open: true,
18
18
  click: true,
19
19
  utm_params: true,
20
- utm_source: proc { |message, mailer| mailer.mailer_name },
20
+ utm_source: ->(message, mailer) { mailer.mailer_name },
21
21
  utm_medium: "email",
22
22
  utm_term: nil,
23
23
  utm_content: nil,
24
- utm_campaign: proc { |message, mailer| mailer.action_name },
25
- user: proc { |message, mailer| (message.to.size == 1 ? User.where(email: message.to.first).first : nil) rescue nil },
26
- mailer: proc { |message, mailer| "#{mailer.class.name}##{mailer.action_name}" },
27
- url_options: {}
24
+ utm_campaign: ->(message, mailer) { mailer.action_name },
25
+ user: ->(message, mailer) { (message.to.size == 1 ? User.where(email: message.to.first).first : nil) rescue nil },
26
+ mailer: ->(message, mailer) { "#{mailer.class.name}##{mailer.action_name}" },
27
+ url_options: {},
28
+ heuristic_parse: false
28
29
  }
29
30
 
30
31
  self.subscribers = []
@@ -3,10 +3,17 @@ require "rails/engine"
3
3
  module AhoyEmail
4
4
  class Engine < ::Rails::Engine
5
5
  initializer "ahoy_email" do |app|
6
- # default to secrets to keep backward compatible
7
- ActiveSupport::Deprecation.silence do
8
- secrets = app.respond_to?(:secrets) ? app.secrets : app.config
9
- AhoyEmail.secret_token ||= secrets.respond_to?(:secret_key_base) ? secrets.secret_key_base : secrets.secret_token
6
+ AhoyEmail.secret_token ||= begin
7
+ creds =
8
+ if app.respond_to?(:credentials) && app.credentials.secret_key_base
9
+ app.credentials
10
+ elsif app.respond_to?(:secrets)
11
+ app.secrets
12
+ else
13
+ app.config
14
+ end
15
+
16
+ creds.respond_to?(:secret_key_base) ? creds.secret_key_base : creds.secret_token
10
17
  end
11
18
 
12
19
  AhoyEmail.belongs_to = {optional: true} if Rails::VERSION::MAJOR >= 5
@@ -2,7 +2,7 @@ module AhoyEmail
2
2
  module Mailer
3
3
  def self.included(base)
4
4
  base.extend ClassMethods
5
- base.send(:prepend, InstanceMethods)
5
+ base.prepend InstanceMethods
6
6
  base.class_eval do
7
7
  attr_accessor :ahoy_options
8
8
  class_attribute :ahoy_options
@@ -157,7 +157,11 @@ module AhoyEmail
157
157
  # Return uri if valid, nil otherwise
158
158
  def parse_uri(href)
159
159
  # to_s prevent to return nil from this method
160
- Addressable::URI.parse(href.to_s) rescue nil
160
+ if options[:heuristic_parse]
161
+ Addressable::URI.heuristic_parse(href.to_s) rescue nil
162
+ else
163
+ Addressable::URI.parse(href.to_s) rescue nil
164
+ end
161
165
  end
162
166
 
163
167
  def url_for(opt)
@@ -1,3 +1,3 @@
1
1
  module AhoyEmail
2
- VERSION = "0.5.1"
2
+ VERSION = "0.5.2"
3
3
  end
@@ -25,6 +25,31 @@ class UserMailer < ActionMailer::Base
25
25
  html_message('<a href="http://example.org?baz[]=1&amp;baz[]=2">Hi<a>')
26
26
  end
27
27
 
28
+ def heuristic_parse
29
+ track heuristic_parse: true
30
+ html_message('<a href="example.org">Hi<a>')
31
+ end
32
+
33
+ def mailto
34
+ track heuristic_parse: true
35
+ html_message('<a href="mailto:someone@yoursite.com">Email Us</a>')
36
+ end
37
+
38
+ def app_link
39
+ track heuristic_parse: true
40
+ html_message('<a href="fb://profile/33138223345">Email Us</a>')
41
+ end
42
+
43
+ def welcome4_heuristic
44
+ track heuristic_parse: true
45
+ html_message('<a href="http://example.org">Hi<a>')
46
+ end
47
+
48
+ def welcome5_heuristic
49
+ track heuristic_parse: true
50
+ html_message('<a href="http://example.org?baz[]=1&amp;baz[]=2">Hi<a>')
51
+ end
52
+
28
53
  private
29
54
 
30
55
  def prevent_delivery_to_guests
@@ -74,6 +99,43 @@ class MailerTest < Minitest::Test
74
99
  assert_match "baz%5B%5D=1&amp;baz%5B%5D=2", body
75
100
  end
76
101
 
102
+ def test_heuristic_parse
103
+ # Should convert the URI fragment into a URI
104
+ message = UserMailer.heuristic_parse
105
+ body = message.body.to_s
106
+ assert_match "http://example.org", body
107
+ end
108
+
109
+ def test_mailto
110
+ # heuristic parse should ignore the mailto link
111
+ message = UserMailer.mailto
112
+ body = message.body.to_s
113
+ assert_match "<a href=\"mailto:someone@yoursite.com\">", body
114
+ end
115
+
116
+ def test_app_link
117
+ # heuristic parse should ignore the app link
118
+ message = UserMailer.app_link
119
+ body = message.body.to_s
120
+ assert_match "<a href=\"fb://profile/33138223345\">", body
121
+ end
122
+
123
+ def test_utm_params_heuristic_parse
124
+ # heuristic parse should not have unexpected side effects
125
+ message = UserMailer.welcome4_heuristic
126
+ body = message.body.to_s
127
+ assert_match "utm_campaign=welcome4", body
128
+ assert_match "utm_medium=email", body
129
+ assert_match "utm_source=user_mailer", body
130
+ end
131
+
132
+ def test_array_params_heuristic_parse
133
+ # heuristic parse should not have unexpected side effects
134
+ message = UserMailer.welcome5_heuristic
135
+ body = message.body.to_s
136
+ assert_match "baz%5B%5D=1&amp;baz%5B%5D=2", body
137
+ end
138
+
77
139
  private
78
140
 
79
141
  def assert_message(method)
@@ -14,5 +14,3 @@ Combustion.initialize! :all do
14
14
  end
15
15
 
16
16
  ActionMailer::Base.delivery_method = :test
17
-
18
- ActiveRecord::Base.belongs_to_required_by_default = true if ActiveRecord::VERSION::MAJOR >= 5
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.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-20 00:00:00.000000000 Z
11
+ date: 2018-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -224,7 +224,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
224
224
  requirements:
225
225
  - - ">="
226
226
  - !ruby/object:Gem::Version
227
- version: 2.0.0
227
+ version: 2.2.0
228
228
  required_rubygems_version: !ruby/object:Gem::Requirement
229
229
  requirements:
230
230
  - - ">="