From 2024e63fa78bfc124f648916b955ac96ee939eab Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 17:04:12 +1100 Subject: [PATCH 01/35] Use `WordPressComRESTAPIInterfacing` in `ActivityServiceRemote` --- .../Services/ActivityServiceRemote.swift | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Sources/WordPressKit/Services/ActivityServiceRemote.swift b/Sources/WordPressKit/Services/ActivityServiceRemote.swift index c8c09ecd1..d81ab3273 100644 --- a/Sources/WordPressKit/Services/ActivityServiceRemote.swift +++ b/Sources/WordPressKit/Services/ActivityServiceRemote.swift @@ -59,7 +59,7 @@ open class ActivityServiceRemote: ServiceRemoteWordPressComREST { let finalPath = self.path(forEndpoint: endpoint, withVersion: ._2_0) - wordPressComRestApi.GET(finalPath, + wordPressComRESTAPI.get(finalPath, parameters: nil, success: { response, _ in do { @@ -105,7 +105,7 @@ open class ActivityServiceRemote: ServiceRemoteWordPressComREST { parameters["on"] = formatter.string(from: on) as AnyObject } - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: parameters, success: { response, _ in do { @@ -135,7 +135,7 @@ open class ActivityServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/rewind" let path = self.path(forEndpoint: endpoint, withVersion: ._2_0) - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: nil, success: { response, _ in guard let rewindStatus = response as? [String: AnyObject] else { @@ -154,12 +154,17 @@ open class ActivityServiceRemote: ServiceRemoteWordPressComREST { }, failure: { error, _ in // FIXME: A hack to support free WPCom sites and Rewind. Should be obsolote as soon as the backend // stops returning 412's for those sites. - if error.domain == WordPressComRestApiEndpointError.errorDomain, error.code == WordPressComRestApiErrorCode.preconditionFailure.rawValue { - let status = RewindStatus(state: .unavailable) - success(status) + let nsError = error as NSError + + guard nsError.domain == WordPressComRestApiEndpointError.errorDomain, + nsError.code == WordPressComRestApiErrorCode.preconditionFailure.rawValue else { + failure(error) return } - failure(error) + + let status = RewindStatus(state: .unavailable) + success(status) + return }) } @@ -167,7 +172,7 @@ open class ActivityServiceRemote: ServiceRemoteWordPressComREST { private extension ActivityServiceRemote { - func mapActivitiesResponse(_ response: AnyObject) throws -> ([Activity], Int) { + func mapActivitiesResponse(_ response: Any) throws -> ([Activity], Int) { guard let json = response as? [String: AnyObject], let totalItems = json["totalItems"] as? Int else { @@ -196,7 +201,7 @@ private extension ActivityServiceRemote { } } - func mapActivityGroupsResponse(_ response: AnyObject) throws -> ([ActivityGroup]) { + func mapActivityGroupsResponse(_ response: Any) throws -> ([ActivityGroup]) { guard let json = response as? [String: AnyObject], let totalItems = json["totalItems"] as? Int, totalItems > 0 else { return [] From 68b7e1b2fd6d951f0ac9849c61b666ae32ab7024 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 17:05:38 +1100 Subject: [PATCH 02/35] Use `WordPressComRESTAPIInterfacing` in `AutomatedTransferService` --- .../WordPressKit/Services/AutomatedTransferService.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/WordPressKit/Services/AutomatedTransferService.swift b/Sources/WordPressKit/Services/AutomatedTransferService.swift index 19f5be65a..168783e89 100644 --- a/Sources/WordPressKit/Services/AutomatedTransferService.swift +++ b/Sources/WordPressKit/Services/AutomatedTransferService.swift @@ -26,7 +26,7 @@ public class AutomatedTransferService: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/automated-transfers/eligibility" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.GET(path, parameters: nil, success: { (responseObject, _) in + wordPressComRESTAPI.get(path, parameters: nil, success: { (responseObject, _) in guard let response = responseObject as? [String: AnyObject] else { failure(.unknown) return @@ -53,7 +53,7 @@ public class AutomatedTransferService: ServiceRemoteWordPressComREST { let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) let payload = ["plugin": pluginSlug] as [String: AnyObject] - wordPressComRestApi.POST(path, parameters: payload, success: { (responseObject, _) in + wordPressComRESTAPI.post(path, parameters: payload, success: { (responseObject, _) in guard let response = responseObject as? [String: AnyObject] else { failure(ResponseError.decodingFailure) return @@ -80,7 +80,7 @@ public class AutomatedTransferService: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/automated-transfers/status" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.GET(path, parameters: nil, success: { (responseObject, _) in + wordPressComRESTAPI.get(path, parameters: nil, success: { (responseObject, _) in guard let response = responseObject as? [String: AnyObject] else { failure(ResponseError.decodingFailure) return From 3acacde71a3966d99dcd2ac3f46a02fee4b4df88 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 19:44:08 +1100 Subject: [PATCH 03/35] Use `WordPressComRESTAPIInterfacing` in `BlogJetpackSettingsServiceRemote` --- .../BlogJetpackSettingsServiceRemote.swift | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Sources/WordPressKit/Services/BlogJetpackSettingsServiceRemote.swift b/Sources/WordPressKit/Services/BlogJetpackSettingsServiceRemote.swift index 10178e3d9..7ac03196a 100644 --- a/Sources/WordPressKit/Services/BlogJetpackSettingsServiceRemote.swift +++ b/Sources/WordPressKit/Services/BlogJetpackSettingsServiceRemote.swift @@ -13,13 +13,13 @@ public class BlogJetpackSettingsServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "jetpack-blogs/\(siteID)/rest-api" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - let parameters = ["path": "/jetpack/v4/settings"] + let parameters: [String: Any] = ["path": "/jetpack/v4/settings"] - wordPressComRestApi.GET(path, - parameters: parameters as [String: AnyObject]?, - success: { - response, _ in - guard let results = response["data"] as? [String: AnyObject], + wordPressComRESTAPI.get(path, + parameters: parameters, + success: { response, _ in + guard let responseDict = response as? [String: Any], + let results = responseDict["data"] as? [String: AnyObject], let remoteSettings = try? self.remoteJetpackSettingsFromDictionary(results) else { failure(ResponseError.decodingFailure) return @@ -38,11 +38,11 @@ public class BlogJetpackSettingsServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "jetpack-blogs/\(siteID)" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: nil, - success: { - response, _ in - guard let results = response["settings"] as? [String: AnyObject], + success: { response, _ in + guard let responseDict = response as? [String: Any], + let results = responseDict["settings"] as? [String: AnyObject], let remoteMonitorSettings = try? self.remoteJetpackMonitorSettingsFromDictionary(results) else { failure(ResponseError.decodingFailure) return @@ -61,11 +61,11 @@ public class BlogJetpackSettingsServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/jetpack/modules" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: nil, - success: { - response, _ in - guard let modules = response["modules"] as? [[String: AnyObject]], + success: { response, _ in + guard let responseDict = response as? [String: Any], + let modules = responseDict["modules"] as? [[String: AnyObject]], let remoteModulesSettings = try? self.remoteJetpackModulesSettingsFromArray(modules) else { failure(ResponseError.decodingFailure) return @@ -94,7 +94,7 @@ public class BlogJetpackSettingsServiceRemote: ServiceRemoteWordPressComREST { "body": jSONBody, "json": true] as [String: AnyObject] - wordPressComRestApi.POST(path, + wordPressComRESTAPI.post(path, parameters: parameters, success: { _, _ in @@ -113,7 +113,7 @@ public class BlogJetpackSettingsServiceRemote: ServiceRemoteWordPressComREST { let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) let parameters = dictionaryFromJetpackMonitorSettings(settings) - wordPressComRestApi.POST(path, + wordPressComRESTAPI.post(path, parameters: parameters, success: { _, _ in @@ -131,7 +131,7 @@ public class BlogJetpackSettingsServiceRemote: ServiceRemoteWordPressComREST { let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) let parameters = [ModuleOptionKeys.active: active] - wordPressComRestApi.POST(path, + wordPressComRESTAPI.post(path, parameters: parameters as [String: AnyObject], success: { _, _ in @@ -148,7 +148,7 @@ public class BlogJetpackSettingsServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "jetpack-blogs/\(siteID)/mine/delete" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.POST(path, + wordPressComRESTAPI.post(path, parameters: nil, success: { _, _ in From 00ea99b9ef43d190a1e873228f85c06d95a2b750 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 19:45:24 +1100 Subject: [PATCH 04/35] Use `WordPressComRESTAPIInterfacing` in `DashboardServiceRemote` --- Sources/WordPressKit/Services/DashboardServiceRemote.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/WordPressKit/Services/DashboardServiceRemote.swift b/Sources/WordPressKit/Services/DashboardServiceRemote.swift index 1970922c5..983ff6f5a 100644 --- a/Sources/WordPressKit/Services/DashboardServiceRemote.swift +++ b/Sources/WordPressKit/Services/DashboardServiceRemote.swift @@ -17,7 +17,7 @@ open class DashboardServiceRemote: ServiceRemoteWordPressComREST { failure(error) } - wordPressComRestApi.GET(requestUrl, + wordPressComRESTAPI.get(requestUrl, parameters: params, success: { response, _ in guard let cards = response as? NSDictionary else { From 5686b208fff347bf875b1504289898a4aff521b2 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 19:47:07 +1100 Subject: [PATCH 05/35] Use `WordPressComRESTAPIInterfacing` in `AtomicAuthenticationServiceRemote` --- .../Services/AtomicAuthenticationServiceRemote.swift | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Sources/WordPressKit/Services/AtomicAuthenticationServiceRemote.swift b/Sources/WordPressKit/Services/AtomicAuthenticationServiceRemote.swift index 74b77aba5..2b7d62ac2 100644 --- a/Sources/WordPressKit/Services/AtomicAuthenticationServiceRemote.swift +++ b/Sources/WordPressKit/Services/AtomicAuthenticationServiceRemote.swift @@ -3,7 +3,7 @@ import Foundation public class AtomicAuthenticationServiceRemote: ServiceRemoteWordPressComREST { public enum ResponseError: Error { - case responseIsNotADictionary(response: AnyObject) + case responseIsNotADictionary(response: Any) case decodingFailure(response: [String: AnyObject]) case couldNotInstantiateCookie(name: String, value: String, domain: String, path: String, expires: Date) } @@ -16,11 +16,9 @@ public class AtomicAuthenticationServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/atomic-auth-proxy/read-access-cookies" let path = self.path(forEndpoint: endpoint, withVersion: ._2_0) - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: nil, - success: { - responseObject, _ in - + success: { responseObject, _ in do { let settings = try self.cookie(from: responseObject) success(settings) @@ -39,7 +37,7 @@ public class AtomicAuthenticationServiceRemote: ServiceRemoteWordPressComREST { return Date(timeIntervalSince1970: TimeInterval(expiration)) } - private func cookie(from responseObject: AnyObject) throws -> HTTPCookie { + private func cookie(from responseObject: Any) throws -> HTTPCookie { guard let response = responseObject as? [String: AnyObject] else { let error = ResponseError.responseIsNotADictionary(response: responseObject) WPKitLogError("❗️Error: \(error)") From fc01a5b87304c8bd6c4bc895a237ad79e0b62b89 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 19:48:39 +1100 Subject: [PATCH 06/35] Use `WordPressComRESTAPIInterfacing` in `BloggingPromptsServiceRemote` --- .../WordPressKit/Services/BloggingPromptsServiceRemote.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/WordPressKit/Services/BloggingPromptsServiceRemote.swift b/Sources/WordPressKit/Services/BloggingPromptsServiceRemote.swift index 861c66ae9..af39889b0 100644 --- a/Sources/WordPressKit/Services/BloggingPromptsServiceRemote.swift +++ b/Sources/WordPressKit/Services/BloggingPromptsServiceRemote.swift @@ -108,7 +108,7 @@ open class BloggingPromptsServiceRemote: ServiceRemoteWordPressComREST { return } - wordPressComRestApi.POST(path, parameters: parameters) { responseObject, _ in + wordPressComRESTAPI.post(path, parameters: parameters) { responseObject, _ in do { let data = try JSONSerialization.data(withJSONObject: responseObject) let response = try JSONDecoder().decode(UpdateBloggingPromptsSettingsResponse.self, from: data) From a2cbce062a0153308b3ac26a094821281736f290 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 19:51:01 +1100 Subject: [PATCH 07/35] Use `WordPressComRESTAPIInterfacing` in `EditorServiceRemote` --- Sources/WordPressKit/Models/EditorSettings.swift | 2 +- Sources/WordPressKit/Services/EditorServiceRemote.swift | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/WordPressKit/Models/EditorSettings.swift b/Sources/WordPressKit/Models/EditorSettings.swift index e5f36b7bb..2b54e5b3e 100644 --- a/Sources/WordPressKit/Models/EditorSettings.swift +++ b/Sources/WordPressKit/Models/EditorSettings.swift @@ -36,7 +36,7 @@ public struct EditorSettings { } extension EditorSettings { - init(with response: AnyObject) throws { + init(with response: Any) throws { guard let response = response as? [String: AnyObject] else { throw NSError(domain: NSURLErrorDomain, code: NSURLErrorBadServerResponse, userInfo: nil) } diff --git a/Sources/WordPressKit/Services/EditorServiceRemote.swift b/Sources/WordPressKit/Services/EditorServiceRemote.swift index 48c8f0e43..1d5ba5f87 100644 --- a/Sources/WordPressKit/Services/EditorServiceRemote.swift +++ b/Sources/WordPressKit/Services/EditorServiceRemote.swift @@ -6,7 +6,7 @@ public class EditorServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/gutenberg?platform=mobile&editor=\(editor.rawValue)" let path = self.path(forEndpoint: endpoint, withVersion: ._2_0) - wordPressComRestApi.POST(path, parameters: nil, success: { (responseObject, _) in + wordPressComRESTAPI.post(path, parameters: nil, success: { (responseObject, _) in do { let settings = try EditorSettings(with: responseObject) success(settings) @@ -28,7 +28,7 @@ public class EditorServiceRemote: ServiceRemoteWordPressComREST { "set_only_if_empty": setOnlyIfEmpty ] as [String: AnyObject] - wordPressComRestApi.POST(path, parameters: parameters, success: { (responseObject, _) in + wordPressComRESTAPI.post(path, parameters: parameters, success: { (responseObject, _) in guard let response = responseObject as? [String: String] else { if let boolResponse = responseObject as? Bool, boolResponse == false { return failure(EditorSettings.Error.badRequest) @@ -51,7 +51,7 @@ public class EditorServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/gutenberg" let path = self.path(forEndpoint: endpoint, withVersion: ._2_0) - wordPressComRestApi.GET(path, parameters: nil, success: { (responseObject, _) in + wordPressComRESTAPI.get(path, parameters: nil, success: { (responseObject, _) in do { let settings = try EditorSettings(with: responseObject) success(settings) From 62628a0a196d92a02d10c0722b51cd92fa86b2ee Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 19:51:46 +1100 Subject: [PATCH 08/35] Use `WordPressComRESTAPIInterfacing` in `FeatureFlagRemote` --- Sources/WordPressKit/Services/FeatureFlagRemote.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/WordPressKit/Services/FeatureFlagRemote.swift b/Sources/WordPressKit/Services/FeatureFlagRemote.swift index 3a7309b20..205e8b053 100644 --- a/Sources/WordPressKit/Services/FeatureFlagRemote.swift +++ b/Sources/WordPressKit/Services/FeatureFlagRemote.swift @@ -21,7 +21,7 @@ open class FeatureFlagRemote: ServiceRemoteWordPressComREST { return } - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: dictionary, success: { response, _ in From 28737791c3b5a0181f4d1c5f0ec85dc7cd0e00e8 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 19:53:11 +1100 Subject: [PATCH 09/35] Use `WordPressComRESTAPIInterfacing` in `HomepageSettingsServiceRemote` --- .../WordPressKit/Services/HomepageSettingsServiceRemote.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/WordPressKit/Services/HomepageSettingsServiceRemote.swift b/Sources/WordPressKit/Services/HomepageSettingsServiceRemote.swift index e035a4ace..5c22783ff 100644 --- a/Sources/WordPressKit/Services/HomepageSettingsServiceRemote.swift +++ b/Sources/WordPressKit/Services/HomepageSettingsServiceRemote.swift @@ -26,7 +26,7 @@ public class HomepageSettingsServiceRemote: ServiceRemoteWordPressComREST { parameters[Keys.pageForPostsID] = postsPageID as AnyObject } - wordPressComRestApi.POST(path, parameters: parameters, + wordPressComRESTAPI.post(path, parameters: parameters, success: { _, _ in success() }, failure: { error, _ in From 8d7b81652cece7e03f954c5826b9fb99b8e49db1 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 19:53:22 +1100 Subject: [PATCH 10/35] Use `WordPressComRESTAPIInterfacing` in `JetpackBackupServiceRemote` --- .../WordPressKit/Services/JetpackBackupServiceRemote.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/WordPressKit/Services/JetpackBackupServiceRemote.swift b/Sources/WordPressKit/Services/JetpackBackupServiceRemote.swift index 7e957e1fa..ce4429156 100644 --- a/Sources/WordPressKit/Services/JetpackBackupServiceRemote.swift +++ b/Sources/WordPressKit/Services/JetpackBackupServiceRemote.swift @@ -29,7 +29,7 @@ open class JetpackBackupServiceRemote: ServiceRemoteWordPressComREST { parameters["types"] = types.toDictionary() as AnyObject } - wordPressComRestApi.POST(path, parameters: parameters, success: { response, _ in + wordPressComRESTAPI.post(path, parameters: parameters, success: { response, _ in do { let decoder = JSONDecoder.apiDecoder let data = try JSONSerialization.data(withJSONObject: response, options: []) @@ -88,7 +88,7 @@ open class JetpackBackupServiceRemote: ServiceRemoteWordPressComREST { let parameters = ["dismissed": true] as [String: AnyObject] - wordPressComRestApi.POST(path, parameters: parameters, success: { _, _ in + wordPressComRESTAPI.post(path, parameters: parameters, success: { _, _ in success() }, failure: { error, _ in failure(error) @@ -109,7 +109,7 @@ open class JetpackBackupServiceRemote: ServiceRemoteWordPressComREST { path = backupPath(for: siteID) } - wordPressComRestApi.GET(path, parameters: nil, success: { response, _ in + wordPressComRESTAPI.get(path, parameters: nil, success: { response, _ in do { let decoder = JSONDecoder.apiDecoder let data = try JSONSerialization.data(withJSONObject: response, options: []) From 1872f2fcd56b8df85a91ac53c87580e22bb017b5 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 19:53:51 +1100 Subject: [PATCH 11/35] Use `WordPressComRESTAPIInterfacing` in `JetpackCapabilitiesServiceRemote` --- .../Services/JetpackCapabilitiesServiceRemote.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/WordPressKit/Services/JetpackCapabilitiesServiceRemote.swift b/Sources/WordPressKit/Services/JetpackCapabilitiesServiceRemote.swift index d3e690462..aad2c331c 100644 --- a/Sources/WordPressKit/Services/JetpackCapabilitiesServiceRemote.swift +++ b/Sources/WordPressKit/Services/JetpackCapabilitiesServiceRemote.swift @@ -19,7 +19,7 @@ open class JetpackCapabilitiesServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/rewind/capabilities" let path = self.path(forEndpoint: endpoint, withVersion: ._2_0) - self.wordPressComRestApi.GET(path, + self.wordPressComRESTAPI.get(path, parameters: nil, success: { response, _ in if let capabilities = (response as? [String: AnyObject])?["capabilities"] as? [String] { From d9c58df94424fb68516644804a07569e6cf2ad5b Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 19:55:18 +1100 Subject: [PATCH 12/35] Use `WordPressComRESTAPIInterfacing` in `JetpackScanServiceRemote` --- .../Services/JetpackScanServiceRemote.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Sources/WordPressKit/Services/JetpackScanServiceRemote.swift b/Sources/WordPressKit/Services/JetpackScanServiceRemote.swift index 67290a5a8..0682d7b3c 100644 --- a/Sources/WordPressKit/Services/JetpackScanServiceRemote.swift +++ b/Sources/WordPressKit/Services/JetpackScanServiceRemote.swift @@ -19,8 +19,9 @@ public class JetpackScanServiceRemote: ServiceRemoteWordPressComREST { public func startScanForSite(_ siteID: Int, success: @escaping(Bool) -> Void, failure: @escaping(Error) -> Void) { let path = self.scanPath(for: siteID, with: "enqueue") - wordPressComRestApi.POST(path, parameters: nil, success: { (response, _) in - guard let responseValue = response["success"] as? Bool else { + wordPressComRESTAPI.post(path, parameters: nil, success: { (response, _) in + guard let responseDict = response as? [String: Any], + let responseValue = responseDict["success"] as? Bool else { success(false) return } @@ -35,7 +36,7 @@ public class JetpackScanServiceRemote: ServiceRemoteWordPressComREST { public func getScanForSite(_ siteID: Int, success: @escaping(JetpackScan) -> Void, failure: @escaping(Error) -> Void) { let path = self.scanPath(for: siteID) - wordPressComRestApi.GET(path, parameters: nil, success: { (response, _) in + wordPressComRESTAPI.get(path, parameters: nil, success: { (response, _) in do { let decoder = JSONDecoder.apiDecoder let data = try JSONSerialization.data(withJSONObject: response, options: []) @@ -67,7 +68,7 @@ public class JetpackScanServiceRemote: ServiceRemoteWordPressComREST { let path = self.path(forEndpoint: "sites/\(siteID)/alerts/fix", withVersion: ._2_0) let parameters = ["threat_ids": threats.map { $0.id as AnyObject }] as [String: AnyObject] - wordPressComRestApi.POST(path, parameters: parameters, success: { (response, _) in + wordPressComRESTAPI.post(path, parameters: parameters, success: { (response, _) in do { let decoder = JSONDecoder.apiDecoder let data = try JSONSerialization.data(withJSONObject: response, options: []) @@ -101,7 +102,7 @@ public class JetpackScanServiceRemote: ServiceRemoteWordPressComREST { let path = self.path(forEndpoint: "sites/\(siteID)/alerts/\(threat.id)", withVersion: ._2_0) let parameters = ["ignore": true] as [String: AnyObject] - wordPressComRestApi.POST(path, parameters: parameters, success: { (_, _) in + wordPressComRESTAPI.post(path, parameters: parameters, success: { (_, _) in success() }, failure: { (error, _) in failure(error) @@ -113,7 +114,7 @@ public class JetpackScanServiceRemote: ServiceRemoteWordPressComREST { let path = self.path(forEndpoint: "sites/\(siteID)/alerts/fix", withVersion: ._2_0) let parameters = ["threat_ids": threats.map { $0.id as AnyObject }] as [String: AnyObject] - wordPressComRestApi.GET(path, parameters: parameters, success: { (response, _) in + wordPressComRESTAPI.get(path, parameters: parameters, success: { (response, _) in do { let decoder = JSONDecoder.apiDecoder let data = try JSONSerialization.data(withJSONObject: response, options: []) @@ -132,7 +133,7 @@ public class JetpackScanServiceRemote: ServiceRemoteWordPressComREST { public func getHistoryForSite(_ siteID: Int, success: @escaping(JetpackScanHistory) -> Void, failure: @escaping(Error) -> Void) { let path = scanPath(for: siteID, with: "history") - wordPressComRestApi.GET(path, parameters: nil, success: { (response, _) in + wordPressComRESTAPI.get(path, parameters: nil, success: { (response, _) in do { let decoder = JSONDecoder.apiDecoder let data = try JSONSerialization.data(withJSONObject: response, options: []) From ffe285d7af01becabd2e2ca9bf60cf9f3a4eebc4 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 19:56:47 +1100 Subject: [PATCH 13/35] Use `WordPressComRESTAPIInterfacing` in `JetpackServiceRemote` --- .../Services/JetpackServiceRemote.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Sources/WordPressKit/Services/JetpackServiceRemote.swift b/Sources/WordPressKit/Services/JetpackServiceRemote.swift index cb39d9405..b84d62f78 100644 --- a/Sources/WordPressKit/Services/JetpackServiceRemote.swift +++ b/Sources/WordPressKit/Services/JetpackServiceRemote.swift @@ -47,16 +47,16 @@ public class JetpackServiceRemote: ServiceRemoteWordPressComREST { failure: @escaping (Error?) -> Void) { let path = self.path(forEndpoint: "connect/site-info", withVersion: ._1_0) let parameters = ["url": url.absoluteString as AnyObject] - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: parameters, - success: { [weak self] (response: AnyObject, _: HTTPURLResponse?) in + success: { [weak self] response, _ in do { let hasJetpack = try self?.hasJetpackMapping(object: response) success(hasJetpack ?? false) } catch { failure(error) } - }) { (error: NSError, _: HTTPURLResponse?) in + }) { error, _ in failure(error) } } @@ -74,16 +74,17 @@ public class JetpackServiceRemote: ServiceRemoteWordPressComREST { let parameters = ["user": username, "password": password] - wordPressComRestApi.POST(requestUrl, + wordPressComRESTAPI.post(requestUrl, parameters: parameters as [String: AnyObject], - success: { (response: AnyObject, _: HTTPURLResponse?) in + success: { response, _ in if let response = response as? [String: Bool], let success = response[Constants.status] { completion(success, nil) } else { completion(false, JetpackInstallError(type: .installResponseError)) } - }) { (error: NSError, _: HTTPURLResponse?) in + }) { error, _ in + let error = error as NSError let key = error.userInfo[WordPressComRestApi.ErrorKeyErrorCode] as? String let jetpackError = JetpackInstallError(title: error.localizedDescription, code: error.code, @@ -99,7 +100,7 @@ public class JetpackServiceRemote: ServiceRemoteWordPressComREST { } private extension JetpackServiceRemote { - func hasJetpackMapping(object: AnyObject) throws -> Bool { + func hasJetpackMapping(object: Any) throws -> Bool { guard let response = object as? [String: AnyObject], let hasJetpack = response[Constants.hasJetpack] as? NSNumber else { throw ResponseError.decodingFailed From 9990bc84aba7b2a1222ab0c37a0305f753eb0673 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:01:12 +1100 Subject: [PATCH 14/35] Use `WordPressComRESTAPIInterfacing` in `JetpackProxyServiceRemote` --- Sources/WordPressKit/Services/JetpackProxyServiceRemote.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/WordPressKit/Services/JetpackProxyServiceRemote.swift b/Sources/WordPressKit/Services/JetpackProxyServiceRemote.swift index efcaadba4..1a8c57ca7 100644 --- a/Sources/WordPressKit/Services/JetpackProxyServiceRemote.swift +++ b/Sources/WordPressKit/Services/JetpackProxyServiceRemote.swift @@ -26,7 +26,7 @@ public class JetpackProxyServiceRemote: ServiceRemoteWordPressComREST { method: DotComMethod, parameters: [String: AnyHashable] = [:], locale: String? = nil, - completion: @escaping (Result) -> Void) -> Progress? { + completion: @escaping (Result) -> Void) -> Progress? { let urlString = self.path(forEndpoint: "jetpack-blogs/\(siteID)/rest-api", withVersion: ._1_1) // Construct the request parameters to be forwarded to the actual endpoint. @@ -49,7 +49,7 @@ public class JetpackProxyServiceRemote: ServiceRemoteWordPressComREST { requestParams["locale"] = locale } - return wordPressComRestApi.POST(urlString, parameters: requestParams as [String: AnyObject]) { response, _ in + return wordPressComRESTAPI.post(urlString, parameters: requestParams) { response, _ in completion(.success(response)) } failure: { error, _ in completion(.failure(error)) From 6363aa0ab90c8e05557bcf18126a7dead41d26ec Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:05:28 +1100 Subject: [PATCH 15/35] Use `WordPressComRESTAPIInterfacing` in `NotificationSettingsServiceRemote` --- .../NotificationSettingsServiceRemote.swift | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Sources/WordPressKit/Services/NotificationSettingsServiceRemote.swift b/Sources/WordPressKit/Services/NotificationSettingsServiceRemote.swift index ded72e5cb..5e33682a9 100644 --- a/Sources/WordPressKit/Services/NotificationSettingsServiceRemote.swift +++ b/Sources/WordPressKit/Services/NotificationSettingsServiceRemote.swift @@ -25,14 +25,14 @@ open class NotificationSettingsServiceRemote: ServiceRemoteWordPressComREST { let path = String(format: "me/notifications/settings/?device_id=%@", deviceId) let requestUrl = self.path(forEndpoint: path, withVersion: ._1_1) - wordPressComRestApi.GET(requestUrl, + wordPressComRESTAPI.get(requestUrl, parameters: nil, - success: { (response: AnyObject, _: HTTPURLResponse?) -> Void in + success: { response, _ in let settings = RemoteNotificationSettings.fromDictionary(response as? NSDictionary) success?(settings) }, - failure: { (error: NSError, _: HTTPURLResponse?) -> Void in - failure?(error) + failure: { error, _ in + failure?(error as NSError) }) } @@ -49,13 +49,13 @@ open class NotificationSettingsServiceRemote: ServiceRemoteWordPressComREST { let parameters = settings - wordPressComRestApi.POST(requestUrl, + wordPressComRESTAPI.post(requestUrl, parameters: parameters, - success: { (_: AnyObject, _: HTTPURLResponse?) -> Void in + success: { _, _ in success?() }, - failure: { (error: NSError, _: HTTPURLResponse?) -> Void in - failure?(error) + failure: { error, _ in + failure?(error as NSError) }) } @@ -83,9 +83,9 @@ open class NotificationSettingsServiceRemote: ServiceRemoteWordPressComREST { "device_uuid": device.wordPressIdentifier() ] - wordPressComRestApi.POST(requestUrl, - parameters: parameters as [String: AnyObject]?, - success: { (response: AnyObject, _: HTTPURLResponse?) -> Void in + wordPressComRESTAPI.post(requestUrl, + parameters: parameters as [String: Any], + success: { response, _ in if let responseDict = response as? NSDictionary, let rawDeviceId = responseDict.object(forKey: "ID") { // Failsafe: Make sure deviceId is always a string @@ -98,8 +98,8 @@ open class NotificationSettingsServiceRemote: ServiceRemoteWordPressComREST { failure?(outerError) } }, - failure: { (error: NSError, _: HTTPURLResponse?) -> Void in - failure?(error) + failure: { error, _ in + failure?(error as NSError) }) } @@ -114,13 +114,13 @@ open class NotificationSettingsServiceRemote: ServiceRemoteWordPressComREST { let endpoint = String(format: "devices/%@/delete", deviceId) let requestUrl = path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.POST(requestUrl, + wordPressComRESTAPI.post(requestUrl, parameters: nil, - success: { (_: AnyObject!, _: HTTPURLResponse?) -> Void in + success: { _, _ in success?() }, - failure: { (error: NSError, _: HTTPURLResponse?) -> Void in - failure?(error) + failure: { error, _ in + failure?(error as NSError) }) } From 6e93cbd5d67c9d3057e1ba3d3d4c0bf5a58feabf Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:06:35 +1100 Subject: [PATCH 16/35] Use `WordPressComRESTAPIInterfacing` in `NotificationSyncServiceRemote` --- .../Services/NotificationSyncServiceRemote.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/WordPressKit/Services/NotificationSyncServiceRemote.swift b/Sources/WordPressKit/Services/NotificationSyncServiceRemote.swift index 78adf6124..53c8c3889 100644 --- a/Sources/WordPressKit/Services/NotificationSyncServiceRemote.swift +++ b/Sources/WordPressKit/Services/NotificationSyncServiceRemote.swift @@ -88,7 +88,7 @@ public class NotificationSyncServiceRemote: ServiceRemoteWordPressComREST { let parameters = ["counts": notifications] - wordPressComRestApi.POST(requestUrl, parameters: parameters as [String: AnyObject]?, success: { (response, _) in + wordPressComRESTAPI.post(requestUrl, parameters: parameters as [String: AnyObject]?, success: { (response, _) in let error = self.errorFromResponse(response) completion(error) @@ -111,7 +111,7 @@ public class NotificationSyncServiceRemote: ServiceRemoteWordPressComREST { "time": timestamp ] - wordPressComRestApi.POST(requestUrl, parameters: parameters as [String: AnyObject]?, success: { (response, _) in + wordPressComRESTAPI.post(requestUrl, parameters: parameters as [String: AnyObject]?, success: { (response, _) in let error = self.errorFromResponse(response) completion(error) @@ -131,7 +131,7 @@ private extension NotificationSyncServiceRemote { /// /// - Returns: SyncError.failed whenever the success field is either missing, or set to false. /// - func errorFromResponse(_ response: AnyObject) -> Error? { + func errorFromResponse(_ response: Any) -> Error? { let document = response as? [String: AnyObject] let success = document?["success"] as? Bool guard success != true else { @@ -166,7 +166,7 @@ private extension NotificationSyncServiceRemote { parameters["fields"] = fields as AnyObject? } - wordPressComRestApi.GET(requestUrl, parameters: parameters, success: { response, _ in + wordPressComRESTAPI.get(requestUrl, parameters: parameters, success: { response, _ in let document = response as? [String: AnyObject] let notes = document?["notes"] as? [[String: AnyObject]] let parsed = notes?.compactMap { RemoteNotification(document: $0) } From 8c49c9fd24c69bbfa2572d8a7665f4e018884a9e Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:07:29 +1100 Subject: [PATCH 17/35] Use `WordPressComRESTAPIInterfacing` in `PeopleServiceRemote` --- .../Services/PeopleServiceRemote.swift | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Sources/WordPressKit/Services/PeopleServiceRemote.swift b/Sources/WordPressKit/Services/PeopleServiceRemote.swift index 3e41390e7..dd7d62af4 100644 --- a/Sources/WordPressKit/Services/PeopleServiceRemote.swift +++ b/Sources/WordPressKit/Services/PeopleServiceRemote.swift @@ -40,7 +40,7 @@ public class PeopleServiceRemote: ServiceRemoteWordPressComREST { "fields": "ID, nice_name, first_name, last_name, name, avatar_URL, roles, is_super_admin, linked_user_ID" as AnyObject ] - wordPressComRestApi.GET(path, parameters: parameters, success: { (responseObject, _) in + wordPressComRESTAPI.get(path, parameters: parameters, success: { (responseObject, _) in guard let response = responseObject as? [String: AnyObject], let users = response["users"] as? [[String: AnyObject]], let people = try? self.peopleFromResponse(users, siteID: siteID, type: User.self) else { @@ -81,7 +81,7 @@ public class PeopleServiceRemote: ServiceRemoteWordPressComREST { "fields": "ID, nice_name, first_name, last_name, name, avatar_URL" as AnyObject ] - wordPressComRestApi.GET(path, parameters: parameters, success: { (responseObject, _) in + wordPressComRESTAPI.get(path, parameters: parameters, success: { (responseObject, _) in guard let response = responseObject as? [String: AnyObject], let followers = response["users"] as? [[String: AnyObject]], let people = try? self.peopleFromResponse(followers, siteID: siteID, type: Follower.self) else { @@ -119,7 +119,7 @@ public class PeopleServiceRemote: ServiceRemoteWordPressComREST { "type": "email" as AnyObject ] - wordPressComRestApi.GET(path, parameters: parameters, success: { responseObject, _ in + wordPressComRESTAPI.get(path, parameters: parameters, success: { responseObject, _ in guard let response = responseObject as? [String: AnyObject], let subscribers = response["subscribers"] as? [[String: AnyObject]], let totalPages = response["pages"] as? Int else { @@ -158,7 +158,7 @@ public class PeopleServiceRemote: ServiceRemoteWordPressComREST { "page": pageNumber as AnyObject ] - wordPressComRestApi.GET(path, parameters: parameters, success: { responseObject, _ in + wordPressComRESTAPI.get(path, parameters: parameters, success: { responseObject, _ in guard let response = responseObject as? [String: AnyObject], let viewers = response["viewers"] as? [[String: AnyObject]], let people = try? self.peopleFromResponse(viewers, siteID: siteID, type: Viewer.self) else { @@ -194,7 +194,7 @@ public class PeopleServiceRemote: ServiceRemoteWordPressComREST { let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) let parameters = ["roles": [newRole]] - wordPressComRestApi.POST(path, + wordPressComRESTAPI.post(path, parameters: parameters as [String: AnyObject]?, success: { (responseObject, _) in guard let response = responseObject as? [String: AnyObject], @@ -233,7 +233,7 @@ public class PeopleServiceRemote: ServiceRemoteWordPressComREST { parameters["reassign"] = reassignID as AnyObject? } - wordPressComRestApi.POST(path, parameters: nil, success: { (_, _) in + wordPressComRESTAPI.post(path, parameters: nil, success: { (_, _) in success?() }, failure: { (error, _) in failure?(error) @@ -255,7 +255,7 @@ public class PeopleServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/followers/\(userID)/delete" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.POST(path, parameters: nil, success: { (_, _) in + wordPressComRESTAPI.post(path, parameters: nil, success: { (_, _) in success?() }, failure: { (error, _) in failure?(error) @@ -277,7 +277,7 @@ public class PeopleServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/email-followers/\(userID)/delete" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.POST(path, parameters: nil, success: { _, _ in + wordPressComRESTAPI.post(path, parameters: nil, success: { _, _ in success?() }, failure: { error, _ in failure?(error) @@ -299,7 +299,7 @@ public class PeopleServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/viewers/\(userID)/delete" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.POST(path, parameters: nil, success: { (_, _) in + wordPressComRESTAPI.post(path, parameters: nil, success: { (_, _) in success?() }, failure: { (error, _) in failure?(error) @@ -321,7 +321,7 @@ public class PeopleServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/roles" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.GET(path, parameters: nil, success: { (responseObject, _) in + wordPressComRESTAPI.get(path, parameters: nil, success: { (responseObject, _) in guard let response = responseObject as? [String: AnyObject], let roles = try? self.rolesFromResponse(response) else { failure?(ResponseError.decodingFailure) @@ -356,7 +356,7 @@ public class PeopleServiceRemote: ServiceRemoteWordPressComREST { "role": role ] - wordPressComRestApi.POST(path, parameters: parameters as [String: AnyObject]?, success: { (responseObject, _) in + wordPressComRESTAPI.post(path, parameters: parameters as [String: AnyObject]?, success: { (responseObject, _) in guard let responseDict = responseObject as? [String: AnyObject] else { failure(ResponseError.decodingFailure) return @@ -399,7 +399,7 @@ public class PeopleServiceRemote: ServiceRemoteWordPressComREST { "message": message ] - wordPressComRestApi.POST(path, parameters: parameters as [String: AnyObject]?, success: { (responseObject, _) in + wordPressComRESTAPI.post(path, parameters: parameters as [String: AnyObject]?, success: { (responseObject, _) in guard let responseDict = responseObject as? [String: AnyObject] else { failure(ResponseError.decodingFailure) return @@ -435,7 +435,7 @@ public class PeopleServiceRemote: ServiceRemoteWordPressComREST { "number": 100 ] as [String: AnyObject] - wordPressComRestApi.GET(path, parameters: params, success: { (responseObject, _) in + wordPressComRESTAPI.get(path, parameters: params, success: { (responseObject, _) in guard let responseDict = responseObject as? [String: AnyObject] else { failure(ResponseError.decodingFailure) return @@ -467,7 +467,7 @@ public class PeopleServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/invites/links/generate" let path = self.path(forEndpoint: endpoint, withVersion: ._2_0) - wordPressComRestApi.POST(path, parameters: nil, success: { (responseObject, _) in + wordPressComRESTAPI.post(path, parameters: nil, success: { (responseObject, _) in guard let responseArray = responseObject as? [[String: AnyObject]] else { failure(ResponseError.decodingFailure) return @@ -498,7 +498,7 @@ public class PeopleServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/invites/links/disable" let path = self.path(forEndpoint: endpoint, withVersion: ._2_0) - wordPressComRestApi.POST(path, parameters: nil, success: { (responseObject, _) in + wordPressComRESTAPI.post(path, parameters: nil, success: { (responseObject, _) in let deletedKeys = responseObject as? [String] ?? [String]() success(deletedKeys) From 0d7b95c3a2948084a8398ff28bbd7a1c21cce2ad Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:09:35 +1100 Subject: [PATCH 18/35] Use `WordPressComRESTAPIInterfacing` in `PlanServiceRemote_ApiVersion1_3` --- .../Plans/PlanServiceRemote_ApiVersion1_3.swift | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Sources/WordPressKit/Services/Plans/PlanServiceRemote_ApiVersion1_3.swift b/Sources/WordPressKit/Services/Plans/PlanServiceRemote_ApiVersion1_3.swift index 395f4c341..b9fefa665 100644 --- a/Sources/WordPressKit/Services/Plans/PlanServiceRemote_ApiVersion1_3.swift +++ b/Sources/WordPressKit/Services/Plans/PlanServiceRemote_ApiVersion1_3.swift @@ -11,11 +11,10 @@ import WordPressShared let endpoint = "sites/\(siteID)/plans" let path = self.path(forEndpoint: endpoint, withVersion: ._1_3) - wordPressComRestApi.GET( + wordPressComRESTAPI.get( path, parameters: nil, - success: { - response, _ in + success: { response, _ in do { try success(PlanServiceRemote_ApiVersion1_3.mapPlansResponse(response)) } catch { @@ -25,14 +24,13 @@ import WordPressShared failure(error) } }, - failure: { - error, _ in + failure: { error, _ in failure(error) } ) } - private static func mapPlansResponse(_ response: AnyObject) throws + private static func mapPlansResponse(_ response: Any) throws -> (activePlan: RemotePlan_ApiVersion1_3, availablePlans: [RemotePlan_ApiVersion1_3]) { guard let json = response as? [String: AnyObject] else { From a5cb6692413d6a66d85654925c9e06103a53481c Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:10:14 +1100 Subject: [PATCH 19/35] Use `WordPressComRESTAPIInterfacing` in `PlanServiceRemote` --- Sources/WordPressKit/Services/Plans/PlanServiceRemote.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/WordPressKit/Services/Plans/PlanServiceRemote.swift b/Sources/WordPressKit/Services/Plans/PlanServiceRemote.swift index b6a630ac8..d654f394b 100644 --- a/Sources/WordPressKit/Services/Plans/PlanServiceRemote.swift +++ b/Sources/WordPressKit/Services/Plans/PlanServiceRemote.swift @@ -23,7 +23,7 @@ public class PlanServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "plans/mobile" let path = self.path(forEndpoint: endpoint, withVersion: ._2_0) - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: nil, success: { response, _ in @@ -56,7 +56,7 @@ public class PlanServiceRemote: ServiceRemoteWordPressComREST { "locale": locale ] - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: parameters as [String: AnyObject], success: { response, _ in From 19f086d76bad3d967e82fc3c9f2eecb61d081b98 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:10:59 +1100 Subject: [PATCH 20/35] Use `WordPressComRESTAPIInterfacing` in `PluginServiceRemote` --- .../WordPressKit/Services/PluginServiceRemote.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/WordPressKit/Services/PluginServiceRemote.swift b/Sources/WordPressKit/Services/PluginServiceRemote.swift index 40ec6ada7..9661df9f4 100644 --- a/Sources/WordPressKit/Services/PluginServiceRemote.swift +++ b/Sources/WordPressKit/Services/PluginServiceRemote.swift @@ -11,7 +11,7 @@ public class PluginServiceRemote: ServiceRemoteWordPressComREST { public func getFeaturedPlugins(success: @escaping ([PluginDirectoryEntry]) -> Void, failure: @escaping (Error) -> Void) { let endpoint = "wpcom/v2/plugins/featured" - wordPressComRestApi.GET(endpoint, parameters: nil, success: { (responseObject, _) in + wordPressComRESTAPI.get(endpoint, parameters: nil, success: { (responseObject, _) in guard let response = responseObject as? [[String: AnyObject]] else { failure(ResponseError.decodingFailure) return @@ -33,7 +33,7 @@ public class PluginServiceRemote: ServiceRemoteWordPressComREST { let path = self.path(forEndpoint: endpoint, withVersion: ._1_2) let parameters = [String: AnyObject]() - wordPressComRestApi.GET(path, parameters: parameters, success: { (responseObject, _) in + wordPressComRESTAPI.get(path, parameters: parameters, success: { (responseObject, _) in guard let response = responseObject as? [String: AnyObject] else { failure(ResponseError.decodingFailure) return @@ -59,7 +59,7 @@ public class PluginServiceRemote: ServiceRemoteWordPressComREST { let path = self.path(forEndpoint: endpoint, withVersion: ._1_2) let parameters = [String: AnyObject]() - wordPressComRestApi.POST( + wordPressComRESTAPI.post( path, parameters: parameters, success: { (responseObject, _) in @@ -120,7 +120,7 @@ public class PluginServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/plugins/\(pluginSlug)/install" let path = self.path(forEndpoint: endpoint, withVersion: ._1_2) - wordPressComRestApi.POST( + wordPressComRESTAPI.post( path, parameters: nil, success: { responseObject, _ in @@ -148,7 +148,7 @@ public class PluginServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/plugins/\(escapedPluginID)/delete" let path = self.path(forEndpoint: endpoint, withVersion: ._1_2) - wordPressComRestApi.POST( + wordPressComRESTAPI.post( path, parameters: nil, success: { _, _ in @@ -167,7 +167,7 @@ public class PluginServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/plugins/\(escapedPluginID)" let path = self.path(forEndpoint: endpoint, withVersion: ._1_2) - wordPressComRestApi.POST( + wordPressComRESTAPI.post( path, parameters: parameters, success: { _, _ in From ea2d32776a826f76e6ec4c6613f429a1e77ddc3d Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:11:34 +1100 Subject: [PATCH 21/35] Use `WordPressComRESTAPIInterfacing` in `PostServiceRemoteREST+Revisions` --- .../Services/PostServiceRemoteREST+Revisions.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/WordPressKit/Services/PostServiceRemoteREST+Revisions.swift b/Sources/WordPressKit/Services/PostServiceRemoteREST+Revisions.swift index cb06c839a..0f9f61c06 100644 --- a/Sources/WordPressKit/Services/PostServiceRemoteREST+Revisions.swift +++ b/Sources/WordPressKit/Services/PostServiceRemoteREST+Revisions.swift @@ -7,7 +7,7 @@ public extension PostServiceRemoteREST { failure: @escaping (Error?) -> Void) { let endpoint = "sites/\(siteId)/post/\(postId)/diffs" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: nil, success: { (response, _) in do { @@ -31,7 +31,7 @@ public extension PostServiceRemoteREST { func getPostLatestRevisionID(for postId: NSNumber, success: @escaping (NSNumber?) -> Void, failure: @escaping (Error?) -> Void) { let endpoint = "sites/\(siteID)/posts/\(postId)" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.GET( + wordPressComRESTAPI.get( path, parameters: [ "context": "edit", From bf66e025831f362374a0a64a1d9bab3bfb32cd0a Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:12:15 +1100 Subject: [PATCH 22/35] Use `WordPressComRESTAPIInterfacing` in `ProductServiceRemote` --- Sources/WordPressKit/Services/ProductServiceRemote.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/WordPressKit/Services/ProductServiceRemote.swift b/Sources/WordPressKit/Services/ProductServiceRemote.swift index 8aff99828..cb9545fa1 100644 --- a/Sources/WordPressKit/Services/ProductServiceRemote.swift +++ b/Sources/WordPressKit/Services/ProductServiceRemote.swift @@ -41,7 +41,7 @@ open class ProductServiceRemote { open func getProducts(completion: @escaping (Result<[Product], Error>) -> Void) { let path = serviceRemote.path(forEndpoint: "products", withVersion: ._1_1) - serviceRemote.wordPressComRestApi.GET( + serviceRemote.wordPressComRESTAPI.get( path, parameters: [:], success: { responseProducts, _ in From e812c17e49fde46171aee56edbf12bc8797ca4ff Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:13:15 +1100 Subject: [PATCH 23/35] Use `WordPressComRESTAPIInterfacing` in `PushAuthenticationServiceRemote` --- .../Services/PushAuthenticationServiceRemote.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/WordPressKit/Services/PushAuthenticationServiceRemote.swift b/Sources/WordPressKit/Services/PushAuthenticationServiceRemote.swift index 8b094b85e..46324e854 100644 --- a/Sources/WordPressKit/Services/PushAuthenticationServiceRemote.swift +++ b/Sources/WordPressKit/Services/PushAuthenticationServiceRemote.swift @@ -20,11 +20,11 @@ import Foundation "push_token": token ] - wordPressComRestApi.POST(requestUrl, parameters: parameters as [String: AnyObject], - success: { (_: AnyObject, _: HTTPURLResponse?) -> Void in + wordPressComRESTAPI.post(requestUrl, parameters: parameters, + success: { _, _ in success?() }, - failure: { (_: NSError, _: HTTPURLResponse?) -> Void in + failure: { _, _ in failure?() }) } From 05efbaeeb7717a1878e8ba0f92f3ccbfbecc2c35 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:14:38 +1100 Subject: [PATCH 24/35] Use `WordPressComRESTAPIInterfacing` in `QRLoginServiceRemote` --- .../Services/QR Login/QRLoginServiceRemote.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/WordPressKit/Services/QR Login/QRLoginServiceRemote.swift b/Sources/WordPressKit/Services/QR Login/QRLoginServiceRemote.swift index ebe1f0a58..db2335278 100644 --- a/Sources/WordPressKit/Services/QR Login/QRLoginServiceRemote.swift +++ b/Sources/WordPressKit/Services/QR Login/QRLoginServiceRemote.swift @@ -7,7 +7,7 @@ open class QRLoginServiceRemote: ServiceRemoteWordPressComREST { let path = self.path(forEndpoint: "auth/qr-code/validate", withVersion: ._2_0) let parameters = [ "token": token, "data": data ] as [String: AnyObject] - wordPressComRestApi.POST(path, parameters: parameters as [String: AnyObject], success: { (response, _) in + wordPressComRESTAPI.post(path, parameters: parameters as [String: AnyObject], success: { (response, _) in do { let decoder = JSONDecoder.apiDecoder let data = try JSONSerialization.data(withJSONObject: response, options: []) @@ -33,8 +33,9 @@ open class QRLoginServiceRemote: ServiceRemoteWordPressComREST { let path = self.path(forEndpoint: "auth/qr-code/authenticate", withVersion: ._2_0) let parameters = [ "token": token, "data": data ] as [String: AnyObject] - wordPressComRestApi.POST(path, parameters: parameters, success: { (response, _) in - guard let authenticated = response["authenticated"] as? Bool else { + wordPressComRESTAPI.post(path, parameters: parameters, success: { (response, _) in + guard let responseDict = response as? [String: Any], + let authenticated = responseDict["authenticated"] as? Bool else { success(false) return } From 42326b33adc030e0c22854cf31771041ae91d085 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:17:21 +1100 Subject: [PATCH 25/35] Use `WordPressComRESTAPIInterfacing` in `ReaderPostServiceRemote` --- .../Services/ReaderPostServiceRemote+RelatedPosts.swift | 2 +- .../Services/ReaderPostServiceRemote+Subscriptions.swift | 8 ++++---- .../Services/ReaderPostServiceRemote+V2.swift | 9 +++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Sources/WordPressKit/Services/ReaderPostServiceRemote+RelatedPosts.swift b/Sources/WordPressKit/Services/ReaderPostServiceRemote+RelatedPosts.swift index d84b7be3c..b65851fd9 100644 --- a/Sources/WordPressKit/Services/ReaderPostServiceRemote+RelatedPosts.swift +++ b/Sources/WordPressKit/Services/ReaderPostServiceRemote+RelatedPosts.swift @@ -24,7 +24,7 @@ extension ReaderPostServiceRemote { "size_global": count ] as [String: AnyObject] - wordPressComRestApi.GET( + wordPressComRESTAPI.get( path, parameters: parameters, success: { (response, _) in diff --git a/Sources/WordPressKit/Services/ReaderPostServiceRemote+Subscriptions.swift b/Sources/WordPressKit/Services/ReaderPostServiceRemote+Subscriptions.swift index b63e244a2..9661cf479 100644 --- a/Sources/WordPressKit/Services/ReaderPostServiceRemote+Subscriptions.swift +++ b/Sources/WordPressKit/Services/ReaderPostServiceRemote+Subscriptions.swift @@ -28,7 +28,7 @@ extension ReaderPostServiceRemote { failure: @escaping (Error?) -> Void) { let path = self.path(forEndpoint: "sites/\(siteID)/posts/\(postID)/subscribers/mine", withVersion: ._1_1) - wordPressComRestApi.GET(path, parameters: nil, success: { response, _ in + wordPressComRESTAPI.get(path, parameters: nil, success: { response, _ in do { guard let responseObject = response as? [String: AnyObject], let isSubscribed = responseObject[Constants.isSubscribed] as? Bool else { @@ -58,7 +58,7 @@ extension ReaderPostServiceRemote { failure: @escaping (Error?) -> Void) { let path = self.path(forEndpoint: "sites/\(siteID)/posts/\(postID)/subscribers/new", withVersion: ._1_1) - wordPressComRestApi.POST(path, parameters: nil, success: { response, _ in + wordPressComRESTAPI.post(path, parameters: nil, success: { response, _ in do { guard let responseObject = response as? [String: AnyObject], let subscribed = responseObject[Constants.success] as? Bool else { @@ -88,7 +88,7 @@ extension ReaderPostServiceRemote { failure: @escaping (Error) -> Void) { let path = self.path(forEndpoint: "sites/\(siteID)/posts/\(postID)/subscribers/mine/delete", withVersion: ._1_1) - wordPressComRestApi.POST(path, parameters: nil, success: { response, _ in + wordPressComRESTAPI.post(path, parameters: nil, success: { response, _ in do { guard let responseObject = response as? [String: AnyObject], let unsubscribed = responseObject[Constants.success] as? Bool else { @@ -125,7 +125,7 @@ extension ReaderPostServiceRemote { failure: @escaping (Error?) -> Void) { let path = self.path(forEndpoint: "sites/\(siteID)/posts/\(postID)/subscribers/mine/update", withVersion: ._1_1) - wordPressComRestApi.POST(path, + wordPressComRESTAPI.post(path, parameters: [Constants.receiveNotificationsRequestKey: receiveNotifications] as [String: AnyObject], success: { response, _ in guard let responseObject = response as? [String: AnyObject], diff --git a/Sources/WordPressKit/Services/ReaderPostServiceRemote+V2.swift b/Sources/WordPressKit/Services/ReaderPostServiceRemote+V2.swift index 09bb80b98..d085ec2e0 100644 --- a/Sources/WordPressKit/Services/ReaderPostServiceRemote+V2.swift +++ b/Sources/WordPressKit/Services/ReaderPostServiceRemote+V2.swift @@ -15,11 +15,12 @@ extension ReaderPostServiceRemote { return } - wordPressComRestApi.GET(requestUrl, + wordPressComRESTAPI.get(requestUrl, parameters: nil, success: { response, _ in - let nextPageHandle = response["next_page_handle"] as? String - let postsDictionary = response["posts"] as? [[String: Any]] + let responseDict = response as? [String: Any] + let nextPageHandle = responseDict?["next_page_handle"] as? String + let postsDictionary = responseDict?["posts"] as? [[String: Any]] let posts = postsDictionary?.compactMap { RemoteReaderPost(dictionary: $0) } ?? [] success(posts, nextPageHandle) }, failure: { error, _ in @@ -99,7 +100,7 @@ extension ReaderPostServiceRemote { let path = self.path(forEndpoint: endpoint, withVersion: ._2_0) - wordPressComRestApi.POST(path, parameters: params, success: { (responseObject, _) in + wordPressComRESTAPI.post(path, parameters: params, success: { (responseObject, _) in guard let response = responseObject as? [String: AnyObject], let status = response["status"] as? Bool, status == true else { From ce3627a910379a8f3d916063bc6f1d606b9ae2f7 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:20:19 +1100 Subject: [PATCH 26/35] Use `WordPressComRESTAPIInterfacing` in `ReaderSiteSearchServiceRemote` --- .../WordPressKit/Services/ReaderSiteSearchServiceRemote.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/WordPressKit/Services/ReaderSiteSearchServiceRemote.swift b/Sources/WordPressKit/Services/ReaderSiteSearchServiceRemote.swift index dcba24cc0..ae0329692 100644 --- a/Sources/WordPressKit/Services/ReaderSiteSearchServiceRemote.swift +++ b/Sources/WordPressKit/Services/ReaderSiteSearchServiceRemote.swift @@ -34,7 +34,7 @@ public class ReaderSiteSearchServiceRemote: ServiceRemoteWordPressComREST { "q": query as AnyObject ] - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: parameters, success: { response, _ in do { @@ -53,7 +53,7 @@ public class ReaderSiteSearchServiceRemote: ServiceRemoteWordPressComREST { private extension ReaderSiteSearchServiceRemote { - func mapSearchResponse(_ response: AnyObject) throws -> ([ReaderFeed], Int) { + func mapSearchResponse(_ response: Any) throws -> ([ReaderFeed], Int) { do { let decoder = JSONDecoder() let data = try JSONSerialization.data(withJSONObject: response, options: []) From 3790cb7f78ecce3e3e2e013265c9c05d7bc50f26 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:21:03 +1100 Subject: [PATCH 27/35] Use `WordPressComRESTAPIInterfacing` in `ReaderTopicServiceRemote` --- .../Services/ReaderTopicServiceRemote+Interests.swift | 6 +++--- .../Services/ReaderTopicServiceRemote+Subscription.swift | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/WordPressKit/Services/ReaderTopicServiceRemote+Interests.swift b/Sources/WordPressKit/Services/ReaderTopicServiceRemote+Interests.swift index 1db13ef76..93d064f21 100644 --- a/Sources/WordPressKit/Services/ReaderTopicServiceRemote+Interests.swift +++ b/Sources/WordPressKit/Services/ReaderTopicServiceRemote+Interests.swift @@ -9,7 +9,7 @@ extension ReaderTopicServiceRemote { failure: @escaping (Error) -> Void) { let path = self.path(forEndpoint: "read/interests", withVersion: ._2_0) - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: nil, success: { response, _ in do { @@ -36,7 +36,7 @@ extension ReaderTopicServiceRemote { let path = self.path(forEndpoint: "read/tags/mine/new", withVersion: ._1_2) let parameters = ["tags": withSlugs] as [String: AnyObject] - wordPressComRestApi.POST(path, parameters: parameters, success: { _, _ in + wordPressComRESTAPI.post(path, parameters: parameters, success: { _, _ in success() }) { error, _ in WPKitLogError("Error fetching reader interests: \(error)") @@ -50,6 +50,6 @@ extension ReaderTopicServiceRemote { public func pathForTopic(slug: String) -> String { let endpoint = path(forEndpoint: "read/tags/\(slug)/posts", withVersion: ._1_2) - return wordPressComRestApi.baseURL.appendingPathComponent(endpoint).absoluteString + return wordPressComRESTAPI.baseURL.appendingPathComponent(endpoint).absoluteString } } diff --git a/Sources/WordPressKit/Services/ReaderTopicServiceRemote+Subscription.swift b/Sources/WordPressKit/Services/ReaderTopicServiceRemote+Subscription.swift index ff2491f6f..4e597b0dc 100644 --- a/Sources/WordPressKit/Services/ReaderTopicServiceRemote+Subscription.swift +++ b/Sources/WordPressKit/Services/ReaderTopicServiceRemote+Subscription.swift @@ -84,7 +84,7 @@ extension ReaderTopicServiceRemote { WPKitLogInfo("URL: \(urlRequest)") - wordPressComRestApi.POST(urlRequest, parameters: parameters, success: { (_, response) in + wordPressComRESTAPI.post(urlRequest, parameters: parameters, success: { (_, response) in WPKitLogInfo("Success \(response?.url?.absoluteString ?? "unknown url")") success() }) { (error, response) in From de8e0e23be978219ef5dce238d400920dc80ffa1 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:25:19 +1100 Subject: [PATCH 28/35] Use `WordPressComRESTAPIInterfacing` in `SharingServiceRemote` --- .../Services/SharingServiceRemote.swift | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/Sources/WordPressKit/Services/SharingServiceRemote.swift b/Sources/WordPressKit/Services/SharingServiceRemote.swift index f22e551ad..55433b6fb 100644 --- a/Sources/WordPressKit/Services/SharingServiceRemote.swift +++ b/Sources/WordPressKit/Services/SharingServiceRemote.swift @@ -44,7 +44,7 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) let params = ["type": "publicize"] - wordPressComRestApi.GET(path, parameters: params as [String: AnyObject]?) { responseObject, httpResponse in + wordPressComRESTAPI.get(path, parameters: params as [String: AnyObject]?) { responseObject, httpResponse in guard let responseDict = responseObject as? NSDictionary else { failure?(self.errorForUnexpectedResponse(httpResponse)) return @@ -53,7 +53,7 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { success?(self.remotePublicizeServicesFromDictionary(responseDict)) } failure: { error, _ in - failure?(error) + failure?(error as NSError) } } @@ -69,7 +69,7 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { let path = path(forEndpoint: "sites/\(siteID)/external-services", withVersion: ._2_0) let params = ["type": "publicize" as AnyObject] - wordPressComRestApi.GET( + wordPressComRESTAPI.get( path, parameters: params, success: { response, httpResponse in @@ -96,9 +96,9 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "me/keyring-connections" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: nil, - success: { (responseObject: AnyObject, httpResponse: HTTPURLResponse?) in + success: { responseObject, httpResponse in guard let onSuccess = success else { return } @@ -133,8 +133,8 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { onSuccess(keyringConnections) }, - failure: { (error: NSError, _: HTTPURLResponse?) in - failure?(error) + failure: { error, _ in + failure?(error as NSError) }) } @@ -170,9 +170,9 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/publicize-connections" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: nil, - success: { (responseObject: AnyObject, httpResponse: HTTPURLResponse?) in + success: { responseObject, httpResponse in guard let onSuccess = success else { return } @@ -190,8 +190,8 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { onSuccess(publicizeConnections) }, - failure: { (error: NSError, _: HTTPURLResponse?) in - failure?(error) + failure: { error, _ in + failure?(error as NSError) }) } @@ -218,9 +218,9 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { parameters[PublicizeConnectionParams.externalUserID] = userID as AnyObject? } - wordPressComRestApi.POST(path, + wordPressComRESTAPI.post(path, parameters: parameters, - success: { (responseObject: AnyObject, httpResponse: HTTPURLResponse?) in + success: { responseObject, httpResponse in guard let onSuccess = success else { return } @@ -233,8 +233,8 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { onSuccess(conn) }, - failure: { (error: NSError, _: HTTPURLResponse?) in - failure?(error) + failure: { error, _ in + failure?(error as NSError) }) } @@ -262,9 +262,9 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { PublicizeConnectionParams.externalUserID: externalUserID ] - wordPressComRestApi.POST(path, + wordPressComRESTAPI.post(path, parameters: parameters as [String: AnyObject]?, - success: { (responseObject: AnyObject, httpResponse: HTTPURLResponse?) in + success: { responseObject, httpResponse in guard let onSuccess = success else { return } @@ -277,8 +277,8 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { onSuccess(conn) }, - failure: { (error: NSError, _: HTTPURLResponse?) in - failure?(error) + failure: { error, _ in + failure?(error as NSError) }) } @@ -302,9 +302,9 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { PublicizeConnectionParams.shared: shared ] - wordPressComRestApi.POST(path, + wordPressComRESTAPI.post(path, parameters: parameters as [String: AnyObject]?, - success: { (responseObject: AnyObject, httpResponse: HTTPURLResponse?) in + success: { responseObject, httpResponse in guard let onSuccess = success else { return } @@ -317,8 +317,8 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { onSuccess(conn) }, - failure: { (error: NSError, _: HTTPURLResponse?) in - failure?(error) + failure: { error, _ in + failure?(error as NSError) }) } @@ -334,13 +334,13 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/publicize-connections/\(connectionID)/delete" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.POST(path, + wordPressComRESTAPI.post(path, parameters: nil, - success: { (_: AnyObject, _: HTTPURLResponse?) in + success: { _, _ in success?() }, - failure: { (error: NSError, _: HTTPURLResponse?) in - failure?(error) + failure: { error, _ in + failure?(error as NSError) }) } @@ -405,9 +405,9 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/sharing-buttons" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: nil, - success: { (responseObject: AnyObject, httpResponse: HTTPURLResponse?) in + success: { responseObject, httpResponse in guard let onSuccess = success else { return } @@ -422,8 +422,8 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { onSuccess(sharingButtons) }, - failure: { (error: NSError, _: HTTPURLResponse?) in - failure?(error) + failure: { error, _ in + failure?(error as NSError) }) } @@ -441,9 +441,9 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { let buttons = dictionariesFromRemoteSharingButtons(sharingButtons) let parameters = [SharingButtonsKeys.sharingButtons: buttons] - wordPressComRestApi.POST(path, + wordPressComRESTAPI.post(path, parameters: parameters as [String: AnyObject]?, - success: { (responseObject: AnyObject, httpResponse: HTTPURLResponse?) in + success: { responseObject, httpResponse in guard let onSuccess = success else { return } @@ -458,8 +458,8 @@ open class SharingServiceRemote: ServiceRemoteWordPressComREST { onSuccess(sharingButtons) }, - failure: { (error: NSError, _: HTTPURLResponse?) in - failure?(error) + failure: { error, _ in + failure?(error as NSError) }) } From b6f7d63b3226c2199896566cd7d8a9dea52aa320 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:27:58 +1100 Subject: [PATCH 29/35] Use `WordPressComRESTAPIInterfacing` in `SiteManagementServiceRemote` --- .../Services/SiteManagementServiceRemote.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/WordPressKit/Services/SiteManagementServiceRemote.swift b/Sources/WordPressKit/Services/SiteManagementServiceRemote.swift index c40e1e785..989b9ef4a 100644 --- a/Sources/WordPressKit/Services/SiteManagementServiceRemote.swift +++ b/Sources/WordPressKit/Services/SiteManagementServiceRemote.swift @@ -14,7 +14,7 @@ open class SiteManagementServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/delete" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.POST(path, + wordPressComRESTAPI.post(path, parameters: nil, success: { response, _ in guard let results = response as? [String: AnyObject] else { @@ -33,7 +33,7 @@ open class SiteManagementServiceRemote: ServiceRemoteWordPressComREST { success?() }, failure: { error, _ in - failure?(error) + failure?(error as NSError) }) } @@ -50,7 +50,7 @@ open class SiteManagementServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/exports/start" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.POST(path, + wordPressComRESTAPI.post(path, parameters: nil, success: { response, _ in guard let results = response as? [String: AnyObject] else { @@ -69,7 +69,7 @@ open class SiteManagementServiceRemote: ServiceRemoteWordPressComREST { success?() }, failure: { error, _ in - failure?(error) + failure?(error as NSError) }) } @@ -84,7 +84,7 @@ open class SiteManagementServiceRemote: ServiceRemoteWordPressComREST { let endpoint = "sites/\(siteID)/purchases" let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: nil, success: { response, _ in guard let results = response as? [SitePurchase] else { @@ -96,7 +96,7 @@ open class SiteManagementServiceRemote: ServiceRemoteWordPressComREST { success?(actives) }, failure: { error, _ in - failure?(error) + failure?(error as NSError) }) } @@ -112,13 +112,13 @@ open class SiteManagementServiceRemote: ServiceRemoteWordPressComREST { let path = self.path(forEndpoint: endpoint, withVersion: ._1_1) let parameters = ["variant": "next-steps"] as [String: AnyObject] - wordPressComRestApi.POST(path, + wordPressComRESTAPI.post(path, parameters: parameters, success: { _, _ in success?() }, failure: { error, _ in - failure?(error) + failure?(error as NSError) }) } From 2c1aea3ed0de0c0124d92d759a212ab9c73c8dfd Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:28:50 +1100 Subject: [PATCH 30/35] Use `WordPressComRESTAPIInterfacing` in `StatsServiceRemoteV2` --- .../Services/StatsServiceRemoteV2.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Sources/WordPressKit/Services/StatsServiceRemoteV2.swift b/Sources/WordPressKit/Services/StatsServiceRemoteV2.swift index 3c1542536..8814a50eb 100644 --- a/Sources/WordPressKit/Services/StatsServiceRemoteV2.swift +++ b/Sources/WordPressKit/Services/StatsServiceRemoteV2.swift @@ -48,7 +48,7 @@ open class StatsServiceRemoteV2: ServiceRemoteWordPressComREST { let path = self.path(forEndpoint: "sites/\(siteID)/\(pathComponent)/", withVersion: ._1_1) - wordPressComRestApi.GET(path, parameters: properties, success: { (response, _) in + wordPressComRESTAPI.get(path, parameters: properties, success: { (response, _) in guard let jsonResponse = response as? [String: AnyObject], let insight = InsightType(jsonDictionary: jsonResponse) @@ -72,7 +72,7 @@ open class StatsServiceRemoteV2: ServiceRemoteWordPressComREST { success: @escaping () -> Void, failure: @escaping (Error) -> Void) { let path = pathForToggleSpamStateEndpoint(referrerDomain: referrerDomain, markAsSpam: !currentValue) - wordPressComRestApi.POST(path, parameters: nil, success: { object, _ in + wordPressComRESTAPI.post(path, parameters: nil, success: { object, _ in guard let dictionary = object as? [String: AnyObject], let response = MarkAsSpamResponse(dictionary: dictionary) else { @@ -117,7 +117,7 @@ open class StatsServiceRemoteV2: ServiceRemoteWordPressComREST { return val1 } - wordPressComRestApi.GET(path, parameters: properties, success: { [weak self] (response, _) in + wordPressComRESTAPI.get(path, parameters: properties, success: { [weak self] (response, _) in guard let self, let jsonResponse = response as? [String: AnyObject], @@ -153,7 +153,7 @@ open class StatsServiceRemoteV2: ServiceRemoteWordPressComREST { public func getDetails(forPostID postID: Int, completion: @escaping ((StatsPostDetails?, Error?) -> Void)) { let path = self.path(forEndpoint: "sites/\(siteID)/stats/post/\(postID)/", withVersion: ._1_1) - wordPressComRestApi.GET(path, parameters: [:], success: { (response, _) in + wordPressComRESTAPI.get(path, parameters: [:], success: { (response, _) in guard let jsonResponse = response as? [String: AnyObject], let postDetails = StatsPostDetails(jsonDictionary: jsonResponse) @@ -183,7 +183,7 @@ extension StatsServiceRemoteV2 { let pathComponent = StatsLastPostInsight.pathComponent let path = self.path(forEndpoint: "sites/\(siteID)/\(pathComponent)", withVersion: ._1_1) - wordPressComRestApi.GET(path, parameters: properties, success: { (response, _) in + wordPressComRESTAPI.get(path, parameters: properties, success: { (response, _) in guard let jsonResponse = response as? [String: AnyObject], let postCount = jsonResponse["found"] as? Int else { completion(nil, ResponseError.decodingFailure) @@ -224,7 +224,7 @@ extension StatsServiceRemoteV2 { let path = self.path(forEndpoint: "sites/\(siteID)/stats/post/\(postID)", withVersion: ._1_1) - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: parameters, success: { (response, _) in guard @@ -259,7 +259,7 @@ extension StatsServiceRemoteV2 { "after": ISO8601DateFormatter().string(from: startDate(for: period, endDate: endingOn)), "before": ISO8601DateFormatter().string(from: endingOn)] as [String: AnyObject] - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: properties, success: { (response, _) in guard From 75451ba07f59fd387f00ea58421f11eae8298a61 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:29:34 +1100 Subject: [PATCH 31/35] Use `WordPressComRESTAPIInterfacing` in `TimeZoneServiceRemote` --- Sources/WordPressKit/Services/TimeZoneServiceRemote.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/WordPressKit/Services/TimeZoneServiceRemote.swift b/Sources/WordPressKit/Services/TimeZoneServiceRemote.swift index 255bcda58..42e4239fa 100644 --- a/Sources/WordPressKit/Services/TimeZoneServiceRemote.swift +++ b/Sources/WordPressKit/Services/TimeZoneServiceRemote.swift @@ -9,7 +9,7 @@ public class TimeZoneServiceRemote: ServiceRemoteWordPressComREST { public func getTimezones(success: @escaping (([TimeZoneGroup]) -> Void), failure: @escaping ((Error) -> Void)) { let endpoint = "timezones" let path = self.path(forEndpoint: endpoint, withVersion: ._2_0) - wordPressComRestApi.GET(path, parameters: nil, success: { (response, _) in + wordPressComRESTAPI.get(path, parameters: nil, success: { (response, _) in do { let groups = try self.timezoneGroupsFromResponse(response) success(groups) @@ -23,7 +23,7 @@ public class TimeZoneServiceRemote: ServiceRemoteWordPressComREST { } private extension TimeZoneServiceRemote { - func timezoneGroupsFromResponse(_ response: AnyObject) throws -> [TimeZoneGroup] { + func timezoneGroupsFromResponse(_ response: Any) throws -> [TimeZoneGroup] { guard let response = response as? [String: Any], let timeZonesByContinent = response["timezones_by_continent"] as? [String: [[String: String]]], let manualUTCOffsets = response["manual_utc_offsets"] as? [[String: String]] else { From 8f1196b37ec04066ed6228db961cb1c236700027 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:30:16 +1100 Subject: [PATCH 32/35] Use `WordPressComRESTAPIInterfacing` in `TransactionsServiceRemote` --- .../WordPressKit/Services/TransactionsServiceRemote.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/WordPressKit/Services/TransactionsServiceRemote.swift b/Sources/WordPressKit/Services/TransactionsServiceRemote.swift index f34decc63..2ba8bf85f 100644 --- a/Sources/WordPressKit/Services/TransactionsServiceRemote.swift +++ b/Sources/WordPressKit/Services/TransactionsServiceRemote.swift @@ -16,7 +16,7 @@ import WordPressShared let endPoint = "me/transactions/supported-countries/" let servicePath = path(forEndpoint: endPoint, withVersion: ._1_1) - wordPressComRestApi.GET(servicePath, + wordPressComRESTAPI.get(servicePath, parameters: nil, success: { response, _ in @@ -69,7 +69,7 @@ import WordPressShared let parameters: [String: AnyObject] = ["temporary": (temporary ? "true" : "false") as AnyObject, "products": productsDictionary as AnyObject] - wordPressComRestApi.POST(urlPath, + wordPressComRESTAPI.post(urlPath, parameters: parameters, success: { (response, _) in @@ -104,7 +104,7 @@ import WordPressShared "cart": cart.jsonRepresentation() as AnyObject, "payment": paymentDict as AnyObject] - wordPressComRestApi.POST(urlPath, parameters: parameters, success: { (_, _) in + wordPressComRESTAPI.post(urlPath, parameters: parameters, success: { (_, _) in success() }) { (error, _) in failure(error) From 0285a53e4c62b591ce1087fa94a9cce0c500af66 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:32:24 +1100 Subject: [PATCH 33/35] Use `WordPressComRESTAPIInterfacing` in `AtomicSiteServiceRemote` --- Sources/WordPressKit/Services/AtomicSiteServiceRemote.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/WordPressKit/Services/AtomicSiteServiceRemote.swift b/Sources/WordPressKit/Services/AtomicSiteServiceRemote.swift index 3c7f970dd..c6eecfdf6 100644 --- a/Sources/WordPressKit/Services/AtomicSiteServiceRemote.swift +++ b/Sources/WordPressKit/Services/AtomicSiteServiceRemote.swift @@ -23,7 +23,7 @@ public final class AtomicSiteServiceRemote: ServiceRemoteWordPressComREST { if let scrollID { parameters["scroll_id"] = scrollID } - wordPressComRestApi.GET(path, parameters: parameters as [String: AnyObject]) { responseObject, httpResponse in + wordPressComRESTAPI.get(path, parameters: parameters as [String: AnyObject]) { responseObject, httpResponse in guard (200..<300).contains(httpResponse?.statusCode ?? 0), let data = (responseObject as? [String: AnyObject])?["data"], JSONSerialization.isValidJSONObject(data) else { @@ -67,7 +67,7 @@ public final class AtomicSiteServiceRemote: ServiceRemoteWordPressComREST { if let scrollID { parameters["scroll_id"] = scrollID } - wordPressComRestApi.GET(path, parameters: parameters as [String: AnyObject]) { responseObject, httpResponse in + wordPressComRESTAPI.get(path, parameters: parameters as [String: AnyObject]) { responseObject, httpResponse in guard (200..<300).contains(httpResponse?.statusCode ?? 0), let data = (responseObject as? [String: AnyObject])?["data"], JSONSerialization.isValidJSONObject(data) else { From 852e042aec47fbacc1715beed64bde7ab2d05195 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:32:57 +1100 Subject: [PATCH 34/35] Use `WordPressComRESTAPIInterfacing` in `WordPressComServiceRemote` --- .../Services/WordPressComServiceRemote+SiteCreation.swift | 4 ++-- .../Services/WordPressComServiceRemote+SiteSegments.swift | 4 ++-- .../Services/WordPressComServiceRemote+SiteVerticals.swift | 4 ++-- .../WordPressComServiceRemote+SiteVerticalsPrompt.swift | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/WordPressKit/Services/WordPressComServiceRemote+SiteCreation.swift b/Sources/WordPressKit/Services/WordPressComServiceRemote+SiteCreation.swift index b40f8723b..c65f80e5f 100644 --- a/Sources/WordPressKit/Services/WordPressComServiceRemote+SiteCreation.swift +++ b/Sources/WordPressKit/Services/WordPressComServiceRemote+SiteCreation.swift @@ -201,7 +201,7 @@ public extension WordPressComServiceRemote { return } - wordPressComRestApi.POST( + wordPressComRESTAPI.post( path, parameters: requestParameters, success: { [weak self] responseObject, httpResponse in @@ -247,7 +247,7 @@ private extension WordPressComServiceRemote { return requestParameters } - func decodeResponse(responseObject: AnyObject) throws -> SiteCreationResponse { + func decodeResponse(responseObject: Any) throws -> SiteCreationResponse { let decoder = JSONDecoder() diff --git a/Sources/WordPressKit/Services/WordPressComServiceRemote+SiteSegments.swift b/Sources/WordPressKit/Services/WordPressComServiceRemote+SiteSegments.swift index ecbaeaa0e..179d0a215 100644 --- a/Sources/WordPressKit/Services/WordPressComServiceRemote+SiteSegments.swift +++ b/Sources/WordPressKit/Services/WordPressComServiceRemote+SiteSegments.swift @@ -93,7 +93,7 @@ public extension WordPressComServiceRemote { let endpoint = "segments" let remotePath = path(forEndpoint: endpoint, withVersion: ._2_0) - wordPressComRestApi.GET( + wordPressComRESTAPI.get( remotePath, parameters: nil, success: { [weak self] responseObject, httpResponse in @@ -122,7 +122,7 @@ public extension WordPressComServiceRemote { // MARK: - Serialization support private extension WordPressComServiceRemote { - private func decodeResponse(responseObject: AnyObject) throws -> [SiteSegment] { + private func decodeResponse(responseObject: Any) throws -> [SiteSegment] { let decoder = JSONDecoder() let data = try JSONSerialization.data(withJSONObject: responseObject, options: []) let response = try decoder.decode([SiteSegment].self, from: data) diff --git a/Sources/WordPressKit/Services/WordPressComServiceRemote+SiteVerticals.swift b/Sources/WordPressKit/Services/WordPressComServiceRemote+SiteVerticals.swift index 27065aad4..81e54e857 100644 --- a/Sources/WordPressKit/Services/WordPressComServiceRemote+SiteVerticals.swift +++ b/Sources/WordPressKit/Services/WordPressComServiceRemote+SiteVerticals.swift @@ -92,7 +92,7 @@ public extension WordPressComServiceRemote { return } - wordPressComRestApi.GET( + wordPressComRESTAPI.get( path, parameters: requestParameters, success: { [weak self] responseObject, httpResponse in @@ -138,7 +138,7 @@ private extension WordPressComServiceRemote { return requestParameters } - func decodeResponse(responseObject: AnyObject) throws -> [SiteVertical] { + func decodeResponse(responseObject: Any) throws -> [SiteVertical] { let decoder = JSONDecoder() diff --git a/Sources/WordPressKit/Services/WordPressComServiceRemote+SiteVerticalsPrompt.swift b/Sources/WordPressKit/Services/WordPressComServiceRemote+SiteVerticalsPrompt.swift index 146b37750..bfee3bff8 100644 --- a/Sources/WordPressKit/Services/WordPressComServiceRemote+SiteVerticalsPrompt.swift +++ b/Sources/WordPressKit/Services/WordPressComServiceRemote+SiteVerticalsPrompt.swift @@ -45,7 +45,7 @@ public extension WordPressComServiceRemote { "segment_id": request as AnyObject ] - wordPressComRestApi.GET( + wordPressComRESTAPI.get( path, parameters: requestParameters, success: { [weak self] responseObject, httpResponse in @@ -74,7 +74,7 @@ public extension WordPressComServiceRemote { // private extension WordPressComServiceRemote { - func decodeResponse(responseObject: AnyObject) throws -> SiteVerticalsPrompt { + func decodeResponse(responseObject: Any) throws -> SiteVerticalsPrompt { let decoder = JSONDecoder() From cba707d591656edddd72a161556b632a33e63a6f Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 4 Apr 2024 20:36:25 +1100 Subject: [PATCH 35/35] Use `WordPressComRESTAPIInterfacing` in `RemoteConfigRemote` --- Sources/WordPressKit/Services/RemoteConfigRemote.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/WordPressKit/Services/RemoteConfigRemote.swift b/Sources/WordPressKit/Services/RemoteConfigRemote.swift index 29a92150f..4fdc076dd 100644 --- a/Sources/WordPressKit/Services/RemoteConfigRemote.swift +++ b/Sources/WordPressKit/Services/RemoteConfigRemote.swift @@ -14,7 +14,7 @@ open class RemoteConfigRemote: ServiceRemoteWordPressComREST { let endpoint = "mobile/remote-config" let path = self.path(forEndpoint: endpoint, withVersion: ._2_0) - wordPressComRestApi.GET(path, + wordPressComRESTAPI.get(path, parameters: nil, success: { response, _ in if let remoteConfigDictionary = response as? [String: Any] {