Skip to content

Commit

Permalink
Do not use GetData in AnnouncementServiceRemote
Browse files Browse the repository at this point in the history
  • Loading branch information
crazytonyli committed Mar 8, 2024
1 parent 20e92ac commit 84d00d3
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions WordPressKit/AnnouncementServiceRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,11 @@ public class AnnouncementServiceRemote: ServiceRemoteWordPressComREST {
}

let path = self.path(forEndpoint: endPoint, withVersion: ._2_0)

wordPressComRestApi.GETData(path, parameters: nil) { result in
switch result {
case .success((let data, _)):
do {
let announcements = try self.decodeAnnouncements(from: data)
completion(.success(announcements))
} catch {
completion(.failure(error))
}
case .failure(let error):
completion(.failure(error))
}
Task { @MainActor [wordPressComRestApi] in
await wordPressComRestApi.perform(.get, URLString: path, type: AnnouncementsContainer.self)
.map { $0.body.announcements }
.eraseToError()
.execute(completion)
}
}
}
Expand All @@ -45,11 +37,6 @@ private extension AnnouncementServiceRemote {
path?.queryItems = makeQueryItems(appId: appId, appVersion: appVersion, locale: locale)
return path?.string
}

func decodeAnnouncements(from data: Data) throws -> [Announcement] {
let container = try JSONDecoder().decode(AnnouncementsContainer.self, from: data)
return container.announcements
}
}

// MARK: - Constants
Expand Down

0 comments on commit 84d00d3

Please sign in to comment.