heya 0.6.1 → 0.7.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
  SHA256:
3
- metadata.gz: cc54010af38a9f2e0e58358f998ad7b81480955416bac5ae1a18c9b5dfdfecd3
4
- data.tar.gz: ef7dbf811f3fec3c2e10e1d569f82aed0ae3309291f21a196c3dd43d28e7bf8e
3
+ metadata.gz: 897c67c77ab4b26f47d21ddde192e5957239cdb319c662fd72dd806de3c552d2
4
+ data.tar.gz: e34438a886e4c1598b0bca34bab406b84b83561310857f2c8730c669961e5a9a
5
5
  SHA512:
6
- metadata.gz: 76e3d5d214c06a53cd03c388682e5c22984c874f56e73c1ebf321b08f011fd513f2402fa4e05d6abea9fe7e705f0d1330645e38de86a541210431370ec2ec71a
7
- data.tar.gz: ac526b113dc81c207e7a26783b7ae63db6ccba85a2588906277eb7eaeda627930037fd195dd23c110b753fe961723b885f19d03f4f0f5a203031d18638ec53a3
6
+ metadata.gz: 6efc0529915073f5e3e2abb9a878e1f2e290cf66b66913989555325ac29f508988378e48637efaa36a345f3bc6ebd6978c110879c52d1999cea7bb3ec35e67a4
7
+ data.tar.gz: 02e88ebd7dea87ba644b380be61ffc41788c24045f8e103df302e44b1a8f82a37850ed56beb12b763b183061abf2526a5cd2affb6a175e155f7096d22a8dde7d
data/CHANGELOG.md CHANGED
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.7.0] - 2022-02-03
10
+ ### Fixed
11
+ - Automatically include Rails url helpers from application in campaign mailer templates (#158, @feliperaul)
12
+
13
+ ### Added
14
+ - Allow the customization of the to field (#155, @feliperaul)
15
+
9
16
  ## [0.6.1] - 2022-01-05
10
17
  ### Fixed
11
18
  - Support Rails 7 (#151, @800a7b32)
data/README.md CHANGED
@@ -247,10 +247,11 @@ The `wait` option tells Heya how long to wait before sending each message (the d
247
247
  Heya uses the following additional options to build the message itself:
248
248
 
249
249
  | Option Name | Default | Description |
250
- | :---------- | :----------- | :------------------------- |
250
+ |-------------|--------------|----------------------------|
251
251
  | `subject` | **required** | The email's subject |
252
252
  | `from` | Heya default | The sender's email address |
253
253
  | `layout` | Heya default | The email's layout file |
254
+ | `to` | See below | See below |
254
255
 
255
256
  You can change the default options using the `default` method at the top of the campaign. Heya applies default options to each step which doesn't supply its own:
256
257
 
@@ -268,6 +269,27 @@ class OnboardingCampaign < ApplicationCampaign
268
269
  end
269
270
  ```
270
271
 
272
+ #### Customizing the `to` field
273
+
274
+ You can customize the `to` field by passing a callable object, which Heya will invoke with the user. For instance:
275
+
276
+ ```ruby
277
+ class OnboardingCampaign < ApplicationCampaign
278
+ step :welcome,
279
+ subject: "Welcome to my app!",
280
+ to: -> (user) { ActionMailer::Base.email_address_with_name(user.email, user.nickname) }
281
+ end
282
+ ```
283
+
284
+ It is recommended to rely on `ActionMailer::Base.email_address_with_name` so that sanitization is correctly applied.
285
+
286
+ If the `to` param is not provided, Heya will default to:
287
+
288
+ 1. `user#first_name`
289
+ 1. `user#name`
290
+
291
+ If the `user` object doesn't respond to these methods, it will fallback to a simple `user.email` in the `to` field.
292
+
271
293
  #### Quality control option
272
294
 
273
295
  You may wish to apply quality control to individual steps of a campaign. For example, when adding a new step to an existing campaign it is
@@ -2,6 +2,7 @@ module Heya
2
2
  class CampaignMailer < ApplicationMailer
3
3
  DEFAULT_LAYOUT = "heya/campaign_mailer"
4
4
  layout -> { params.fetch(:step).params.fetch("layout", DEFAULT_LAYOUT) }
5
+ include Rails.application.routes.url_helpers
5
6
 
6
7
  def build
7
8
  user = params.fetch(:user)
@@ -26,7 +27,7 @@ module Heya
26
27
  from: from,
27
28
  bcc: bcc,
28
29
  reply_to: reply_to,
29
- to: user.email,
30
+ to: to_address(user, step),
30
31
  subject: subject,
31
32
  template_path: "heya/campaign_mailer/#{campaign_name}",
32
33
  template_name: step_name
@@ -52,5 +53,27 @@ module Heya
52
53
  end
53
54
  end
54
55
  end
56
+
57
+ def to_address(user, step)
58
+ return step.params["to"].call(user) if step.params["to"].respond_to?(:call)
59
+
60
+ if user.respond_to?(:first_name)
61
+ self.class.email_address_with_name(user.email, user.first_name)
62
+ elsif user.respond_to?(:name)
63
+ self.class.email_address_with_name(user.email, user.name)
64
+ else
65
+ user.email
66
+ end
67
+ end
68
+
69
+ # This method is a backport and can be removed when we drop support of
70
+ # Rails 6.0; As of Rails 6.1, ActionMailer::Base, which we inherit from,
71
+ # already includes it.
72
+ def self.email_address_with_name(address, name)
73
+ Mail::Address.new.tap do |builder|
74
+ builder.address = address
75
+ builder.display_name = name
76
+ end.to_s
77
+ end
55
78
  end
56
79
  end
@@ -4,7 +4,7 @@ module Heya
4
4
  module Campaigns
5
5
  module Actions
6
6
  class Email < Action
7
- VALID_PARAMS = %w[subject from reply_to bcc layout]
7
+ VALID_PARAMS = %w[subject from reply_to bcc layout to]
8
8
 
9
9
  def self.validate_step(step)
10
10
  step.params.assert_valid_keys(VALID_PARAMS)
data/lib/heya/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Heya
4
- VERSION = "0.6.1"
4
+ VERSION = "0.7.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heya
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Wood
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-05 00:00:00.000000000 Z
11
+ date: 2022-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0'
133
133
  requirements: []
134
- rubygems_version: 3.2.22
134
+ rubygems_version: 3.3.3
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: "Heya \U0001F44B"