NetNewsWire/Frameworks/Account/Feedbin/FeedbinFeed.swift

73 lines
1.6 KiB
Swift
Raw Normal View History

2017-12-10 22:58:44 +01:00
//
// FeedbinFeed.swift
2017-12-10 22:58:44 +01:00
// Account
//
// Created by Brent Simmons on 12/10/17.
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
//
import Foundation
import RSCore
import RSParser
struct FeedbinFeed {
2017-12-10 22:58:44 +01:00
// https://github.com/feedbin/feedbin-api/blob/master/content/feeds.md
//
2017-12-10 22:58:44 +01:00
// "id": 525,
// "created_at": "2013-03-12T11:30:25.209432Z",
// "feed_id": 47,
// "title": "Daring Fireball",
// "feed_url": "http://daringfireball.net/index.xml",
// "site_url": "http://daringfireball.net/"
let subscriptionID: Int
let feedID: Int
let creationDate: Date?
let name: String?
let url: String
let homePageURL: String?
2017-12-10 22:58:44 +01:00
struct Key {
static let subscriptionID = "id"
static let feedID = "feed_id"
static let creationDate = "created_at"
static let name = "title"
static let url = "feed_url"
static let homePageURL = "site_url"
}
init?(dictionary: JSONDictionary) {
guard let subscriptionID = dictionary[Key.subscriptionID] as? Int else {
2017-12-10 22:58:44 +01:00
return nil
}
guard let feedID = dictionary[Key.feedID] as? Int else {
2017-12-10 22:58:44 +01:00
return nil
}
guard let url = dictionary[Key.url] as? String else {
return nil
}
self.subscriptionID = subscriptionID
self.feedID = feedID
2017-12-10 22:58:44 +01:00
self.url = url
if let creationDateString = dictionary[Key.creationDate] as? String {
self.creationDate = RSDateWithString(creationDateString)
}
2017-12-10 23:04:14 +01:00
else {
self.creationDate = nil
}
2017-12-10 22:58:44 +01:00
self.name = dictionary[Key.name] as? String
self.homePageURL = dictionary[Key.homePageURL] as? String
}
static func feeds(with array: JSONArray) -> [FeedbinFeed]? {
2017-12-10 22:58:44 +01:00
let subs = array.compactMap { FeedbinFeed(dictionary: $0) }
2017-12-10 22:58:44 +01:00
return subs.isEmpty ? nil : subs
}
}