From 5d3d0dd5503fb924eb12089327ea551f54720b02 Mon Sep 17 00:00:00 2001 From: Andrew Edwards Date: Sat, 31 Mar 2018 20:23:29 -0400 Subject: [PATCH] Added initializers for all models. --- README.md | 2 +- .../Models/AdvancedSuppressionManager.swift | 6 +++ Sources/SendGrid/Models/EmailAddress.swift | 10 ++++- Sources/SendGrid/Models/EmailAttachment.swift | 12 +++++ Sources/SendGrid/Models/MailSettings.swift | 42 ++++++++++++++++++ Sources/SendGrid/Models/Personalization.swift | 18 ++++++++ Sources/SendGrid/Models/SendGridEmail.swift | 36 +++++++++++++++ Sources/SendGrid/Models/SendGridError.swift | 4 +- .../SendGrid/Models/TrackingSettings.swift | 44 +++++++++++++++++++ 9 files changed, 169 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 363aec5..b13ef36 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,6 @@ do { try sendgridClient.send(...) } catch let error as SendGridError { - print(error.localizedDescription) + print(error) } ~~~~ diff --git a/Sources/SendGrid/Models/AdvancedSuppressionManager.swift b/Sources/SendGrid/Models/AdvancedSuppressionManager.swift index 5d6544f..ceed024 100644 --- a/Sources/SendGrid/Models/AdvancedSuppressionManager.swift +++ b/Sources/SendGrid/Models/AdvancedSuppressionManager.swift @@ -7,6 +7,12 @@ public struct AdvancedSuppressionManager: Content { /// An array containing the unsubscribe groups that you would like to be displayed on the unsubscribe preferences page. public var groupsToDisplay: [String]? + public init(groupId: Int? = nil, + groupsToDisplay: [String]? = nil) { + self.groupId = groupId + self.groupsToDisplay = groupsToDisplay + } + public enum CodingKeys: CodingKey, String { case groupId = "group_id" case groupsToDisplay = "groups_to_display" diff --git a/Sources/SendGrid/Models/EmailAddress.swift b/Sources/SendGrid/Models/EmailAddress.swift index bad93f1..d7a4ac9 100644 --- a/Sources/SendGrid/Models/EmailAddress.swift +++ b/Sources/SendGrid/Models/EmailAddress.swift @@ -9,8 +9,14 @@ import Vapor public struct EmailAddress: Content { /// format: email - var email: String? + public var email: String? /// The name of the person to whom you are sending an email. - var name: String? + public var name: String? + + public init(email: String? = nil, + name: String? = nil) { + self.email = email + self.name = name + } } diff --git a/Sources/SendGrid/Models/EmailAttachment.swift b/Sources/SendGrid/Models/EmailAttachment.swift index b0d7880..37b2f88 100644 --- a/Sources/SendGrid/Models/EmailAttachment.swift +++ b/Sources/SendGrid/Models/EmailAttachment.swift @@ -24,6 +24,18 @@ public struct EmailAttachment: Content { /// The content id for the attachment. This is used when the disposition is set to “inline” and the attachment is an image, allowing the file to be displayed within the body of your email. public var contentId: String? + public init(content: String? = nil, + type: String? = nil, + filename: String? = nil, + disposition: String? = nil, + contentId: String? = nil) { + self.content = content + self.type = type + self.filename = filename + self.disposition = disposition + self.contentId = contentId + } + public enum CodingKeys: CodingKey, String { case content case type diff --git a/Sources/SendGrid/Models/MailSettings.swift b/Sources/SendGrid/Models/MailSettings.swift index a821704..4c09acf 100644 --- a/Sources/SendGrid/Models/MailSettings.swift +++ b/Sources/SendGrid/Models/MailSettings.swift @@ -23,6 +23,18 @@ public struct MailSettings: Content { /// This allows you to test the content of your email for spam. public var spamCheck: SpamCheck? + public init(bcc: BCC? = nil, + bypassListManagement: BypassListManagement? = nil, + footer: Footer? = nil, + sandboxMode: SandboxMode? = nil, + spamCheck: SpamCheck? = nil) { + self.bcc = bcc + self.bypassListManagement = bypassListManagement + self.footer = footer + self.sandboxMode = sandboxMode + self.spamCheck = spamCheck + } + public enum CodingKeys: CodingKey, String { case bcc case bypassListManagement = "bypass_list_management" @@ -36,11 +48,21 @@ public struct BCC: Content { /// Indicates if this setting is enabled. public var enable: Bool? public var email: String? + + public init(enable: Bool? = nil, + email: String? = nil) { + self.enable = enable + self.email = email + } } public struct BypassListManagement: Content { /// Indicates if this setting is enabled. public var enable: Bool? + + public init(enable: Bool? = nil) { + self.enable = enable + } } public struct Footer: Content { @@ -52,11 +74,23 @@ public struct Footer: Content { /// The HTML content of your footer. public var html: String? + + public init(enable: Bool? = nil, + text: String? = nil, + html: String? = nil) { + self.enable = enable + self.text = text + self.html = html + } } public struct SandboxMode: Content { /// Indicates if this setting is enabled. public var enable: Bool? + + public init(enable: Bool? = nil) { + self.enable = enable + } } public struct SpamCheck: Content { @@ -69,6 +103,14 @@ public struct SpamCheck: Content { /// An Inbound Parse URL that you would like a copy of your email along with the spam report to be sent to. public var postToUrl: String? + public init(enable: Bool? = nil, + threshold: Int? = nil, + postToUrl: String? = nil) { + self.enable = enable + self.threshold = threshold + self.postToUrl = postToUrl + } + public enum CodingKeys: CodingKey, String { case enable case threshold diff --git a/Sources/SendGrid/Models/Personalization.swift b/Sources/SendGrid/Models/Personalization.swift index bbaa0e2..19eb3e0 100644 --- a/Sources/SendGrid/Models/Personalization.swift +++ b/Sources/SendGrid/Models/Personalization.swift @@ -26,6 +26,24 @@ public struct Personalization: Content { /// A unix timestamp allowing you to specify when you want your email to be delivered. 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, + 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.customArgs = customArgs + self.sendAt = sendAt + } + public enum CodingKeys: CodingKey, String { case to case cc diff --git a/Sources/SendGrid/Models/SendGridEmail.swift b/Sources/SendGrid/Models/SendGridEmail.swift index 85972d8..bffb369 100644 --- a/Sources/SendGrid/Models/SendGridEmail.swift +++ b/Sources/SendGrid/Models/SendGridEmail.swift @@ -51,6 +51,42 @@ public struct SendGridEmail: Content { /// Settings to determine how you would like to track the metrics of how your recipients interact with your email. public var trackingSettings: TrackingSettings? + public init(personalizations: [Personalization]? = nil, + from: EmailAddress? = nil, + replyTo: EmailAddress? = nil, + subject: String? = nil, + content: [String: String]? = nil, + attachments: [EmailAttachment]? = nil, + templateId: String? = nil, + sections: [String: String]? = nil, + headers: [String: String]? = nil, + categories: [String]? = nil, + customArgs: [String: String]? = nil, + sendAt: Date? = nil, + batchId: String? = nil, + asm: AdvancedSuppressionManager? = nil, + ipPoolName: String? = nil, + mailSettings: MailSettings? = nil, + trackingSettings: TrackingSettings? = nil) { + self.personalizations = personalizations + self.from = from + self.replyTo = replyTo + self.subject = subject + self.content = content + self.attachments = attachments + self.templateId = templateId + self.sections = sections + self.headers = headers + self.categories = categories + self.customArgs = customArgs + self.sendAt = sendAt + self.batchId = batchId + self.asm = asm + self.ipPoolName = ipPoolName + self.mailSettings = mailSettings + self.trackingSettings = trackingSettings + } + public enum CodingKeys: CodingKey, String { case personalizations case from diff --git a/Sources/SendGrid/Models/SendGridError.swift b/Sources/SendGrid/Models/SendGridError.swift index 43d0cfa..2701b91 100644 --- a/Sources/SendGrid/Models/SendGridError.swift +++ b/Sources/SendGrid/Models/SendGridError.swift @@ -1,10 +1,10 @@ import Vapor public struct SendGridError: Error, Content { - var errors: [SendGridErrorResponse] + var errors: [SendGridErrorResponse]? } public struct SendGridErrorResponse: Content { - public var message: String + public var message: String? public var field: String? public var help: String? } diff --git a/Sources/SendGrid/Models/TrackingSettings.swift b/Sources/SendGrid/Models/TrackingSettings.swift index 09477c7..6f6f502 100644 --- a/Sources/SendGrid/Models/TrackingSettings.swift +++ b/Sources/SendGrid/Models/TrackingSettings.swift @@ -20,6 +20,16 @@ public struct TrackingSettings: Content { /// Allows you to enable tracking provided by Google Analytics. public var ganalytics: GoogleAnalytics? + public init(clickTracking: ClickTracking? = nil, + openTracking: OpenTracking? = nil, + subscriptionTracking: SubscriptionTracking? = nil, + ganalytics: GoogleAnalytics? = nil) { + self.clickTracking = clickTracking + self.openTracking = openTracking + self.subscriptionTracking = subscriptionTracking + self.ganalytics = ganalytics + } + public enum CodingKeys: CodingKey, String { case clickTracking = "click_tracking" case openTracking = "open_tracking" @@ -35,6 +45,12 @@ public struct ClickTracking: Content { /// Indicates if this setting should be included in the text/plain portion of your email. public var enableText: Bool? + public init(enable: Bool? = nil, + enableText: Bool? = nil) { + self.enable = enable + self.enableText = enableText + } + public enum CodingKeys: CodingKey, String { case enable case enableText = "enable_text" @@ -48,6 +64,12 @@ public struct OpenTracking: Content { /// Allows you to specify a substitution tag that you can insert in the body of your email at a location that you desire. This tag will be replaced by the open tracking pixel. public var substitutionTag: String? + public init(enable: Bool? = nil, + substitutionTag: String? = nil) { + self.enable = enable + self.substitutionTag = substitutionTag + } + public enum CodingKeys: CodingKey, String { case enable case substitutionTag = "substitution_tag" @@ -67,6 +89,14 @@ public struct SubscriptionTracking: Content { /// A tag that will be replaced with the unsubscribe URL. for example: [unsubscribe_url]. If this parameter is used, it will override both the text and html parameters. The URL of the link will be placed at the substitution tag’s location, with no additional formatting. public var substitutionTag: String? + public init(enable: Bool? = nil, + text: String? = nil, + html: String? = nil) { + self.enable = enable + self.text = text + self.html = html + } + public enum CodingKeys: CodingKey, String { case enable case text @@ -94,6 +124,20 @@ public struct GoogleAnalytics: Content { /// The name of the campaign. public var utmCampaign: String? + public init(enable: Bool? = nil, + utmSource: String? = nil, + utmMedium: String? = nil, + utmTerm: String? = nil, + utmContent: String? = nil, + utmCampaign: String? = nil) { + self.enable = enable + self.utmSource = utmSource + self.utmMedium = utmMedium + self.utmTerm = utmTerm + self.utmContent = utmContent + self.utmCampaign = utmCampaign + } + public enum CodingKeys: CodingKey, String { case enable case utmSource = "utm_source"