Complete (probably) work on Feedbin sync data types.

This commit is contained in:
Brent Simmons 2018-10-14 18:38:33 -07:00
parent cd6e6daf31
commit 485bde7ff2
2 changed files with 23 additions and 15 deletions

View File

@ -13,6 +13,7 @@ import RSCore
struct FeedbinArticle {
// https://github.com/feedbin/feedbin-api/blob/master/content/entries.md
// https://github.com/feedbin/feedbin-api/blob/master/content/updated-entries.md
//
// "id": 2077,
// "feed_id": 135,
@ -24,38 +25,39 @@ struct FeedbinArticle {
// "published": "2013-02-03T01:00:19.000000Z",
// "created_at": "2013-02-04T01:00:19.127893Z"
let syncID: String
let feedID: String
let articleID: Int
let feedID: Int
let title: String?
let url: String?
let authorName: String?
let contentHTML: String?
let contentDiffHTML: String?
let summary: String?
let datePublished: Date?
let dateArrived: Date?
struct Key {
static let syncID = "id"
static let articleID = "id"
static let feedID = "feed_id"
static let title = "title"
static let url = "url"
static let authorName = "author"
static let contentHTML = "content"
static let contentDiffHTML = "content_diff"
static let summary = "summary"
static let datePublished = "published"
static let dateArrived = "created_at"
}
init?(jsonDictionary: JSONDictionary) {
guard let syncIDInt = jsonDictionary[Key.syncID] as? Int else {
guard let articleID = jsonDictionary[Key.articleID] as? Int else {
return nil
}
guard let feedIDInt = jsonDictionary[Key.feedID] as? Int else {
guard let feedID = jsonDictionary[Key.feedID] as? Int else {
return nil
}
self.syncID = "\(syncIDInt)"
self.feedID = "\(feedIDInt)"
self.articleID = articleID
self.feedID = feedID
self.title = jsonDictionary[Key.title] as? String
self.url = jsonDictionary[Key.url] as? String
@ -68,6 +70,13 @@ struct FeedbinArticle {
self.contentHTML = nil
}
if let contentDiffHTML = jsonDictionary[Key.contentDiffHTML] as? String, !contentDiffHTML.isEmpty {
self.contentDiffHTML = contentDiffHTML
}
else {
self.contentDiffHTML = nil
}
if let summary = jsonDictionary[Key.summary] as? String, !summary.isEmpty {
self.summary = summary
}
@ -91,7 +100,6 @@ struct FeedbinArticle {
}
static func articles(with array: JSONArray) -> [FeedbinArticle]? {
let articlesArray = array.compactMap { FeedbinArticle(jsonDictionary: $0) }
return articlesArray.isEmpty ? nil : articlesArray
}

View File

@ -21,8 +21,8 @@ struct FeedbinFeed {
// "feed_url": "http://daringfireball.net/index.xml",
// "site_url": "http://daringfireball.net/"
let subscriptionID: String
let feedID: String
let subscriptionID: Int
let feedID: Int
let creationDate: Date?
let name: String?
let url: String
@ -39,18 +39,18 @@ struct FeedbinFeed {
init?(dictionary: JSONDictionary) {
guard let subscriptionIDInt = dictionary[Key.subscriptionID] as? Int else {
guard let subscriptionID = dictionary[Key.subscriptionID] as? Int else {
return nil
}
guard let feedIDInt = dictionary[Key.feedID] as? Int else {
guard let feedID = dictionary[Key.feedID] as? Int else {
return nil
}
guard let url = dictionary[Key.url] as? String else {
return nil
}
self.subscriptionID = String(subscriptionIDInt)
self.feedID = String(feedIDInt)
self.subscriptionID = subscriptionID
self.feedID = feedID
self.url = url
if let creationDateString = dictionary[Key.creationDate] as? String {