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

Commit 9930ab2

Browse files
authored
Use WordPressComRESTAPIInterfacing for all Swift sync requests (#777)
2 parents 0d50348 + cba707d commit 9930ab2

File tree

42 files changed

+209
-204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+209
-204
lines changed

Sources/WordPressKit/Models/EditorSettings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public struct EditorSettings {
3636
}
3737

3838
extension EditorSettings {
39-
init(with response: AnyObject) throws {
39+
init(with response: Any) throws {
4040
guard let response = response as? [String: AnyObject] else {
4141
throw NSError(domain: NSURLErrorDomain, code: NSURLErrorBadServerResponse, userInfo: nil)
4242
}

Sources/WordPressKit/Services/ActivityServiceRemote.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ open class ActivityServiceRemote: ServiceRemoteWordPressComREST {
5959

6060
let finalPath = self.path(forEndpoint: endpoint, withVersion: ._2_0)
6161

62-
wordPressComRestApi.GET(finalPath,
62+
wordPressComRESTAPI.get(finalPath,
6363
parameters: nil,
6464
success: { response, _ in
6565
do {
@@ -105,7 +105,7 @@ open class ActivityServiceRemote: ServiceRemoteWordPressComREST {
105105
parameters["on"] = formatter.string(from: on) as AnyObject
106106
}
107107

108-
wordPressComRestApi.GET(path,
108+
wordPressComRESTAPI.get(path,
109109
parameters: parameters,
110110
success: { response, _ in
111111
do {
@@ -135,7 +135,7 @@ open class ActivityServiceRemote: ServiceRemoteWordPressComREST {
135135
let endpoint = "sites/\(siteID)/rewind"
136136
let path = self.path(forEndpoint: endpoint, withVersion: ._2_0)
137137

138-
wordPressComRestApi.GET(path,
138+
wordPressComRESTAPI.get(path,
139139
parameters: nil,
140140
success: { response, _ in
141141
guard let rewindStatus = response as? [String: AnyObject] else {
@@ -154,20 +154,25 @@ open class ActivityServiceRemote: ServiceRemoteWordPressComREST {
154154
}, failure: { error, _ in
155155
// FIXME: A hack to support free WPCom sites and Rewind. Should be obsolote as soon as the backend
156156
// stops returning 412's for those sites.
157-
if error.domain == WordPressComRestApiEndpointError.errorDomain, error.code == WordPressComRestApiErrorCode.preconditionFailure.rawValue {
158-
let status = RewindStatus(state: .unavailable)
159-
success(status)
157+
let nsError = error as NSError
158+
159+
guard nsError.domain == WordPressComRestApiEndpointError.errorDomain,
160+
nsError.code == WordPressComRestApiErrorCode.preconditionFailure.rawValue else {
161+
failure(error)
160162
return
161163
}
162-
failure(error)
164+
165+
let status = RewindStatus(state: .unavailable)
166+
success(status)
167+
return
163168
})
164169
}
165170

166171
}
167172

168173
private extension ActivityServiceRemote {
169174

170-
func mapActivitiesResponse(_ response: AnyObject) throws -> ([Activity], Int) {
175+
func mapActivitiesResponse(_ response: Any) throws -> ([Activity], Int) {
171176

172177
guard let json = response as? [String: AnyObject],
173178
let totalItems = json["totalItems"] as? Int else {
@@ -196,7 +201,7 @@ private extension ActivityServiceRemote {
196201
}
197202
}
198203

199-
func mapActivityGroupsResponse(_ response: AnyObject) throws -> ([ActivityGroup]) {
204+
func mapActivityGroupsResponse(_ response: Any) throws -> ([ActivityGroup]) {
200205
guard let json = response as? [String: AnyObject],
201206
let totalItems = json["totalItems"] as? Int, totalItems > 0 else {
202207
return []

Sources/WordPressKit/Services/AtomicAuthenticationServiceRemote.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Foundation
33
public class AtomicAuthenticationServiceRemote: ServiceRemoteWordPressComREST {
44

55
public enum ResponseError: Error {
6-
case responseIsNotADictionary(response: AnyObject)
6+
case responseIsNotADictionary(response: Any)
77
case decodingFailure(response: [String: AnyObject])
88
case couldNotInstantiateCookie(name: String, value: String, domain: String, path: String, expires: Date)
99
}
@@ -16,11 +16,9 @@ public class AtomicAuthenticationServiceRemote: ServiceRemoteWordPressComREST {
1616
let endpoint = "sites/\(siteID)/atomic-auth-proxy/read-access-cookies"
1717
let path = self.path(forEndpoint: endpoint, withVersion: ._2_0)
1818

19-
wordPressComRestApi.GET(path,
19+
wordPressComRESTAPI.get(path,
2020
parameters: nil,
21-
success: {
22-
responseObject, _ in
23-
21+
success: { responseObject, _ in
2422
do {
2523
let settings = try self.cookie(from: responseObject)
2624
success(settings)
@@ -39,7 +37,7 @@ public class AtomicAuthenticationServiceRemote: ServiceRemoteWordPressComREST {
3937
return Date(timeIntervalSince1970: TimeInterval(expiration))
4038
}
4139

42-
private func cookie(from responseObject: AnyObject) throws -> HTTPCookie {
40+
private func cookie(from responseObject: Any) throws -> HTTPCookie {
4341
guard let response = responseObject as? [String: AnyObject] else {
4442
let error = ResponseError.responseIsNotADictionary(response: responseObject)
4543
WPKitLogError("❗️Error: \(error)")

Sources/WordPressKit/Services/AtomicSiteServiceRemote.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public final class AtomicSiteServiceRemote: ServiceRemoteWordPressComREST {
2323
if let scrollID {
2424
parameters["scroll_id"] = scrollID
2525
}
26-
wordPressComRestApi.GET(path, parameters: parameters as [String: AnyObject]) { responseObject, httpResponse in
26+
wordPressComRESTAPI.get(path, parameters: parameters as [String: AnyObject]) { responseObject, httpResponse in
2727
guard (200..<300).contains(httpResponse?.statusCode ?? 0),
2828
let data = (responseObject as? [String: AnyObject])?["data"],
2929
JSONSerialization.isValidJSONObject(data) else {
@@ -67,7 +67,7 @@ public final class AtomicSiteServiceRemote: ServiceRemoteWordPressComREST {
6767
if let scrollID {
6868
parameters["scroll_id"] = scrollID
6969
}
70-
wordPressComRestApi.GET(path, parameters: parameters as [String: AnyObject]) { responseObject, httpResponse in
70+
wordPressComRESTAPI.get(path, parameters: parameters as [String: AnyObject]) { responseObject, httpResponse in
7171
guard (200..<300).contains(httpResponse?.statusCode ?? 0),
7272
let data = (responseObject as? [String: AnyObject])?["data"],
7373
JSONSerialization.isValidJSONObject(data) else {

Sources/WordPressKit/Services/AutomatedTransferService.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class AutomatedTransferService: ServiceRemoteWordPressComREST {
2626
let endpoint = "sites/\(siteID)/automated-transfers/eligibility"
2727
let path = self.path(forEndpoint: endpoint, withVersion: ._1_1)
2828

29-
wordPressComRestApi.GET(path, parameters: nil, success: { (responseObject, _) in
29+
wordPressComRESTAPI.get(path, parameters: nil, success: { (responseObject, _) in
3030
guard let response = responseObject as? [String: AnyObject] else {
3131
failure(.unknown)
3232
return
@@ -53,7 +53,7 @@ public class AutomatedTransferService: ServiceRemoteWordPressComREST {
5353
let path = self.path(forEndpoint: endpoint, withVersion: ._1_1)
5454
let payload = ["plugin": pluginSlug] as [String: AnyObject]
5555

56-
wordPressComRestApi.POST(path, parameters: payload, success: { (responseObject, _) in
56+
wordPressComRESTAPI.post(path, parameters: payload, success: { (responseObject, _) in
5757
guard let response = responseObject as? [String: AnyObject] else {
5858
failure(ResponseError.decodingFailure)
5959
return
@@ -80,7 +80,7 @@ public class AutomatedTransferService: ServiceRemoteWordPressComREST {
8080
let endpoint = "sites/\(siteID)/automated-transfers/status"
8181
let path = self.path(forEndpoint: endpoint, withVersion: ._1_1)
8282

83-
wordPressComRestApi.GET(path, parameters: nil, success: { (responseObject, _) in
83+
wordPressComRESTAPI.get(path, parameters: nil, success: { (responseObject, _) in
8484
guard let response = responseObject as? [String: AnyObject] else {
8585
failure(ResponseError.decodingFailure)
8686
return

Sources/WordPressKit/Services/BlogJetpackSettingsServiceRemote.swift

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ public class BlogJetpackSettingsServiceRemote: ServiceRemoteWordPressComREST {
1313

1414
let endpoint = "jetpack-blogs/\(siteID)/rest-api"
1515
let path = self.path(forEndpoint: endpoint, withVersion: ._1_1)
16-
let parameters = ["path": "/jetpack/v4/settings"]
16+
let parameters: [String: Any] = ["path": "/jetpack/v4/settings"]
1717

18-
wordPressComRestApi.GET(path,
19-
parameters: parameters as [String: AnyObject]?,
20-
success: {
21-
response, _ in
22-
guard let results = response["data"] as? [String: AnyObject],
18+
wordPressComRESTAPI.get(path,
19+
parameters: parameters,
20+
success: { response, _ in
21+
guard let responseDict = response as? [String: Any],
22+
let results = responseDict["data"] as? [String: AnyObject],
2323
let remoteSettings = try? self.remoteJetpackSettingsFromDictionary(results) else {
2424
failure(ResponseError.decodingFailure)
2525
return
@@ -38,11 +38,11 @@ public class BlogJetpackSettingsServiceRemote: ServiceRemoteWordPressComREST {
3838
let endpoint = "jetpack-blogs/\(siteID)"
3939
let path = self.path(forEndpoint: endpoint, withVersion: ._1_1)
4040

41-
wordPressComRestApi.GET(path,
41+
wordPressComRESTAPI.get(path,
4242
parameters: nil,
43-
success: {
44-
response, _ in
45-
guard let results = response["settings"] as? [String: AnyObject],
43+
success: { response, _ in
44+
guard let responseDict = response as? [String: Any],
45+
let results = responseDict["settings"] as? [String: AnyObject],
4646
let remoteMonitorSettings = try? self.remoteJetpackMonitorSettingsFromDictionary(results) else {
4747
failure(ResponseError.decodingFailure)
4848
return
@@ -61,11 +61,11 @@ public class BlogJetpackSettingsServiceRemote: ServiceRemoteWordPressComREST {
6161
let endpoint = "sites/\(siteID)/jetpack/modules"
6262
let path = self.path(forEndpoint: endpoint, withVersion: ._1_1)
6363

64-
wordPressComRestApi.GET(path,
64+
wordPressComRESTAPI.get(path,
6565
parameters: nil,
66-
success: {
67-
response, _ in
68-
guard let modules = response["modules"] as? [[String: AnyObject]],
66+
success: { response, _ in
67+
guard let responseDict = response as? [String: Any],
68+
let modules = responseDict["modules"] as? [[String: AnyObject]],
6969
let remoteModulesSettings = try? self.remoteJetpackModulesSettingsFromArray(modules) else {
7070
failure(ResponseError.decodingFailure)
7171
return
@@ -94,7 +94,7 @@ public class BlogJetpackSettingsServiceRemote: ServiceRemoteWordPressComREST {
9494
"body": jSONBody,
9595
"json": true] as [String: AnyObject]
9696

97-
wordPressComRestApi.POST(path,
97+
wordPressComRESTAPI.post(path,
9898
parameters: parameters,
9999
success: {
100100
_, _ in
@@ -113,7 +113,7 @@ public class BlogJetpackSettingsServiceRemote: ServiceRemoteWordPressComREST {
113113
let path = self.path(forEndpoint: endpoint, withVersion: ._1_1)
114114
let parameters = dictionaryFromJetpackMonitorSettings(settings)
115115

116-
wordPressComRestApi.POST(path,
116+
wordPressComRESTAPI.post(path,
117117
parameters: parameters,
118118
success: {
119119
_, _ in
@@ -131,7 +131,7 @@ public class BlogJetpackSettingsServiceRemote: ServiceRemoteWordPressComREST {
131131
let path = self.path(forEndpoint: endpoint, withVersion: ._1_1)
132132
let parameters = [ModuleOptionKeys.active: active]
133133

134-
wordPressComRestApi.POST(path,
134+
wordPressComRESTAPI.post(path,
135135
parameters: parameters as [String: AnyObject],
136136
success: {
137137
_, _ in
@@ -148,7 +148,7 @@ public class BlogJetpackSettingsServiceRemote: ServiceRemoteWordPressComREST {
148148
let endpoint = "jetpack-blogs/\(siteID)/mine/delete"
149149
let path = self.path(forEndpoint: endpoint, withVersion: ._1_1)
150150

151-
wordPressComRestApi.POST(path,
151+
wordPressComRESTAPI.post(path,
152152
parameters: nil,
153153
success: {
154154
_, _ in

Sources/WordPressKit/Services/BloggingPromptsServiceRemote.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ open class BloggingPromptsServiceRemote: ServiceRemoteWordPressComREST {
108108
return
109109
}
110110

111-
wordPressComRestApi.POST(path, parameters: parameters) { responseObject, _ in
111+
wordPressComRESTAPI.post(path, parameters: parameters) { responseObject, _ in
112112
do {
113113
let data = try JSONSerialization.data(withJSONObject: responseObject)
114114
let response = try JSONDecoder().decode(UpdateBloggingPromptsSettingsResponse.self, from: data)

Sources/WordPressKit/Services/DashboardServiceRemote.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ open class DashboardServiceRemote: ServiceRemoteWordPressComREST {
1717
failure(error)
1818
}
1919

20-
wordPressComRestApi.GET(requestUrl,
20+
wordPressComRESTAPI.get(requestUrl,
2121
parameters: params,
2222
success: { response, _ in
2323
guard let cards = response as? NSDictionary else {

Sources/WordPressKit/Services/EditorServiceRemote.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class EditorServiceRemote: ServiceRemoteWordPressComREST {
66
let endpoint = "sites/\(siteID)/gutenberg?platform=mobile&editor=\(editor.rawValue)"
77
let path = self.path(forEndpoint: endpoint, withVersion: ._2_0)
88

9-
wordPressComRestApi.POST(path, parameters: nil, success: { (responseObject, _) in
9+
wordPressComRESTAPI.post(path, parameters: nil, success: { (responseObject, _) in
1010
do {
1111
let settings = try EditorSettings(with: responseObject)
1212
success(settings)
@@ -28,7 +28,7 @@ public class EditorServiceRemote: ServiceRemoteWordPressComREST {
2828
"set_only_if_empty": setOnlyIfEmpty
2929
] as [String: AnyObject]
3030

31-
wordPressComRestApi.POST(path, parameters: parameters, success: { (responseObject, _) in
31+
wordPressComRESTAPI.post(path, parameters: parameters, success: { (responseObject, _) in
3232
guard let response = responseObject as? [String: String] else {
3333
if let boolResponse = responseObject as? Bool, boolResponse == false {
3434
return failure(EditorSettings.Error.badRequest)
@@ -51,7 +51,7 @@ public class EditorServiceRemote: ServiceRemoteWordPressComREST {
5151
let endpoint = "sites/\(siteID)/gutenberg"
5252
let path = self.path(forEndpoint: endpoint, withVersion: ._2_0)
5353

54-
wordPressComRestApi.GET(path, parameters: nil, success: { (responseObject, _) in
54+
wordPressComRESTAPI.get(path, parameters: nil, success: { (responseObject, _) in
5555
do {
5656
let settings = try EditorSettings(with: responseObject)
5757
success(settings)

Sources/WordPressKit/Services/FeatureFlagRemote.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ open class FeatureFlagRemote: ServiceRemoteWordPressComREST {
2121
return
2222
}
2323

24-
wordPressComRestApi.GET(path,
24+
wordPressComRESTAPI.get(path,
2525
parameters: dictionary,
2626
success: { response, _ in
2727

0 commit comments

Comments
 (0)