Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for text property #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions Sources/Mailgun/Models/TemplateMessage.swift
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ public struct MailgunTemplateMessage: Content {
public let templateData: [String:String]?
public let templateVersion: String?
public let templateText: Bool?
public let text: String?
public let attachment: [File]?
public let inline: [File]?

@@ -31,6 +32,7 @@ public struct MailgunTemplateMessage: Content {
case templateData = "h:X-Mailgun-Variables"
case templateVersion = "t:version"
case templateText = "t:text"
case text
}

public func encode(to encoder: Encoder) throws {
@@ -48,13 +50,14 @@ public struct MailgunTemplateMessage: Content {
try container.encode(jsonString, forKey: .templateData)
}
try container.encode(templateVersion, forKey: .templateVersion)
let text = templateText == true ? "yes" : nil // need to send yes as string
try container.encode(text, forKey: .templateText)
let templateText = templateText == true ? "yes" : nil // need to send yes as string
try container.encode(templateText, forKey: .templateText)
try container.encode(attachment, forKey: .attachment)
try container.encode(inline, forKey: .inline)
try container.encode(text, forKey: .text)
}

public init(from: String, to: String, replyTo: String? = nil, cc: String? = nil, bcc: String? = nil, subject: String, template: String, templateData: [String:String]? = nil, templateVersion: String? = nil, templateText: Bool? = nil, attachments: [File]? = nil, inline: [File]? = nil) {
public init(from: String, to: String, replyTo: String? = nil, cc: String? = nil, bcc: String? = nil, subject: String, template: String, templateData: [String:String]? = nil, templateVersion: String? = nil, templateText: Bool? = nil, attachments: [File]? = nil, inline: [File]? = nil, text: String? = nil) {
self.from = from
self.to = to
self.replyTo = replyTo
@@ -67,9 +70,10 @@ public struct MailgunTemplateMessage: Content {
self.templateText = templateText
self.attachment = attachments
self.inline = inline
self.text = text
}

public init(from: String, to: [String], replyTo: String? = nil, cc: [String]? = nil, bcc: [String]? = nil, subject: String, template: String, templateData: [String:String]? = nil, templateVersion: String? = nil, templateText: Bool? = nil, attachments: [File]? = nil, inline: [File]? = nil) {
public init(from: String, to: [String], replyTo: String? = nil, cc: [String]? = nil, bcc: [String]? = nil, subject: String, template: String, templateData: [String:String]? = nil, templateVersion: String? = nil, templateText: Bool? = nil, attachments: [File]? = nil, inline: [File]? = nil, text: String? = nil) {
self.from = from
self.to = to.joined(separator: ",")
self.replyTo = replyTo
@@ -82,9 +86,10 @@ public struct MailgunTemplateMessage: Content {
self.templateText = templateText
self.attachment = attachments
self.inline = inline
self.text = text
}

public init(from: String, to: [FullEmail], replyTo: String? = nil, cc: [FullEmail]? = nil, bcc: [FullEmail]? = nil, subject: String, template: String, templateData: [String:String]? = nil, templateVersion: String? = nil, templateText: Bool? = nil, attachments: [File]? = nil, inline: [File]? = nil) {
public init(from: String, to: [FullEmail], replyTo: String? = nil, cc: [FullEmail]? = nil, bcc: [FullEmail]? = nil, subject: String, template: String, templateData: [String:String]? = nil, templateVersion: String? = nil, templateText: Bool? = nil, attachments: [File]? = nil, inline: [File]? = nil, text: String? = nil) {
self.from = from
self.to = to.stringArray.joined(separator: ",")
self.replyTo = replyTo
@@ -97,5 +102,6 @@ public struct MailgunTemplateMessage: Content {
self.templateText = templateText
self.attachment = attachments
self.inline = inline
self.text = text
}
}