Skip to content

Commit

Permalink
Merge pull request #19 from vapor-community/rc1.2
Browse files Browse the repository at this point in the history
Added initializers for all models.
  • Loading branch information
Andrewangeta committed Apr 1, 2018
2 parents 9a05b90 + 5d3d0dd commit 4547bcf
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -50,6 +50,6 @@ do {
try sendgridClient.send(...)
}
catch let error as SendGridError {
print(error.localizedDescription)
print(error)
}
~~~~
6 changes: 6 additions & 0 deletions Sources/SendGrid/Models/AdvancedSuppressionManager.swift
Expand Up @@ -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"
Expand Down
10 changes: 8 additions & 2 deletions Sources/SendGrid/Models/EmailAddress.swift
Expand Up @@ -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
}
}
12 changes: 12 additions & 0 deletions Sources/SendGrid/Models/EmailAttachment.swift
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions Sources/SendGrid/Models/MailSettings.swift
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions Sources/SendGrid/Models/Personalization.swift
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions Sources/SendGrid/Models/SendGridEmail.swift
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions 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?
}
44 changes: 44 additions & 0 deletions Sources/SendGrid/Models/TrackingSettings.swift
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 4547bcf

Please sign in to comment.