Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ let package = Package(
targets: [
.target(
name: "BrevoKit",
exclude: ["Resources/TODO.md"],
dependencies: [
.product(name: "OpenAPIURLSession", package: "swift-openapi-urlsession"),
.product(name: "Logging", package: "swift-log")
Expand Down
36 changes: 35 additions & 1 deletion Sources/BrevoKit/Contacts/Contacts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,45 @@ public struct Contacts {
case .badRequest(let badRequest):
brevo.logger.error("Bad request: \(badRequest)")
throw BrevoError.badRequest
case .notFound(let notFound):
case .notFound:
return nil
case .undocumented(let statusCode, let undocumentedPayload):
brevo.logger.error("Undocumented response with status code \(statusCode): \(undocumentedPayload)")
throw BrevoError.unknownResponse
}
}

public func deleteContact(email identifier: String) async throws {
try await deleteContact(identifier: identifier, identifierType: .emailId)
}

public func deleteContact(externalID identifier: String) async throws {
try await deleteContact(identifier: identifier, identifierType: .extId)
}

private func deleteContact(identifier: String, identifierType: Operations.DeleteContact.Input.Query.IdentifierTypePayload) async throws {
let response = try await brevo.client.deleteContact(
.init(
path: Operations.DeleteContact.Input.Path(identifier: .case1(identifier)),
query: Operations.DeleteContact.Input.Query(identifierType: identifierType)
)
)

switch response {
case .noContent:
brevo.logger.info("Deleted contact with identifier \(identifier)")
case .badRequest(let badRequest):
brevo.logger.error("Bad request: \(badRequest)")
throw BrevoError.badRequest
case .notFound:
brevo.logger.warning("Contact with identifier \(identifier) not found")
throw BrevoError.notFound
case .methodNotAllowed(let methodNotAllowed):
brevo.logger.error("Method not allowed: \(methodNotAllowed)")
throw BrevoError.methodNotAllowed
case .undocumented(let statusCode, let undocumentedPayload):
brevo.logger.error("Undocumented response with status code \(statusCode): \(undocumentedPayload)")
throw BrevoError.unknownResponse
}
}
}
1 change: 1 addition & 0 deletions Sources/BrevoKit/Helpers/Errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public enum BrevoError: Error {
case badRequest
case unknownResponse
case notFound
case methodNotAllowed
}

public extension DecodingError {
Expand Down