frenzy-ios/Fervor/Feed.swift

41 lines
1.2 KiB
Swift

//
// Feed.swift
// Fervor
//
// Created by Shadowfacts on 10/29/21.
//
import Foundation
public struct Feed: Decodable {
public let id: FervorID
public let title: String
public let url: URL
public let serviceURL: URL?
public let feedURL: URL
public let lastUpdated: Date
public let groupIDs: [FervorID]
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decode(FervorID.self, forKey: .id)
self.title = try container.decode(String.self, forKey: .title)
self.url = try container.decode(URL.self, forKey: .url)
self.serviceURL = try container.decodeIfPresent(URL.self, forKey: .serviceURL)
self.feedURL = try container.decode(URL.self, forKey: .feedURL)
self.lastUpdated = try container.decode(Date.self, forKey: .lastUpdated)
self.groupIDs = try container.decode([FervorID].self, forKey: .groupIDs)
}
private enum CodingKeys: String, CodingKey {
case id
case title
case url
case serviceURL = "service_url"
case feedURL = "feed_url"
case lastUpdated = "last_updated"
case groupIDs = "group_ids"
}
}