-
Notifications
You must be signed in to change notification settings - Fork 10
/
subscription_confirmation_email_builder.rb
72 lines (56 loc) · 1.43 KB
/
subscription_confirmation_email_builder.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class SubscriptionConfirmationEmailBuilder
include Callable
def initialize(subscription:)
@subscription = subscription
@subscriber = subscription.subscriber
@subscriber_list = subscription.subscriber_list
end
def call
Email.create!(
subject: subject,
body: body,
address: subscriber.address,
subscriber_id: subscriber.id,
)
end
private
attr_reader :subscription, :subscriber, :subscriber_list
def subject
"You’ve subscribed to: #{subscriber_list.title}"
end
def body
<<~BODY
# You’ve subscribed to GOV.UK emails
#{I18n.t!("emails.confirmation.frequency.#{subscription.frequency}")}
#{title_and_optional_url}
Thanks
GOV.UK emails
[Unsubscribe](#{unsubscribe_url})
[Change your email preferences](#{manage_url})
BODY
end
def title_and_optional_url
result = subscriber_list.title
source_url = SourceUrlPresenter.call(
subscriber_list.url,
utm_source: subscriber_list.slug,
utm_content: "confirmation",
)
result += "\n\n#{source_url}" if source_url
result
end
def unsubscribe_url
PublicUrls.unsubscribe(
subscription,
utm_source: subscriber_list.slug,
utm_content: subscription.frequency,
)
end
def manage_url
PublicUrls.manage_url(
subscriber,
utm_source: subscriber_list.slug,
utm_content: subscription.frequency,
)
end
end