NetNewsWire/Frameworks/Account/Feedbin/FeedbinSubscription.swift

71 lines
1.6 KiB
Swift
Raw Normal View History

2017-12-10 22:58:44 +01:00
//
// FeedbinSubscription.swift
// Account
//
// Created by Brent Simmons on 12/10/17.
// Copyright © 2017 Ranchero Software, LLC. All rights reserved.
//
import Foundation
import RSCore
import RSParser
struct FeedbinSubscription {
let subscriptionID: String
let feedID: String
let creationDate: Date?
2017-12-10 23:04:14 +01:00
let name: String?
2017-12-10 22:58:44 +01:00
let url: String
let homePageURL: String?
// "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/"
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 subscriptionIDInt = dictionary[Key.subscriptionID] as? Int else {
return nil
}
guard let feedIDInt = dictionary[Key.feedID] as? Int else {
return nil
}
guard let url = dictionary[Key.url] as? String else {
return nil
}
self.subscriptionID = "\(subscriptionIDInt)"
self.feedID = "\(feedIDInt)"
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 subscriptions(with array: JSONArray) -> [FeedbinSubscription]? {
2017-12-10 23:04:14 +01:00
let subs = array.flatMap { FeedbinSubscription(dictionary: $0) }
2017-12-10 22:58:44 +01:00
return subs.isEmpty ? nil : subs
}
}