Mark read/unread structure.
This commit is contained in:
parent
dc60ebf1f8
commit
69c947bd65
|
@ -692,17 +692,80 @@ final class GoogleReaderCompatibleAPICaller: NSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
func createUnreadEntries(entries: [Int], completion: @escaping (Result<Void, Error>) -> Void) {
|
func createUnreadEntries(entries: [Int], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||||
// let callURL = GoogleReaderCompatibleBaseURL.appendingPathComponent("unread_entries.json")
|
guard let baseURL = APIBaseURL else {
|
||||||
// let request = URLRequest(url: callURL, credentials: credentials)
|
completion(.failure(CredentialsError.incompleteCredentials))
|
||||||
// let payload = GoogleReaderCompatibleUnreadEntry(unreadEntries: entries)
|
return
|
||||||
// transport.send(request: request, method: HTTPMethod.post, payload: payload, completion: completion)
|
}
|
||||||
|
|
||||||
|
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) {
|
func deleteUnreadEntries(entries: [Int], completion: @escaping (Result<Void, Error>) -> Void) {
|
||||||
// let callURL = GoogleReaderCompatibleBaseURL.appendingPathComponent("unread_entries.json")
|
guard let baseURL = APIBaseURL else {
|
||||||
// let request = URLRequest(url: callURL, credentials: credentials)
|
completion(.failure(CredentialsError.incompleteCredentials))
|
||||||
// let payload = GoogleReaderCompatibleUnreadEntry(unreadEntries: entries)
|
return
|
||||||
// transport.send(request: request, method: HTTPMethod.delete, payload: payload, completion: completion)
|
}
|
||||||
|
|
||||||
|
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) {
|
func retrieveStarredEntries(completion: @escaping (Result<[Int]?, Error>) -> Void) {
|
||||||
|
|
|
@ -453,6 +453,7 @@ final class GoogleReaderCompatibleAccountDelegate: AccountDelegate {
|
||||||
return account.update(articles, statusKey: statusKey, flag: flag)
|
return account.update(articles, statusKey: statusKey, flag: flag)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func accountDidInitialize(_ account: Account) {
|
func accountDidInitialize(_ account: Account) {
|
||||||
accountMetadata = account.metadata
|
accountMetadata = account.metadata
|
||||||
credentials = try? account.retrieveGoogleAuthCredentials()
|
credentials = try? account.retrieveGoogleAuthCredentials()
|
||||||
|
|
Loading…
Reference in New Issue