This repository was archived by the owner on Sep 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathAccount.swift
144 lines (131 loc) · 3.61 KB
/
Account.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// Account.swift
// reddift
//
// Created by generator.rb via from https://github.com/reddit/reddit/wiki/JSON
// Created at 2015-04-15 11:23:32 +0900
//
import Foundation
/**
Account object.
*/
public struct Account: Thing, Created {
/// identifier of Thing like 15bfi0.
public let id: String
/// name of Thing, that is fullname, like t3_15bfi0.
public let name: String
/// type of Thing, like t3.
public static let kind = "t2"
/**
user has unread mail? null if not your account
example: false
*/
public let hasMail: Bool
/**
example: 1427126074
*/
public let created: Int
/**
example: false
*/
public let hideFromRobots: Bool
/**
example: 0
*/
public let goldCreddits: Int
/**
example: 1427122474
*/
public let createdUtc: Int
/**
user has unread mod mail? null if not your account
example: false
*/
public let hasModMail: Bool
/**
user's link karma
example: 1
*/
public let linkKarma: Int
/**
user's comment karma
example: 1
*/
public let commentKarma: Int
/**
whether this account is set to be over 18
example: true
*/
public let over18: Bool
/**
reddit gold status
example: false
*/
public let isGold: Bool
/**
whether this account moderates any subreddits
example: false
*/
public let isMod: Bool
/**
example:
*/
public let goldExpiration: Bool
/**
user has provided an email address and got it verified?
example: false
*/
public let hasVerifiedEmail: Bool
/**
Number of unread messages in the inbox. Not present if not your account
example: 0
*/
public let inboxCount: Int
public init(id: String) {
self.id = id
self.name = "\(Account.kind)_\(self.id)"
hasMail = false
created = 0
hideFromRobots = false
goldCreddits = 0
createdUtc = 0
hasModMail = false
linkKarma = 0
commentKarma = 0
over18 = false
isGold = false
isMod = false
goldExpiration = false
hasVerifiedEmail = false
inboxCount = 0
}
/**
Parse t2 object.
- parameter data: Dictionary, must be generated parsing "t2".
- returns: Account object as Thing.
*/
public init(json data: JSONDictionary) {
id = data["id"] as? String ?? ""
hasMail = data["has_mail"] as? Bool ?? false
name = data["name"] as? String ?? ""
created = data["created"] as? Int ?? 0
hideFromRobots = data["hide_from_robots"] as? Bool ?? false
goldCreddits = data["gold_creddits"] as? Int ?? 0
createdUtc = data["created_utc"] as? Int ?? 0
hasModMail = data["has_mod_mail"] as? Bool ?? false
linkKarma = data["link_karma"] as? Int ?? 0
commentKarma = data["comment_karma"] as? Int ?? 0
over18 = data["over_18"] as? Bool ?? false
isGold = data["is_gold"] as? Bool ?? false
isMod = data["is_mod"] as? Bool ?? false
goldExpiration = data["gold_expiration"] as? Bool ?? false
hasVerifiedEmail = data["has_verified_email"] as? Bool ?? false
inboxCount = data["inbox_count"] as? Int ?? 0
}
}
func parseDataInJSON_t2(_ json: JSONAny) -> Result<Thing> {
if let object = json as? JSONDictionary {
return Result(fromOptional: Account(json: object), error: ReddiftError.accountJsonObjectIsMalformed as NSError)
}
return Result(fromOptional: nil, error: ReddiftError.accountJsonObjectIsNotDictionary as NSError)
}