-
Notifications
You must be signed in to change notification settings - Fork 0
/
RequestToken.swift
60 lines (45 loc) · 1.48 KB
/
RequestToken.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
//
// RequestToken.swift
//
// Created by Aurélien Aubert on 05/06/16.
//
import Foundation
class RequestToken: NSObject, NSCoding {
var accessToken: String!
var refreshToken: String?
var dateToken: Date!
var isUserAuth: Bool!
init(data: NSDictionary) {
if let accessToken = data["access_token"] as? String {
self.accessToken = accessToken
}
if let refreshToken = data["refresh_token"] as? String {
self.refreshToken = refreshToken
self.isUserAuth = true
}
else {
self.isUserAuth = false
}
self.dateToken = Date()
}
required init?(coder aDecoder: NSCoder) {
if let accessToken = aDecoder.decodeObject(forKey: "accessToken") as? String {
self.accessToken = accessToken
}
if let refreshToken = aDecoder.decodeObject(forKey: "refreshToken") as? String {
self.refreshToken = refreshToken
self.isUserAuth = true
}
else {
self.isUserAuth = false
}
if let dateToken = aDecoder.decodeObject(forKey: "dateToken") as? Date {
self.dateToken = dateToken
}
}
func encode(with aCoder: NSCoder) {
aCoder.encode(self.accessToken, forKey: "accessToken")
aCoder.encode(self.refreshToken, forKey: "refreshToken")
aCoder.encode(self.dateToken, forKey: "dateToken")
}
}