-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathPersonalization.swift
96 lines (84 loc) · 3.39 KB
/
Personalization.swift
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import Foundation
public struct Personalization<DynamicTemplateData: Codable & Sendable>: Codable, Sendable {
/// An array of recipients.
///
/// > Important: Each object within this array may contain the name, but must always contain the email, of a recipient.
public var to: [EmailAddress]?
/// An array of recipients who will receive a copy of your email.
///
/// > Important: Each object within this array may contain the name, but must always contain the email, of a recipient.
public var cc: [EmailAddress]?
/// An array of recipients who will receive a blind carbon copy of your email.
///
/// > Important: Each object within this array may contain the name, but must always contain the email, of a recipient.
public var bcc: [EmailAddress]?
/// The subject of your email.
public var subject: String?
/// A collection of JSON key/value pairs allowing you to specify specific handling instructions for your email.
public var headers: [String: String]?
/// A collection of key/value pairs following the pattern `"substitution_tag":"value to substitute"`.
public var substitutions: [String: String]?
/// A collection of key/value pairs following the pattern `"key":"value"` to substitute handlebar template data.
public var dynamicTemplateData: DynamicTemplateData?
/// Values that are specific to this personalization that will be carried along with the email and its activity data.
public var customArgs: [String: String]?
/// A UNIX timestamp allowing you to specify when you want your email to be delivered.
///
/// > Important: Scheduling more than 72 hours in advance is forbidden.
public var sendAt: Date?
public init(
to: [EmailAddress]? = nil,
cc: [EmailAddress]? = nil,
bcc: [EmailAddress]? = nil,
subject: String? = nil,
headers: [String: String]? = nil,
substitutions: [String: String]? = nil,
dynamicTemplateData: DynamicTemplateData? = nil,
customArgs: [String: String]? = nil,
sendAt: Date? = nil
) {
self.to = to
self.cc = cc
self.bcc = bcc
self.subject = subject
self.headers = headers
self.substitutions = substitutions
self.dynamicTemplateData = dynamicTemplateData
self.customArgs = customArgs
self.sendAt = sendAt
}
private enum CodingKeys: String, CodingKey {
case to
case cc
case bcc
case subject
case headers
case substitutions
case customArgs = "custom_args"
case dynamicTemplateData = "dynamic_template_data"
case sendAt = "send_at"
}
}
extension Personalization where DynamicTemplateData == [String: String] {
public init(
to: [EmailAddress]? = nil,
cc: [EmailAddress]? = nil,
bcc: [EmailAddress]? = nil,
subject: String? = nil,
headers: [String: String]? = nil,
substitutions: [String: String]? = nil,
dynamicTemplateData: [String: String]? = nil,
customArgs: [String: String]? = nil,
sendAt: Date? = nil
) {
self.to = to
self.cc = cc
self.bcc = bcc
self.subject = subject
self.headers = headers
self.substitutions = substitutions
self.dynamicTemplateData = dynamicTemplateData
self.customArgs = customArgs
self.sendAt = sendAt
}
}