diff --git a/Package.resolved b/Package.resolved index 3d70c83..a8fa1b7 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "af8bd123eff657a06880dbdd5a78b7feb8021800b086b1cfbb4415867cbf6590", + "originHash" : "8da9d3c2ed2fbdebac6161799e4fea1be3c58f706b8052fc06e1684461b13362", "pins" : [ { "identity" : "swift-collections", @@ -19,6 +19,15 @@ "version" : "1.4.0" } }, + { + "identity" : "swift-log", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-log.git", + "state" : { + "revision" : "ce592ae52f982c847a4efc0dd881cc9eb32d29f2", + "version" : "1.6.4" + } + }, { "identity" : "swift-openapi-runtime", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index 853841a..e517a71 100644 --- a/Package.swift +++ b/Package.swift @@ -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") diff --git a/Sources/BrevoKit/Contacts/Contacts.swift b/Sources/BrevoKit/Contacts/Contacts.swift index feab7d4..fe0e900 100644 --- a/Sources/BrevoKit/Contacts/Contacts.swift +++ b/Sources/BrevoKit/Contacts/Contacts.swift @@ -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 + } + } } diff --git a/Sources/BrevoKit/Helpers/Errors.swift b/Sources/BrevoKit/Helpers/Errors.swift index fc344af..c25be8d 100644 --- a/Sources/BrevoKit/Helpers/Errors.swift +++ b/Sources/BrevoKit/Helpers/Errors.swift @@ -4,6 +4,7 @@ public enum BrevoError: Error { case badRequest case unknownResponse case notFound + case methodNotAllowed } public extension DecodingError {