40 lines
1.3 KiB
Swift
40 lines
1.3 KiB
Swift
//
|
|
// Token.swift
|
|
// Fervor
|
|
//
|
|
// Created by Shadowfacts on 11/25/21.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public struct Token: Codable, Sendable {
|
|
public let accessToken: String
|
|
public let expiresIn: Int?
|
|
public let refreshToken: String?
|
|
public let owner: String?
|
|
|
|
public init(from decoder: Decoder) throws {
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
|
|
self.accessToken = try container.decode(String.self, forKey: .accessToken)
|
|
self.expiresIn = try container.decodeIfPresent(Int.self, forKey: .expiresIn)
|
|
self.refreshToken = try container.decodeIfPresent(String.self, forKey: .refreshToken)
|
|
self.owner = try container.decodeIfPresent(String.self, forKey: .owner)
|
|
}
|
|
|
|
public func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
try container.encode(accessToken, forKey: .accessToken)
|
|
try container.encodeIfPresent(expiresIn, forKey: .expiresIn)
|
|
try container.encodeIfPresent(refreshToken, forKey: .refreshToken)
|
|
try container.encodeIfPresent(owner, forKey: .owner)
|
|
}
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
case accessToken = "access_token"
|
|
case expiresIn = "expires_in"
|
|
case refreshToken = "refresh_token"
|
|
case owner
|
|
}
|
|
}
|