Decode status cards
This commit is contained in:
parent
cd5b4c1145
commit
1b19a13b05
|
@ -22,6 +22,23 @@ public class Card: Decodable {
|
||||||
public let width: Int?
|
public let width: Int?
|
||||||
public let height: 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 {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case url
|
case url
|
||||||
case title
|
case title
|
||||||
|
|
|
@ -36,6 +36,7 @@ public class Status: Decodable {
|
||||||
public let language: String?
|
public let language: String?
|
||||||
public let pinned: Bool?
|
public let pinned: Bool?
|
||||||
public let bookmarked: Bool?
|
public let bookmarked: Bool?
|
||||||
|
public let card: Card?
|
||||||
|
|
||||||
public static func getContext(_ status: Status) -> Request<ConversationContext> {
|
public static func getContext(_ status: Status) -> Request<ConversationContext> {
|
||||||
return Request<ConversationContext>(method: .get, path: "/api/v1/statuses/\(status.id)/context")
|
return Request<ConversationContext>(method: .get, path: "/api/v1/statuses/\(status.id)/context")
|
||||||
|
@ -128,6 +129,7 @@ public class Status: Decodable {
|
||||||
case language
|
case language
|
||||||
case pinned
|
case pinned
|
||||||
case bookmarked
|
case bookmarked
|
||||||
|
case card
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue