Refactor pinPost() to use template request

This commit is contained in:
Angelo Stavrow 2021-05-13 16:24:45 -04:00
parent cbf5559e5b
commit 4053280b36
No known key found for this signature in database
GPG Key ID: 1A49C7064E060EEE
1 changed files with 5 additions and 18 deletions

View File

@ -341,29 +341,16 @@ public class WFClient {
completion(.failure(error))
}
let dataTask = session.dataTask(with: request) { (data, response, error) in
// Something went wrong; return the error message.
if let error = error {
completion(.failure(error))
}
if let response = response as? HTTPURLResponse {
guard let data = data else { return }
// If we get a 200 OK, return the WFUser as success; if not, return a WFError as failure.
if response.statusCode == 200 {
post(with: request, expecting: 200) { result in
switch result {
case .success(_):
completion(.success(true))
} else {
// We didn't get a 200 OK, so return a WFError
guard let error = self.translateWFError(fromServerResponse: data) else { return }
case .failure(let error):
completion(.failure(error))
}
}
}
dataTask.resume()
}
/// Unpins a post from a collection.
///
/// Removes the post from a navigation item and puts it back on the blog itself. While the API endpoint can take an