Skip to content

Commit

Permalink
Final touches before new major release (#51)
Browse files Browse the repository at this point in the history
* Update to VaporTesting

* Small various changes

* Make `set` for stored client work
  • Loading branch information
fpseverino authored Feb 1, 2025
1 parent 1a24f07 commit b7cb492
Show file tree
Hide file tree
Showing 10 changed files with 115 additions and 61 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @fpseverino
3 changes: 1 addition & 2 deletions .spi.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
version: 1
builder:
configs:
- documentation_targets: [SendGrid]
swift_version: 6.0
- documentation_targets: [SendGrid]
70 changes: 70 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"fileScopedDeclarationPrivacy": {
"accessLevel": "private"
},
"indentation": {
"spaces": 4
},
"indentConditionalCompilationBlocks": true,
"indentSwitchCaseLabels": false,
"lineBreakAroundMultilineExpressionChainComponents": false,
"lineBreakBeforeControlFlowKeywords": false,
"lineBreakBeforeEachArgument": false,
"lineBreakBeforeEachGenericRequirement": false,
"lineLength": 140,
"maximumBlankLines": 1,
"multiElementCollectionTrailingCommas": true,
"noAssignmentInExpressions": {
"allowedFunctions": [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether": false,
"respectsExistingLineBreaks": true,
"rules": {
"AllPublicDeclarationsHaveDocumentation": false,
"AlwaysUseLiteralForEmptyCollectionInit": false,
"AlwaysUseLowerCamelCase": true,
"AmbiguousTrailingClosureOverload": true,
"BeginDocumentationCommentWithOneLineSummary": false,
"DoNotUseSemicolons": true,
"DontRepeatTypeInStaticProperties": true,
"FileScopedDeclarationPrivacy": true,
"FullyIndirectEnum": true,
"GroupNumericLiterals": true,
"IdentifiersMustBeASCII": true,
"NeverForceUnwrap": false,
"NeverUseForceTry": false,
"NeverUseImplicitlyUnwrappedOptionals": false,
"NoAccessLevelOnExtensionDeclaration": true,
"NoAssignmentInExpressions": true,
"NoBlockComments": true,
"NoCasesWithOnlyFallthrough": true,
"NoEmptyTrailingClosureParentheses": true,
"NoLabelsInCasePatterns": true,
"NoLeadingUnderscores": false,
"NoParensAroundConditions": true,
"NoPlaygroundLiterals": true,
"NoVoidReturnOnFunctionSignature": true,
"OmitExplicitReturns": false,
"OneCasePerLine": true,
"OneVariableDeclarationPerLine": true,
"OnlyOneTrailingClosureArgument": true,
"OrderedImports": true,
"ReplaceForEachWithForLoop": true,
"ReturnVoidInsteadOfEmptyTuple": true,
"TypeNamesShouldBeCapitalized": true,
"UseEarlyExits": false,
"UseExplicitNilCheckInConditions": true,
"UseLetInEveryBoundCaseVariable": true,
"UseShorthandTypeNames": true,
"UseSingleLinePropertyGetter": true,
"UseSynthesizedInitializer": true,
"UseTripleSlashForDocumentationComments": true,
"UseWhereClausesInForLoops": false,
"ValidateDocumentationComments": false
},
"spacesAroundRangeFormationOperators": false,
"tabWidth": 8,
"version": 1
}
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ let package = Package(
.library(name: "SendGrid", targets: ["SendGrid"])
],
dependencies: [
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
.package(url: "https://github.com/vapor-community/sendgrid-kit.git", from: "3.0.0-rc.1"),
.package(url: "https://github.com/vapor/vapor.git", from: "4.112.0"),
.package(url: "https://github.com/vapor-community/sendgrid-kit.git", from: "3.0.0"),
],
targets: [
.target(
Expand All @@ -26,7 +26,7 @@ let package = Package(
name: "SendGridTests",
dependencies: [
.target(name: "SendGrid"),
.product(name: "XCTVapor", package: "vapor"),
.product(name: "VaporTesting", package: "vapor"),
],
swiftSettings: swiftSettings
),
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@

📧 SendGrid library for the Vapor web framework, based on [SendGridKit](https://github.com/vapor-community/sendgrid-kit).

Send simple emails, or leverage the full capabilities of [SendGrid's V3 API](https://www.twilio.com/docs/sendgrid/api-reference/mail-send/mail-send).
Send simple emails or leverage the full capabilities of [SendGrid's V3 API](https://www.twilio.com/docs/sendgrid/api-reference/mail-send/mail-send).

### Getting Started

Use the SPM string to easily include the dependendency in your `Package.swift` file

```swift
.package(url: "https://github.com/vapor-community/sendgrid.git", from: "6.0.0-rc.1")
.package(url: "https://github.com/vapor-community/sendgrid.git", from: "6.0.0"),
```

and add it to your target's dependencies:

```swift
.product(name: "SendGrid", package: "sendgrid")
.product(name: "SendGrid", package: "sendgrid"),
```

## Overview
Expand Down Expand Up @@ -63,6 +63,8 @@ If the request to the API failed for any reason a `SendGridError` is thrown, whi
Simply ensure you catch errors thrown like any other throwing function.

```swift
import SendGrid

do {
try await req.sendgrid.client.send(email: email)
} catch let error as SendGridError {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SendGrid/Application+SendGrid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extension Application {

public var client: SendGridClient {
get { self.storage.client }
set { self.storage.client = newValue }
nonmutating set { self.storage.client = newValue }
}

private var storage: Storage {
Expand Down
6 changes: 4 additions & 2 deletions Sources/SendGrid/SendGrid.docc/SendGrid.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# ``SendGrid``

📧 SendGrid library for the Vapor web framework, based on SendGridKit.
SendGrid library for the Vapor web framework, based on SendGridKit.

## Overview

Send simple emails, or leverage the full capabilities of SendGrid's V3 API.
Send simple emails or leverage the full capabilities of SendGrid's V3 API.

> Warning: Make sure that the `SENDGRID_API_KEY` variable is set in your environment.
This can be set in the Xcode scheme, or specified in your `docker-compose.yml`, or even provided as part of a `swift run` command.
Expand All @@ -30,6 +30,8 @@ If the request to the API failed for any reason a `SendGridError` is thrown, whi
Simply ensure you catch errors thrown like any other throwing function.

```swift
import SendGrid

do {
try await req.sendgrid.client.send(email: email)
} catch let error as SendGridError {
Expand Down
10 changes: 0 additions & 10 deletions Tests/SendGridTests/Helpers/isLoggingConfigured.swift

This file was deleted.

9 changes: 0 additions & 9 deletions Tests/SendGridTests/Helpers/withApp.swift

This file was deleted.

61 changes: 30 additions & 31 deletions Tests/SendGridTests/SendGridTests.swift
Original file line number Diff line number Diff line change
@@ -1,58 +1,50 @@
import SendGrid
import Testing
import XCTVapor
import VaporTesting

@Suite("SendGrid Tests")
struct SendGridTests {
@Test func application() async throws {
try await withApp { app in
// TODO: Replace from addresses and to addresses
let email = SendGridEmail(
personalizations: [Personalization(to: ["TO-ADDRESS"])],
from: "FROM-ADDRESS",
subject: "Test Email",
content: ["This email was sent using SendGridKit!"]
)
// TODO: Replace with `false` when you have a valid API key
let credentialsAreInvalid = true

// TODO: Replace from addresses and to addresses
let email = SendGridEmail(
personalizations: [Personalization(to: ["TO-ADDRESS"])],
from: "FROM-ADDRESS",
subject: "Test Email",
content: ["This email was sent using SendGridKit!"]
)

@Test("Access client from Application")
func application() async throws {
try await withApp { app in
try await withKnownIssue {
try await app.sendgrid.client.send(email: email)
} when: {
// TODO: Replace with `false` when you have a valid API key
true
credentialsAreInvalid
}
}
}

@Test func request() async throws {
@Test("Access client from Request")
func request() async throws {
try await withApp { app in
app.get("test") { req async throws -> Response in
// TODO: Replace from addresses and to addresses
let email = SendGridEmail(
personalizations: [Personalization(to: ["TO-ADDRESS"])],
from: "FROM-ADDRESS",
subject: "Test Email",
content: ["This email was sent using SendGridKit!"]
)
try await req.sendgrid.client.send(email: email)
return Response(status: .ok)
}

try await app.test(.GET, "test") { res async throws in
// TODO: Replace with `.ok` when you have a valid API key
#expect(res.status == .internalServerError)
let internalServerError = res.status == .internalServerError
let ok = res.status == .ok
#expect(credentialsAreInvalid ? internalServerError : ok)
}
}
}

@Test func storage() async throws {
@Test("Client storage in Application")
func storage() async throws {
try await withApp { app in
// TODO: Replace from addresses and to addresses
let email = SendGridEmail(
personalizations: [Personalization(to: ["TO-ADDRESS"])],
from: "FROM-ADDRESS",
subject: "Test Email",
content: ["This email was sent using SendGridKit!"]
)

do {
try await app.sendgrid.client.send(email: email)
} catch {}
Expand All @@ -62,6 +54,13 @@ struct SendGridTests {
do {
try await app.sendgrid.client.send(email: email)
} catch {}

// Change the client and try sending again
app.sendgrid.client = .init(httpClient: app.http.client.shared, apiKey: "new-api-key")

do {
try await app.sendgrid.client.send(email: email)
} catch {}
}
}
}

0 comments on commit b7cb492

Please sign in to comment.