2017-12-03 02:47:08 +01:00
|
|
|
//
|
|
|
|
// InitialFeedDownloader.swift
|
2018-08-29 07:18:24 +02:00
|
|
|
// NetNewsWire
|
2017-12-03 02:47:08 +01:00
|
|
|
//
|
|
|
|
// Created by Brent Simmons on 9/3/16.
|
|
|
|
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import RSParser
|
|
|
|
import RSWeb
|
|
|
|
|
|
|
|
struct InitialFeedDownloader {
|
|
|
|
|
2019-12-15 01:14:55 +01:00
|
|
|
static func download(_ url: URL,_ completion: @escaping (_ parsedFeed: ParsedFeed?) -> Void) {
|
2017-12-03 02:47:08 +01:00
|
|
|
|
|
|
|
downloadUsingCache(url) { (data, response, error) in
|
|
|
|
guard let data = data else {
|
2019-12-15 01:14:55 +01:00
|
|
|
completion(nil)
|
2017-12-03 02:47:08 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
let parserData = ParserData(url: url.absoluteString, data: data)
|
|
|
|
FeedParser.parse(parserData) { (parsedFeed, error) in
|
2019-12-15 01:14:55 +01:00
|
|
|
completion(parsedFeed)
|
2017-12-03 02:47:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|