From 1b19a13b05cacf8283581dfb6bcd74c39eb5daa3 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 4 Mar 2020 21:14:58 -0500 Subject: [PATCH] Decode status cards --- Pachyderm/Model/Card.swift | 17 +++++++++++++++++ Pachyderm/Model/Status.swift | 2 ++ 2 files changed, 19 insertions(+) diff --git a/Pachyderm/Model/Card.swift b/Pachyderm/Model/Card.swift index 16f4de86..cd5b7ac0 100644 --- a/Pachyderm/Model/Card.swift +++ b/Pachyderm/Model/Card.swift @@ -22,6 +22,23 @@ public class Card: Decodable { public let width: Int? public let height: Int? + public required init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + + self.url = try container.decode(URL.self, forKey: .url) + self.title = try container.decode(String.self, forKey: .title) + self.description = try container.decode(String.self, forKey: .description) + self.kind = try container.decode(Kind.self, forKey: .kind) + self.image = try? container.decode(URL.self, forKey: .image) + self.authorName = try? container.decode(String.self, forKey: .authorName) + self.authorURL = try? container.decode(URL.self, forKey: .authorURL) + self.providerName = try? container.decode(String.self, forKey: .providerName) + self.providerURL = try? container.decode(URL.self, forKey: .providerURL) + self.html = try? container.decode(String.self, forKey: .html) + self.width = try? container.decode(Int.self, forKey: .width) + self.height = try? container.decode(Int.self, forKey: .height) + } + private enum CodingKeys: String, CodingKey { case url case title diff --git a/Pachyderm/Model/Status.swift b/Pachyderm/Model/Status.swift index 520cc46e..e039ddf2 100644 --- a/Pachyderm/Model/Status.swift +++ b/Pachyderm/Model/Status.swift @@ -36,6 +36,7 @@ public class Status: Decodable { public let language: String? public let pinned: Bool? public let bookmarked: Bool? + public let card: Card? public static func getContext(_ status: Status) -> Request { return Request(method: .get, path: "/api/v1/statuses/\(status.id)/context") @@ -128,6 +129,7 @@ public class Status: Decodable { case language case pinned case bookmarked + case card } }