From 25dff3a6662aba9283e17f14c3f33f1ae0db1e47 Mon Sep 17 00:00:00 2001 From: Petr Pavlik Date: Thu, 22 Aug 2024 00:50:07 +0200 Subject: [PATCH] refactor --- .../IndiePitcherSwift/IndiePitcherSwift.swift | 42 +++++++++---------- Sources/IndiePitcherSwift/dtos.swift | 16 +++---- .../IndiePitcherSwiftTests.swift | 6 +-- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Sources/IndiePitcherSwift/IndiePitcherSwift.swift b/Sources/IndiePitcherSwift/IndiePitcherSwift.swift index 7f924db..d1836f0 100644 --- a/Sources/IndiePitcherSwift/IndiePitcherSwift.swift +++ b/Sources/IndiePitcherSwift/IndiePitcherSwift.swift @@ -26,10 +26,10 @@ public struct IndiePitcher { } private func buildUri(path: String) -> URI { - URI(stringLiteral: "https://api.indiepitcher.com/v2" + path) + URI(stringLiteral: "https://api.indiepitcher.com/v1" + path) } - /// Add a new contact to the contact list, or update an existing one if `updateIfExists` is set to `true`. + /// Add a new contact to the mailing list, or update an existing one if `updateIfExists` is set to `true`. /// - Parameter contact: Contact properties. /// - Returns: Created contact. @discardableResult public func addContact(contact: CreateContact) async throws -> DataResponse { @@ -59,8 +59,8 @@ public struct IndiePitcher { return try response.content.decode(DataResponse.self) } - /// Deletes a contact with provided email from the contact list - /// - Parameter email: The email address of the contact you wish to remove from the contact list + /// Deletes a contact with provided email from the mailing list + /// - Parameter email: The email address of the contact you wish to remove from the mailing list /// - Returns: A generic empty response. @discardableResult public func deleteContact(email: String) async throws -> EmptyResposne { @@ -75,7 +75,7 @@ public struct IndiePitcher { return try response.content.decode(EmptyResposne.self) } - /// Returns a paginated list of stored contacts in the contact list. + /// Returns a paginated list of stored contacts in the mailing list. /// - Parameters: /// - page: Page to fetch, the first page has index 1. /// - perPage: How many contacts to return per page. @@ -100,8 +100,8 @@ public struct IndiePitcher { return try response.content.decode(EmptyResposne.self) } - /// Send a personalized email to one more (up to 100 using 1 API call) contacts subscribed to a proviced contact list. This is the recommended way to send an email to members of a team of your product. - /// All provided emails must belong to your contact list and must be members of provided contact list. All contacts are automatically subscribed to `important` default contact list. You can use peronalization tags such as `Hi {{firstName|default:"there"}}` to peronalize individual sent emails, and scheduled it to be sent with a delay. + /// Send a personalized email to one more (up to 100 using 1 API call) contacts subscribed to a proviced mailing list. This is the recommended way to send an email to members of a team of your product. + /// All provided emails must belong to your mailing list and must be members of provided mailing list. All contacts are automatically subscribed to `important` default mailing list. You can use peronalization tags such as `Hi {{firstName|default:"there"}}` to peronalize individual sent emails, and scheduled it to be sent with a delay. /// - Parameter data: Input params. /// - Returns: A genereic response with no return data. @discardableResult public func sendEmailToContact(data: SendEmailToContact) async throws -> EmptyResposne { @@ -112,53 +112,53 @@ public struct IndiePitcher { return try response.content.decode(EmptyResposne.self) } - /// Send a personalized email to all contacts subscribed to a provided contact list. This is the recommendat way to send a newsletter, by creating a list called something like `Newsletter`. - /// All contacts are automatically subscribed to `important` default contact list. You can use peronalization tags such as `Hi {{firstName|default:"there"}}` to peronalize individual sent emails, and scheduled it to be sent with a delay. + /// Send a personalized email to all contacts subscribed to a provided mailing list. This is the recommendat way to send a newsletter, by creating a list called something like `Newsletter`. + /// All contacts are automatically subscribed to `important` default mailing list. You can use peronalization tags such as `Hi {{firstName|default:"there"}}` to peronalize individual sent emails, and scheduled it to be sent with a delay. /// - Parameter data: Input params. /// - Returns: A genereic response with no return data. - @discardableResult public func sendEmailToContactList(data: SendEmailToContactList) async throws -> EmptyResposne { - let response = try await client.post(buildUri(path: "/email/contact_list"), + @discardableResult public func sendEmailToMailingList(data: SendEmailToMailingList) async throws -> EmptyResposne { + let response = try await client.post(buildUri(path: "/email/list"), headers: commonHeaders, content: data) return try response.content.decode(EmptyResposne.self) } - /// Returns contact lists contacts can subscribe to. + /// Returns mailing lists contacts can subscribe to. /// - Parameters: /// - page: Page to fetch, the first page has index 1. /// - perPage: How many contacts to return per page. - /// - Returns: A paginated array of contact lists - public func listContactLists(page: Int = 1, perPage: Int = 10) async throws -> PagedDataResponse { + /// - Returns: A paginated array of mailing lists + public func listMailingLists(page: Int = 1, perPage: Int = 10) async throws -> PagedDataResponse { struct Payload: Content { let page: Int let per: Int } - let response = try await client.get(buildUri(path: "/contact_lists?page=\(page)&per=\(perPage)"), + let response = try await client.get(buildUri(path: "/lists?page=\(page)&per=\(perPage)"), headers: commonHeaders) - return try response.content.decode(PagedDataResponse.self) + return try response.content.decode(PagedDataResponse.self) } - /// Generates a new public URL for a contact with provided email to manage their contact list subscriptions. + /// Generates a new public URL for a contact with provided email to manage their mailing list subscriptions. /// - Parameters: /// - contactEmail: The email of a contact this session is for. - /// - returnURL: The URL to redirect to when the user is done editing their contact list, or when the session has expired. + /// - returnURL: The URL to redirect to when the user is done editing their mailing list, or when the session has expired. /// - Returns: Newly created URL session. - public func createContactListsPortalSession(contactEmail: String, returnURL: URL) async throws -> DataResponse { + public func createMailingListsPortalSession(contactEmail: String, returnURL: URL) async throws -> DataResponse { struct Payload: Content { let contactEmail: String let returnURL: URL } - let response = try await client.post(buildUri(path: "/contact_lists/portal_session"), + let response = try await client.post(buildUri(path: "/lists/portal_session"), headers: commonHeaders, content: Payload(contactEmail: contactEmail, returnURL: returnURL)) - return try response.content.decode(DataResponse.self) + return try response.content.decode(DataResponse.self) } } diff --git a/Sources/IndiePitcherSwift/dtos.swift b/Sources/IndiePitcherSwift/dtos.swift index fe6d84d..52a3992 100644 --- a/Sources/IndiePitcherSwift/dtos.swift +++ b/Sources/IndiePitcherSwift/dtos.swift @@ -78,7 +78,7 @@ public enum CustomContactPropertyValue: Codable, Equatable { } } -/// A contact in the contact list +/// A contact in the mailing list public struct Contact: Content { public init(email: String, userId: String? = nil, avatarUrl: String? = nil, name: String? = nil, hardBouncedAt: Date? = nil, subscribedToLists: [String], customProperties: [String : CustomContactPropertyValue], languageCode: String? = nil) { self.email = email @@ -164,7 +164,7 @@ public struct CreateMultipleContacts: Content { public var contacts: [CreateContact] } -/// The payload to update a contact in the contact list. The email is required to identify the contact. +/// The payload to update a contact in the mailing list. The email is required to identify the contact. public struct UpdateContact: Content { /// Initializer @@ -284,7 +284,7 @@ public struct SendEmailToContact: Content { public var delayUntilDate: Date? } -public struct SendEmailToContactList: Content { +public struct SendEmailToMailingList: Content { /// Initializer /// - Parameters: @@ -322,8 +322,8 @@ public struct SendEmailToContactList: Content { public var delayUntilDate: Date? } -/// Represents a contact list contacts can subscribe to, such as `Monthly newsletter` or `Onboarding`. -public struct ContactList: Content { +/// Represents a mailing list contacts can subscribe to, such as `Monthly newsletter` or `Onboarding`. +public struct MailingList: Content { public init(name: String, title: String, numSubscribers: Int) { self.name = name @@ -331,10 +331,10 @@ public struct ContactList: Content { self.numSubscribers = numSubscribers } - /// The unique name of the contact list meant to be used by the public API. Not intended to be be shown to the end users, that's what `title` is for. + /// The unique name of the mailing list meant to be used by the public API. Not intended to be be shown to the end users, that's what `title` is for. public var name: String - /// A human readable name of the contact list. + /// A human readable name of the mailing list. public var title: String /// The number of contacts subscribed to this list. @@ -343,7 +343,7 @@ public struct ContactList: Content { /// A portal session that allows a contact to manage their email list subscriptions when redirected to returned `url`. A session is valid for 30 minutes. -public struct ContactListPortalSession: Content { +public struct MailingListPortalSession: Content { public init(url: URL, expiresAt: Date, returnURL: URL) { self.url = url self.expiresAt = expiresAt diff --git a/Tests/IndiePitcherSwiftTests/IndiePitcherSwiftTests.swift b/Tests/IndiePitcherSwiftTests/IndiePitcherSwiftTests.swift index d376a6e..2c97e64 100644 --- a/Tests/IndiePitcherSwiftTests/IndiePitcherSwiftTests.swift +++ b/Tests/IndiePitcherSwiftTests/IndiePitcherSwiftTests.swift @@ -25,14 +25,14 @@ final class IndiePitcherSwiftTests: XCTestCase { bodyFormat: .markdown)) } - func testGetContactLists() async throws { - let listsResponse = try await indiePitcher.listContactLists() + func testGetMailingLists() async throws { + let listsResponse = try await indiePitcher.listMailingLists() expect(listsResponse.metadata.total) == 2 expect(listsResponse.data.count) == 2 } func testSendMarketingEmailToList() async throws { - try await indiePitcher.sendEmailToContactList(data: .init(subject: "Test marketing email from IP Swift SDK unit tests", + try await indiePitcher.sendEmailToMailingList(data: .init(subject: "Test marketing email from IP Swift SDK unit tests", body: "This is a test body of a marketing email that supports **markdown**.", bodyFormat: .markdown, list: "test_list_1"))