frenzy-ios/Fervor/Item.swift

53 lines
1.8 KiB
Swift

//
// Item.swift
// Fervor
//
// Created by Shadowfacts on 10/29/21.
//
import Foundation
public struct Item: Decodable {
public let id: FervorID
public let feedID: FervorID
public let title: String?
public let author: String?
public let published: Date?
public let createdAt: Date?
public let content: String?
public let summary: String?
public let url: URL
public let serviceURL: URL?
public let read: Bool?
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.id = try container.decode(FervorID.self, forKey: .id)
self.feedID = try container.decode(FervorID.self, forKey: .feedID)
self.title = try container.decodeIfPresent(String.self, forKey: .title)
self.author = try container.decodeIfPresent(String.self, forKey: .author)
self.published = try container.decodeIfPresent(Date.self, forKey: .published)
self.createdAt = try container.decodeIfPresent(Date.self, forKey: .createdAt)
self.content = try container.decodeIfPresent(String.self, forKey: .content)
self.summary = try container.decodeIfPresent(String.self, forKey: .summary)
self.url = try container.decode(URL.self, forKey: .url)
self.serviceURL = try container.decodeIfPresent(URL.self, forKey: .serviceURL)
self.read = try container.decodeIfPresent(Bool.self, forKey: .read)
}
private enum CodingKeys: String, CodingKey {
case id
case feedID = "feed_id"
case title
case author
case published
case createdAt = "created_at"
case content
case summary
case url
case serviceURL = "service_url"
case read
}
}