Files
SideStore/Sources/SideStoreCore/Patreon/Patron.swift

66 lines
1.4 KiB
Swift
Raw Normal View History

//
// Patron.swift
// AltStore
//
// Created by Riley Testut on 8/21/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
import Foundation
2023-03-01 00:48:36 -05:00
extension PatreonAPI {
struct PatronResponse: Decodable {
struct Attributes: Decodable {
var full_name: String
var patron_status: String?
}
2023-03-01 00:48:36 -05:00
struct Relationships: Decodable {
struct Tiers: Decodable {
struct TierID: Decodable {
var id: String
var type: String
}
2023-03-01 00:48:36 -05:00
var data: [TierID]
}
2023-03-01 00:48:36 -05:00
var currently_entitled_tiers: Tiers
}
2023-03-01 00:48:36 -05:00
var id: String
var attributes: Attributes
2023-03-01 00:48:36 -05:00
var relationships: Relationships?
}
}
2023-03-01 00:48:36 -05:00
public extension Patron {
enum Status: String, Decodable {
case active = "active_patron"
case declined = "declined_patron"
case former = "former_patron"
2023-03-01 00:48:36 -05:00
case unknown
}
}
2023-03-01 00:48:36 -05:00
public class Patron {
public var name: String
public var identifier: String
2023-03-01 00:48:36 -05:00
public var status: Status
2023-03-01 00:48:36 -05:00
public var benefits: Set<Benefit> = []
2023-03-01 00:48:36 -05:00
init(response: PatreonAPI.PatronResponse) {
name = response.attributes.full_name
identifier = response.id
if let status = response.attributes.patron_status {
self.status = Status(rawValue: status) ?? .unknown
2023-03-01 00:48:36 -05:00
} else {
status = .unknown
}
}
}