2017-12-10 22:58:44 +01:00
|
|
|
//
|
2018-10-15 03:10:07 +02: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
|
|
|
|
|
2018-10-15 03:10:07 +02:00
|
|
|
struct FeedbinFeed {
|
2017-12-10 22:58:44 +01:00
|
|
|
|
2018-10-15 03:10:07 +02: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/"
|
|
|
|
|
2018-10-15 03:38:33 +02:00
|
|
|
let subscriptionID: Int
|
|
|
|
let feedID: Int
|
2018-10-15 03:10:07 +02:00
|
|
|
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) {
|
|
|
|
|
2018-10-15 03:38:33 +02:00
|
|
|
guard let subscriptionID = dictionary[Key.subscriptionID] as? Int else {
|
2017-12-10 22:58:44 +01:00
|
|
|
return nil
|
|
|
|
}
|
2018-10-15 03:38:33 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-10-15 03:38:33 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2018-10-15 03:10:07 +02:00
|
|
|
static func feeds(with array: JSONArray) -> [FeedbinFeed]? {
|
2017-12-10 22:58:44 +01:00
|
|
|
|
2018-10-15 03:10:07 +02:00
|
|
|
let subs = array.compactMap { FeedbinFeed(dictionary: $0) }
|
2017-12-10 22:58:44 +01:00
|
|
|
return subs.isEmpty ? nil : subs
|
|
|
|
}
|
|
|
|
}
|