Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 84d00d3

Browse files
committed
Do not use GetData in AnnouncementServiceRemote
1 parent 20e92ac commit 84d00d3

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

WordPressKit/AnnouncementServiceRemote.swift

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,11 @@ public class AnnouncementServiceRemote: ServiceRemoteWordPressComREST {
1414
}
1515

1616
let path = self.path(forEndpoint: endPoint, withVersion: ._2_0)
17-
18-
wordPressComRestApi.GETData(path, parameters: nil) { result in
19-
switch result {
20-
case .success((let data, _)):
21-
do {
22-
let announcements = try self.decodeAnnouncements(from: data)
23-
completion(.success(announcements))
24-
} catch {
25-
completion(.failure(error))
26-
}
27-
case .failure(let error):
28-
completion(.failure(error))
29-
}
17+
Task { @MainActor [wordPressComRestApi] in
18+
await wordPressComRestApi.perform(.get, URLString: path, type: AnnouncementsContainer.self)
19+
.map { $0.body.announcements }
20+
.eraseToError()
21+
.execute(completion)
3022
}
3123
}
3224
}
@@ -45,11 +37,6 @@ private extension AnnouncementServiceRemote {
4537
path?.queryItems = makeQueryItems(appId: appId, appVersion: appVersion, locale: locale)
4638
return path?.string
4739
}
48-
49-
func decodeAnnouncements(from data: Data) throws -> [Announcement] {
50-
let container = try JSONDecoder().decode(AnnouncementsContainer.self, from: data)
51-
return container.announcements
52-
}
5340
}
5441

5542
// MARK: - Constants

0 commit comments

Comments
 (0)