From ae0e7f13a31b4a1472bb90a8b4c13167b310b5ba Mon Sep 17 00:00:00 2001 From: Francesco Paolo Severino Date: Sat, 7 Sep 2024 22:33:11 +0200 Subject: [PATCH 1/2] Fix errors --- .github/CODEOWNERS | 1 + Sources/SendGridKit/SendGridClient.swift | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..37a58a4 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @Andrewangeta @fpseverino \ No newline at end of file diff --git a/Sources/SendGridKit/SendGridClient.swift b/Sources/SendGridKit/SendGridClient.swift index 9dd1a2d..53b1e7a 100644 --- a/Sources/SendGridKit/SendGridClient.swift +++ b/Sources/SendGridKit/SendGridClient.swift @@ -1,7 +1,8 @@ -import Foundation +@preconcurrency import Foundation import NIO import AsyncHTTPClient import NIOHTTP1 +import NIOFoundationCompat public struct SendGridClient: Sendable { let apiURL = "https://api.sendgrid.com/v3/mail/send" From c21a8903876bfaa77e5a6431cf45b60bf26b0ec2 Mon Sep 17 00:00:00 2001 From: Francesco Paolo Severino Date: Sat, 7 Sep 2024 22:43:51 +0200 Subject: [PATCH 2/2] Add test coverage --- Tests/SendGridKitTests/SendGridTestsKit.swift | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Tests/SendGridKitTests/SendGridTestsKit.swift b/Tests/SendGridKitTests/SendGridTestsKit.swift index c65ec2e..1f9c17f 100644 --- a/Tests/SendGridKitTests/SendGridTestsKit.swift +++ b/Tests/SendGridKitTests/SendGridTestsKit.swift @@ -18,12 +18,27 @@ class SendGridKitTests: XCTestCase { func testSendEmail() async throws { // TODO: Replace to address with the email address you'd like to recieve your test email - let emailAddress = EmailAddress(email: "TO-ADDRESS", name: "Test User") + let emailAddress = EmailAddress("TO-ADDRESS") // TODO: Replace from address with the email address associated with your verified Sender Identity let fromEmailAddress = EmailAddress(email: "FROM-ADDRESS", name: "Test") + let personalization = Personalization(to: [emailAddress], subject: "Test Email") - let emailContent = EmailContent(type: "text/plain", value: "This email was sent using SendGridKit!") - let email = SendGridEmail(personalizations: [personalization], from: fromEmailAddress, content: [emailContent]) + + let attachment = EmailAttachment( + content: "Hello, World!".data(using: .utf8)!.base64EncodedString(), + type: "text/plain", + filename: "hello.txt", + disposition: "attachment" + ) + + let emailContent = EmailContent("This email was sent using SendGridKit!") + + let email = SendGridEmail( + personalizations: [personalization], + from: fromEmailAddress, + content: [emailContent], + attachments: [attachment] + ) do { try await client.send(email: email)