Skip to content

Commit 6678b50

Browse files
authored
Merge pull request #11 from vamsii777/feature/add-update-domain
Add Support for DomainTLSMode
2 parents d0a83e6 + 27f48be commit 6678b50

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

Sources/Resend/Models/Request/Domain/DomainUpdate.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import Foundation
22

3+
public enum DomainTLSMode: String, Codable {
4+
case opportunistic
5+
case enforced
6+
}
7+
38
struct DomainUpdate: Encodable {
49
var clickTracking: Bool
510
var openTracking: Bool
6-
var tls: String
11+
var tls: DomainTLSMode
712

813
enum CodingKeys: String, CodingKey {
914
case clickTracking = "click_tracking"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Foundation
2+
3+
public struct DomainDeleteResponse: Decodable {
4+
public var object: String
5+
public var id: String
6+
public var deleted: Bool
7+
}

Sources/Resend/Resend/DomainClient.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ public class DomainClient: ResendClient {
4949
}
5050

5151
/// Update a domain
52-
public func update(domainId: String, clickTracking: Bool, openTracking: Bool, tls: String = "opportunistic") async throws -> Domain {
52+
/// - Parameters:
53+
/// - domainId: The ID of the domain to update
54+
/// - clickTracking: Track clicks within the body of each HTML email
55+
/// - openTracking: Track the open rate of each email
56+
/// - tls: TLS policy (.opportunistic or .enforced)
57+
/// - Returns: The updated Domain object
58+
public func update(domainId: String, clickTracking: Bool, openTracking: Bool, tls: DomainTLSMode = .opportunistic) async throws -> Domain {
5359
let body = DomainUpdate(clickTracking: clickTracking, openTracking: openTracking, tls: tls)
5460
let response = try await httpClient.execute(
5561
request: .init(
@@ -77,7 +83,9 @@ public class DomainClient: ResendClient {
7783
}
7884

7985
/// Delete a domain
80-
public func delete(domainId: String) async throws {
86+
/// - Parameter domainId: The ID of the domain to delete
87+
/// - Returns: DomainDeleteResponse containing the result of the deletion
88+
public func delete(domainId: String) async throws -> DomainDeleteResponse {
8189
let response = try await httpClient.execute(
8290
request: .init(
8391
url: APIPath.getPath(for: .domainDelete(domainId: domainId)),
@@ -86,8 +94,6 @@ public class DomainClient: ResendClient {
8694
)
8795
).get()
8896

89-
guard response.status == .ok else {
90-
throw ResendError.unknownError
91-
}
97+
return try parseResponse(response, to: DomainDeleteResponse.self)
9298
}
9399
}

0 commit comments

Comments
 (0)