Cleanup tag names, fetch subscriptions

This commit is contained in:
Jeremy Beker 2019-06-01 08:08:19 -04:00
parent 76d1daf122
commit a0efc7fda9
No known key found for this signature in database
GPG Key ID: CD5EE767A4A34FD0
4 changed files with 72 additions and 20 deletions

View File

@ -178,10 +178,10 @@ final class GoogleReaderCompatibleAPICaller: NSObject {
return
}
//let conditionalGet = accountMetadata?.conditionalGetInfo[ConditionalGetKeys.tags]
let request = URLRequest(url: callURL, credentials: credentials)
transport.send(request: request, resultType: GoogleReaderCompatibleTagWrapper.self) { result in
let conditionalGet = accountMetadata?.conditionalGetInfo[ConditionalGetKeys.tags]
let request = URLRequest(url: callURL, credentials: credentials, conditionalGet: conditionalGet)
transport.send(request: request, resultType: GoogleReaderCompatibleTagContainer.self) { result in
switch result {
case .success(let (response, wrapper)):
@ -222,17 +222,35 @@ final class GoogleReaderCompatibleAPICaller: NSObject {
}
func retrieveSubscriptions(completion: @escaping (Result<[GoogleReaderCompatibleSubscription]?, Error>) -> Void) {
guard let baseURL = APIBaseURL else {
completion(.failure(CredentialsError.incompleteCredentials))
return
}
// Add query string for getting JSON (probably should break this out as I will be doing it a lot)
guard var components = URLComponents(url: baseURL.appendingPathComponent("/reader/api/0/subscription/list"), resolvingAgainstBaseURL: false) else {
completion(.failure(TransportError.noURL))
return
}
components.queryItems = [
URLQueryItem(name: "output", value: "json")
]
guard let callURL = components.url else {
completion(.failure(TransportError.noURL))
return
}
let callURL = GoogleReaderCompatibleBaseURL.appendingPathComponent("subscriptions.json")
let conditionalGet = accountMetadata?.conditionalGetInfo[ConditionalGetKeys.subscriptions]
let request = URLRequest(url: callURL, credentials: credentials, conditionalGet: conditionalGet)
transport.send(request: request, resultType: [GoogleReaderCompatibleSubscription].self) { result in
transport.send(request: request, resultType: GoogleReaderCompatibleSubscriptionContainer.self) { result in
switch result {
case .success(let (response, subscriptions)):
case .success(let (response, container)):
self.storeConditionalGet(key: ConditionalGetKeys.subscriptions, headers: response.allHeaderFields)
completion(.success(subscriptions))
completion(.success(container?.subscriptions))
case .failure(let error):
completion(.failure(error))
}

View File

@ -542,9 +542,7 @@ private extension GoogleReaderCompatibleAccountDelegate {
os_log(.debug, log: log, "Syncing folders with %ld tags.", tags.count)
// TODO: filter on folder tag type
// TODO: filter names to get rid of prefixes
let tagNames = tags.map { $0.tagID }
let tagNames = tags.filter { $0.type == "folder" }.map { $0.tagID.replacingOccurrences(of: "user/-/label/", with: "") }
// Delete any folders not at GoogleReaderCompatible
if let folders = account.folders {
@ -665,7 +663,7 @@ private extension GoogleReaderCompatibleAccountDelegate {
feed.homePageURL = subscription.homePageURL
} else {
let feed = account.createFeed(with: subscription.name, url: subscription.url, feedID: subFeedId, homePageURL: subscription.homePageURL)
feed.subscriptionID = String(subscription.subscriptionID)
feed.subscriptionID = String(subscription.feedID)
account.addFeed(feed)
}
}
@ -854,7 +852,7 @@ private extension GoogleReaderCompatibleAccountDelegate {
DispatchQueue.main.async {
let feed = account.createFeed(with: sub.name, url: sub.url, feedID: String(sub.feedID), homePageURL: sub.homePageURL)
feed.subscriptionID = String(sub.subscriptionID)
feed.subscriptionID = String(sub.feedID)
account.addFeed(feed, to: container) { result in
switch result {

View File

@ -10,24 +10,60 @@ import Foundation
import RSCore
import RSParser
struct GoogleReaderCompatibleSubscriptionContainer: Codable {
let subscriptions: [GoogleReaderCompatibleSubscription]
enum CodingKeys: String, CodingKey {
case subscriptions = "subscriptions"
}
}
/*
{
"id": "feed/1",
"title": "Questionable Content",
"categories": [
{
"id": "user/-/label/Comics",
"label": "Comics"
}
],
"url": "http://www.questionablecontent.net/QCRSS.xml",
"htmlUrl": "http://www.questionablecontent.net",
"iconUrl": "https://rss.confusticate.com/f.php?24decabc"
}
*/
struct GoogleReaderCompatibleSubscription: Codable {
let subscriptionID: Int
let feedID: Int
let feedID: String
let name: String?
let categories: [GoogleReaderCompatibleCategory]
let url: String
let homePageURL: String?
let iconURL: String?
enum CodingKeys: String, CodingKey {
case subscriptionID = "id"
case feedID = "feed_id"
case feedID = "id"
case name = "title"
case url = "feed_url"
case homePageURL = "site_url"
case categories = "categories"
case url = "url"
case homePageURL = "htmlUrl"
case iconURL = "iconUrl"
}
}
struct GoogleReaderCompatibleCategory: Codable {
let categoryId: String
let categoryLabel: String
enum CodingKeys: String, CodingKey {
case categoryId = "id"
case categoryLabel = "label"
}
}
struct GoogleReaderCompatibleCreateSubscription: Codable {
let feedURL: String
enum CodingKeys: String, CodingKey {

View File

@ -8,7 +8,7 @@
import Foundation
struct GoogleReaderCompatibleTagWrapper: Codable {
struct GoogleReaderCompatibleTagContainer: Codable {
let tags: [GoogleReaderCompatibleTag]
enum CodingKeys: String, CodingKey {