2021-12-08 02:58:02 +00:00
|
|
|
//
|
|
|
|
// LocalData.swift
|
|
|
|
// Reader
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 11/25/21.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
struct LocalData {
|
|
|
|
|
|
|
|
private init() {}
|
|
|
|
|
|
|
|
private static let encoder = JSONEncoder()
|
|
|
|
private static let decoder = JSONDecoder()
|
|
|
|
|
|
|
|
static var account: Account? {
|
|
|
|
get {
|
|
|
|
guard let data = UserDefaults.standard.data(forKey: "account") else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return try? decoder.decode(Account.self, from: data)
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
let data = try! encoder.encode(newValue)
|
|
|
|
UserDefaults.standard.set(data, forKey: "account")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Account: Codable {
|
2021-12-25 19:04:45 +00:00
|
|
|
let id: UUID
|
2021-12-08 02:58:02 +00:00
|
|
|
let instanceURL: URL
|
|
|
|
let clientID: String
|
|
|
|
let clientSecret: String
|
|
|
|
let accessToken: String
|
|
|
|
// todo: refresh tokens
|
2021-12-25 19:04:45 +00:00
|
|
|
|
|
|
|
init(instanceURL: URL, clientID: String, clientSecret: String, accessToken: String) {
|
|
|
|
self.id = UUID()
|
|
|
|
self.instanceURL = instanceURL
|
|
|
|
self.clientID = clientID
|
|
|
|
self.clientSecret = clientSecret
|
|
|
|
self.accessToken = accessToken
|
|
|
|
}
|
2021-12-08 02:58:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|