Cleanup tag names, fetch subscriptions
This commit is contained in:
parent
76d1daf122
commit
a0efc7fda9
|
@ -178,10 +178,10 @@ final class GoogleReaderCompatibleAPICaller: NSObject {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//let conditionalGet = accountMetadata?.conditionalGetInfo[ConditionalGetKeys.tags]
|
let conditionalGet = accountMetadata?.conditionalGetInfo[ConditionalGetKeys.tags]
|
||||||
let request = URLRequest(url: callURL, credentials: credentials)
|
let request = URLRequest(url: callURL, credentials: credentials, conditionalGet: conditionalGet)
|
||||||
|
|
||||||
transport.send(request: request, resultType: GoogleReaderCompatibleTagWrapper.self) { result in
|
transport.send(request: request, resultType: GoogleReaderCompatibleTagContainer.self) { result in
|
||||||
|
|
||||||
switch result {
|
switch result {
|
||||||
case .success(let (response, wrapper)):
|
case .success(let (response, wrapper)):
|
||||||
|
@ -222,17 +222,35 @@ final class GoogleReaderCompatibleAPICaller: NSObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
func retrieveSubscriptions(completion: @escaping (Result<[GoogleReaderCompatibleSubscription]?, Error>) -> Void) {
|
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 conditionalGet = accountMetadata?.conditionalGetInfo[ConditionalGetKeys.subscriptions]
|
||||||
let request = URLRequest(url: callURL, credentials: credentials, conditionalGet: conditionalGet)
|
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 {
|
switch result {
|
||||||
case .success(let (response, subscriptions)):
|
case .success(let (response, container)):
|
||||||
self.storeConditionalGet(key: ConditionalGetKeys.subscriptions, headers: response.allHeaderFields)
|
self.storeConditionalGet(key: ConditionalGetKeys.subscriptions, headers: response.allHeaderFields)
|
||||||
completion(.success(subscriptions))
|
completion(.success(container?.subscriptions))
|
||||||
case .failure(let error):
|
case .failure(let error):
|
||||||
completion(.failure(error))
|
completion(.failure(error))
|
||||||
}
|
}
|
||||||
|
|
|
@ -542,9 +542,7 @@ private extension GoogleReaderCompatibleAccountDelegate {
|
||||||
|
|
||||||
os_log(.debug, log: log, "Syncing folders with %ld tags.", tags.count)
|
os_log(.debug, log: log, "Syncing folders with %ld tags.", tags.count)
|
||||||
|
|
||||||
// TODO: filter on folder tag type
|
let tagNames = tags.filter { $0.type == "folder" }.map { $0.tagID.replacingOccurrences(of: "user/-/label/", with: "") }
|
||||||
// TODO: filter names to get rid of prefixes
|
|
||||||
let tagNames = tags.map { $0.tagID }
|
|
||||||
|
|
||||||
// Delete any folders not at GoogleReaderCompatible
|
// Delete any folders not at GoogleReaderCompatible
|
||||||
if let folders = account.folders {
|
if let folders = account.folders {
|
||||||
|
@ -665,7 +663,7 @@ private extension GoogleReaderCompatibleAccountDelegate {
|
||||||
feed.homePageURL = subscription.homePageURL
|
feed.homePageURL = subscription.homePageURL
|
||||||
} else {
|
} else {
|
||||||
let feed = account.createFeed(with: subscription.name, url: subscription.url, feedID: subFeedId, homePageURL: subscription.homePageURL)
|
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)
|
account.addFeed(feed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -854,7 +852,7 @@ private extension GoogleReaderCompatibleAccountDelegate {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
|
|
||||||
let feed = account.createFeed(with: sub.name, url: sub.url, feedID: String(sub.feedID), homePageURL: sub.homePageURL)
|
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
|
account.addFeed(feed, to: container) { result in
|
||||||
switch result {
|
switch result {
|
||||||
|
|
|
@ -10,22 +10,58 @@ import Foundation
|
||||||
import RSCore
|
import RSCore
|
||||||
import RSParser
|
import RSParser
|
||||||
|
|
||||||
struct GoogleReaderCompatibleSubscription: Codable {
|
struct GoogleReaderCompatibleSubscriptionContainer: Codable {
|
||||||
|
let subscriptions: [GoogleReaderCompatibleSubscription]
|
||||||
let subscriptionID: Int
|
|
||||||
let feedID: Int
|
|
||||||
let name: String?
|
|
||||||
let url: String
|
|
||||||
let homePageURL: String?
|
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
enum CodingKeys: String, CodingKey {
|
||||||
case subscriptionID = "id"
|
case subscriptions = "subscriptions"
|
||||||
case feedID = "feed_id"
|
}
|
||||||
case name = "title"
|
|
||||||
case url = "feed_url"
|
|
||||||
case homePageURL = "site_url"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
{
|
||||||
|
"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 feedID: String
|
||||||
|
let name: String?
|
||||||
|
let categories: [GoogleReaderCompatibleCategory]
|
||||||
|
let url: String
|
||||||
|
let homePageURL: String?
|
||||||
|
let iconURL: String?
|
||||||
|
|
||||||
|
enum CodingKeys: String, CodingKey {
|
||||||
|
case feedID = "id"
|
||||||
|
case name = "title"
|
||||||
|
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 {
|
struct GoogleReaderCompatibleCreateSubscription: Codable {
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
struct GoogleReaderCompatibleTagWrapper: Codable {
|
struct GoogleReaderCompatibleTagContainer: Codable {
|
||||||
let tags: [GoogleReaderCompatibleTag]
|
let tags: [GoogleReaderCompatibleTag]
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
enum CodingKeys: String, CodingKey {
|
||||||
|
|
Loading…
Reference in New Issue