-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Activity.swift
87 lines (77 loc) · 2.34 KB
/
Activity.swift
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import Foundation
public struct Activity {
public let category: Activity.Category
public let comment: ActivityComment?
public let createdAt: TimeInterval
public let id: Int
public let memberData: MemberData
public let project: Project?
public let update: Update?
public let user: User?
public enum Category: String {
case backing
case cancellation
case commentPost = "comment-post"
case commentProject = "comment-project"
case failure
case follow
case funding
case launch
case success
case suspension
case update
case watch
case unknown
}
public struct MemberData {
public let amount: Int?
public let backing: Backing?
public let oldAmount: Int?
public let oldRewardId: Int?
public let newAmount: Int?
public let newRewardId: Int?
public let rewardId: Int?
}
}
extension Activity: Equatable {}
public func == (lhs: Activity, rhs: Activity) -> Bool {
return lhs.id == rhs.id
}
extension Activity: Decodable {
enum CodingKeys: String, CodingKey {
case category
case comment
case createdAt = "created_at"
case id
case project
case update
case user
}
public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.self)
self.category = try values.decode(Activity.Category.self, forKey: .category)
self.comment = try values.decodeIfPresent(ActivityComment.self, forKey: .comment)
self.createdAt = try values.decode(TimeInterval.self, forKey: .createdAt)
self.id = try values.decode(Int.self, forKey: .id)
self.memberData = try Activity.MemberData(from: decoder)
self.project = try values.decodeIfPresent(Project.self, forKey: .project)
self.update = try values.decodeIfPresent(Update.self, forKey: .update)
self.user = try values.decodeIfPresent(User.self, forKey: .user)
}
}
extension Activity.Category: Decodable {
public init(from decoder: Decoder) throws {
self = try Activity.Category(rawValue: decoder.singleValueContainer().decode(String.self)) ?? .unknown
}
}
extension Activity.MemberData: Decodable {
enum CodingKeys: String, CodingKey {
case amount
case backing
case oldAmount = "old_amount"
case oldRewardId = "old_reward_id"
case newAmount = "new_amount"
case newRewardId = "new_reward_id"
case rewardId = "reward_id"
}
}