-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResource.swift
More file actions
41 lines (34 loc) · 1.27 KB
/
Resource.swift
File metadata and controls
41 lines (34 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Resource.swift
//
// Created by Pirush Prechathavanich on 4/4/18.
// Copyright © 2018 Nimbl3. All rights reserved.
//
import Foundation
public struct Resource: JSONAPICodable {
enum CodingKeys: String, CodingKey {
case id, type, attributes, relationships, links, meta
}
public let id: String
public let type: String
public let attributes: JSON?
public let relationships: [String: Relationship]?
public let links: Links?
public let meta: JSON?
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = (try? container.decode(String.self, forKey: .id)) ?? ""
type = try container.decode(String.self, forKey: .type)
attributes = try container.decodeIfPresent(JSON.self, forKey: .attributes)
relationships = try container.decodeIfPresent([String: Relationship].self, forKey: .relationships)
links = try container.decodeIfPresent(Links.self, forKey: .links)
meta = try container.decodeIfPresent(JSON.self, forKey: .meta)
}
init(id: String, type: String) {
self.id = id
self.type = type
self.attributes = nil
self.relationships = nil
self.links = nil
self.meta = nil
}
}