Change to use the entries.json service for Feedbin instead of the per feed one

This commit is contained in:
Maurice Parker 2019-05-13 10:29:34 -05:00
parent c4ce93e96a
commit ccac456d77
2 changed files with 26 additions and 28 deletions

View File

@ -299,7 +299,7 @@ final class FeedbinAPICaller: NSObject {
}
func retrieveEntries(_ feedID: String, completion: @escaping (Result<([FeedbinEntry]?, String?), Error>) -> Void) {
func retrieveEntries(completion: @escaping (Result<([FeedbinEntry]?, String?), Error>) -> Void) {
let since: Date = {
if let lastArticleFetch = accountMetadata?.lastArticleFetch {
@ -310,8 +310,8 @@ final class FeedbinAPICaller: NSObject {
}()
let sinceString = FeedbinDate.formatter.string(from: since)
var callURL = URLComponents(url: feedbinBaseURL.appendingPathComponent("feeds/\(feedID)/entries.json"), resolvingAgainstBaseURL: false)!
callURL.queryItems = [URLQueryItem(name: "since", value: sinceString)]
var callURL = URLComponents(url: feedbinBaseURL.appendingPathComponent("entries.json"), resolvingAgainstBaseURL: false)!
callURL.queryItems = [URLQueryItem(name: "since", value: sinceString), URLQueryItem(name: "per_page", value: "100")]
let request = URLRequest(url: callURL.url!, credentials: credentials)
transport.send(request: request, resultType: [FeedbinEntry].self) { [weak self] result in

View File

@ -850,37 +850,26 @@ private extension FeedbinAccountDelegate {
os_log(.debug, log: log, "Refreshing articles...")
let group = DispatchGroup()
for feed in account.flattenedFeeds() {
group.enter()
caller.retrieveEntries() { [weak self] result in
caller.retrieveEntries(feed.feedID) { [weak self] result in
switch result {
case .success(let (entries, page)):
switch result {
case .success(let (entries, page)):
self?.processEntries(account: account, entries: entries) {
self?.refreshArticles(account, page: page) {
group.leave()
}
self?.processEntries(account: account, entries: entries) {
self?.refreshArticles(account, page: page) {
guard let self = self else { return }
os_log(.debug, log: self.log, "Done refreshing articles.")
completion()
}
case .failure(let error):
guard let self = self else { return }
os_log(.error, log: self.log, "Refresh articles failed: %@.", error.localizedDescription)
}
case .failure(let error):
guard let self = self else { return }
os_log(.error, log: self.log, "Refresh articles failed: %@.", error.localizedDescription)
}
}
group.notify(queue: DispatchQueue.main) {
completion()
}
}
func refreshArticles(_ account: Account, page: String?, completion: @escaping (() -> Void)) {
@ -908,20 +897,29 @@ private extension FeedbinAccountDelegate {
}
func processEntries(account: Account, entries: [FeedbinEntry]?, completion: @escaping (() -> Void)) {
let parsedItems = mapEntriesToParsedItems(entries: entries)
let parsedMap = Dictionary(grouping: parsedItems, by: { item in item.feedURL } )
let group = DispatchGroup()
for (feedID, mapItems) in parsedMap {
group.enter()
if let feed = account.idToFeedDictionary[feedID] {
DispatchQueue.main.async {
account.update(feed, parsedItems: Set(mapItems), defaultRead: true) {
completion()
group.leave()
}
}
}
}
group.notify(queue: DispatchQueue.main) {
completion()
}
}