Skip to content

Commit

Permalink
Use vapor/ci linting (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino authored Oct 5, 2024
1 parent 6ce2b23 commit cd3d999
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 92 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,9 @@ on:
push: { branches: [ main ] }

jobs:
lint:
runs-on: ubuntu-latest
container: swift:jammy
steps:
- name: Check out SendGridKit
uses: actions/checkout@v4
- name: Run format lint check
run: swift format lint --strict --recursive --parallel .

unit-tests:
uses: vapor/ci/.github/workflows/run-unit-tests.yml@main
with:
with_linting: true
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
70 changes: 0 additions & 70 deletions .swift-format

This file was deleted.

2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let package = Package(
.library(name: "SendGridKit", targets: ["SendGridKit"])
],
dependencies: [
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.22.0")
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.23.0")
],
targets: [
.target(
Expand Down
11 changes: 3 additions & 8 deletions Sources/SendGridKit/SendGridClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@ public struct SendGridClient: Sendable {
public init(httpClient: HTTPClient, apiKey: String, forEU: Bool = false) {
self.httpClient = httpClient
self.apiKey = apiKey
self.apiURL =
forEU
? "https://api.eu.sendgrid.com/v3/mail/send" : "https://api.sendgrid.com/v3/mail/send"
self.apiURL = forEU ? "https://api.eu.sendgrid.com/v3/mail/send" : "https://api.sendgrid.com/v3/mail/send"
}

public func send<DynamicTemplateData: Codable & Sendable>(
email: SendGridEmail<DynamicTemplateData>
) async throws {
public func send<DynamicTemplateData: Codable & Sendable>(email: SendGridEmail<DynamicTemplateData>) async throws {
var headers = HTTPHeaders()
headers.add(name: "Authorization", value: "Bearer \(apiKey)")
headers.add(name: "Content-Type", value: "application/json")
Expand All @@ -53,7 +49,6 @@ public struct SendGridClient: Sendable {
if (200...299).contains(response.status.code) { return }

// `JSONDecoder` will handle empty body by throwing decoding error
throw try await decoder.decode(
SendGridError.self, from: response.body.collect(upTo: 1024 * 1024))
throw try await decoder.decode(SendGridError.self, from: response.body.collect(upTo: 1024 * 1024))
}
}
9 changes: 5 additions & 4 deletions Tests/SendGridKitTests/SendGridTestsKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,17 @@ struct SendGridKitTests {
let integer: Int
let double: Double
}
let dynamicTemplateData = DynamicTemplateData(
text: "Hello, World!", integer: 42, double: 3.14)
let dynamicTemplateData = DynamicTemplateData(text: "Hello, World!", integer: 42, double: 3.14)

// TODO: Replace the addresses with real email addresses
let personalization = Personalization(
to: [EmailAddress("TO-ADDRESS")], subject: "Test Email",
dynamicTemplateData: dynamicTemplateData)
dynamicTemplateData: dynamicTemplateData
)
let email = SendGridEmail(
personalizations: [personalization], from: EmailAddress("FROM-ADDRESS"),
content: [EmailContent("Hello, World!")])
content: [EmailContent("Hello, World!")]
)

try await withKnownIssue {
try await client.send(email: email)
Expand Down

0 comments on commit cd3d999

Please sign in to comment.