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

Commit 4d1d004

Browse files
committed
Add support for AL for WPCom free sites
1 parent c2ae16b commit 4d1d004

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

WordPressKit/Activity.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ public class RewindStatus {
164164
public let reason: String?
165165
public let restore: RestoreStatus?
166166

167+
internal init(state: State) {
168+
//FIXME: A hack to support free WPCom sites and Rewind. Should be obsolote as soon as the backend
169+
// stops returning 412's for those sites.
170+
self.state = state
171+
self.lastUpdated = Date()
172+
self.reason = nil
173+
self.restore = nil
174+
}
175+
167176
init(dictionary: [String: AnyObject]) throws {
168177
guard let rewindState = dictionary["state"] as? String else {
169178
throw Error.missingState

WordPressKit/ActivityServiceRemote.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,13 @@ public class ActivityServiceRemote: ServiceRemoteWordPressComREST {
8686
failure(ResponseError.decodingFailure)
8787
}
8888
}, failure: { error, _ in
89+
//FIXME: A hack to support free WPCom sites and Rewind. Should be obsolote as soon as the backend
90+
// stops returning 412's for those sites.
91+
if let error = error as? WordPressComRestApiError, error == WordPressComRestApiError.preconditionFailure {
92+
let status = RewindStatus(state: .unavailable)
93+
success(status)
94+
return
95+
}
8996
failure(error)
9097
})
9198
}

WordPressKit/WordPressComRestApi.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import Alamofire
2121
case responseSerializationFailed
2222
case tooManyRequests
2323
case unknown
24+
case preconditionFailure
2425
}
2526

2627
open class WordPressComRestApi: NSObject {
@@ -358,6 +359,13 @@ extension WordPressComRestApi {
358359
}
359360
return WordPressComRestApiError.unknown as NSError
360361
}
362+
363+
//FIXME: A hack to support free WPCom sites and Rewind. Should be obsolote as soon as the backend
364+
// stops returning 412's for those sites.
365+
if httpResponse.statusCode == 412, let code = responseDictionary["code"] as? String, code == "no_connected_jetpack" {
366+
return WordPressComRestApiError.preconditionFailure as NSError
367+
}
368+
361369
var errorDictionary: AnyObject? = responseDictionary as AnyObject?
362370
if let errorArray = responseDictionary["errors"] as? [AnyObject], errorArray.count > 0 {
363371
errorDictionary = errorArray.first

0 commit comments

Comments
 (0)