Mark read/unread structure.

This commit is contained in:
Jeremy Beker 2019-06-11 16:42:28 -04:00
parent dc60ebf1f8
commit 69c947bd65
No known key found for this signature in database
GPG Key ID: CD5EE767A4A34FD0
2 changed files with 72 additions and 8 deletions

View File

@ -692,17 +692,80 @@ final class GoogleReaderCompatibleAPICaller: NSObject {
}
func createUnreadEntries(entries: [Int], completion: @escaping (Result<Void, Error>) -> Void) {
// let callURL = GoogleReaderCompatibleBaseURL.appendingPathComponent("unread_entries.json")
// let request = URLRequest(url: callURL, credentials: credentials)
// let payload = GoogleReaderCompatibleUnreadEntry(unreadEntries: entries)
// transport.send(request: request, method: HTTPMethod.post, payload: payload, completion: completion)
guard let baseURL = APIBaseURL else {
completion(.failure(CredentialsError.incompleteCredentials))
return
}
self.requestAuthorizationToken(endpoint: baseURL) { (result) in
switch result {
case .success(let token):
// Do POST asking for data about all the new articles
var request = URLRequest(url: baseURL.appendingPathComponent("/reader/api/0/edit-tag"), credentials: self.credentials)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
// Get ids from above into hex representation of value
let idsToFetch = entries.map({ (idValue) -> String in
let idHexString = String(format: "%.16x", idValue)
return "i=\(idHexString)"
}).joined(separator:"&")
let postData = "T=\(token)&\(idsToFetch)&a=user/-/state/com.google/read".data(using: String.Encoding.utf8)
self.transport.send(request: request, method: HTTPMethod.post, payload: postData!, completion: { (result) in
switch result {
case .success:
completion(.success(()))
case .failure(let error):
completion(.failure(error))
}
})
case .failure(let error):
completion(.failure(error))
}
}
}
func deleteUnreadEntries(entries: [Int], completion: @escaping (Result<Void, Error>) -> Void) {
// let callURL = GoogleReaderCompatibleBaseURL.appendingPathComponent("unread_entries.json")
// let request = URLRequest(url: callURL, credentials: credentials)
// let payload = GoogleReaderCompatibleUnreadEntry(unreadEntries: entries)
// transport.send(request: request, method: HTTPMethod.delete, payload: payload, completion: completion)
guard let baseURL = APIBaseURL else {
completion(.failure(CredentialsError.incompleteCredentials))
return
}
self.requestAuthorizationToken(endpoint: baseURL) { (result) in
switch result {
case .success(let token):
// Do POST asking for data about all the new articles
var request = URLRequest(url: baseURL.appendingPathComponent("/reader/api/0/edit-tag"), credentials: self.credentials)
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
request.httpMethod = "POST"
// Get ids from above into hex representation of value
let idsToFetch = entries.map({ (idValue) -> String in
let idHexString = String(format: "%.16x", idValue)
return "i=\(idHexString)"
}).joined(separator:"&")
let postData = "T=\(token)&\(idsToFetch)&r=user/-/state/com.google/read".data(using: String.Encoding.utf8)
self.transport.send(request: request, method: HTTPMethod.post, payload: postData!, completion: { (result) in
switch result {
case .success:
completion(.success(()))
case .failure(let error):
completion(.failure(error))
}
})
case .failure(let error):
completion(.failure(error))
}
}
}
func retrieveStarredEntries(completion: @escaping (Result<[Int]?, Error>) -> Void) {

View File

@ -453,6 +453,7 @@ final class GoogleReaderCompatibleAccountDelegate: AccountDelegate {
return account.update(articles, statusKey: statusKey, flag: flag)
}
func accountDidInitialize(_ account: Account) {
accountMetadata = account.metadata
credentials = try? account.retrieveGoogleAuthCredentials()