53 lines
1.7 KiB
Swift
53 lines
1.7 KiB
Swift
|
//
|
||
|
// Item.swift
|
||
|
// Fervor
|
||
|
//
|
||
|
// Created by Shadowfacts on 10/29/21.
|
||
|
//
|
||
|
|
||
|
import Foundation
|
||
|
|
||
|
public struct Item: Decodable {
|
||
|
let id: FervorID
|
||
|
let feedID: FervorID
|
||
|
let title: String
|
||
|
let author: String
|
||
|
let published: Date?
|
||
|
let createdAt: Date?
|
||
|
let content: String?
|
||
|
let summary: String?
|
||
|
let url: URL
|
||
|
let serviceURL: URL?
|
||
|
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.decode(String.self, forKey: .title)
|
||
|
self.author = try container.decode(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
|
||
|
}
|
||
|
}
|