2019-08-28 11:13:22 -07:00
|
|
|
//
|
|
|
|
|
// Tier.swift
|
|
|
|
|
// AltStore
|
|
|
|
|
//
|
|
|
|
|
// Created by Riley Testut on 8/21/19.
|
|
|
|
|
// Copyright © 2019 Riley Testut. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
|
|
|
|
|
|
extension PatreonAPI
|
|
|
|
|
{
|
2023-11-15 14:13:58 -06:00
|
|
|
typealias TierResponse = DataResponse<TierAttributes, TierRelationships>
|
|
|
|
|
|
|
|
|
|
struct TierAttributes: Decodable
|
2019-08-28 11:13:22 -07:00
|
|
|
{
|
2023-11-15 14:13:58 -06:00
|
|
|
var title: String
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct TierRelationships: Decodable
|
|
|
|
|
{
|
|
|
|
|
var benefits: Response<[AnyItemResponse]>?
|
2019-08-28 11:13:22 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-15 14:13:58 -06:00
|
|
|
extension PatreonAPI
|
2019-08-28 11:13:22 -07:00
|
|
|
{
|
2023-11-15 14:13:58 -06:00
|
|
|
public struct Tier: Hashable
|
2019-08-28 11:13:22 -07:00
|
|
|
{
|
2023-11-15 14:13:58 -06:00
|
|
|
public var name: String
|
|
|
|
|
public var identifier: String
|
|
|
|
|
|
|
|
|
|
// Relationships
|
|
|
|
|
public var benefits: [Benefit] = []
|
|
|
|
|
|
|
|
|
|
internal init(response: TierResponse, including included: IncludedResponses?)
|
|
|
|
|
{
|
|
|
|
|
self.name = response.attributes.title
|
|
|
|
|
self.identifier = response.id
|
|
|
|
|
|
|
|
|
|
guard let included, let benefitIDs = response.relationships?.benefits?.data.map(\.id) else { return }
|
|
|
|
|
|
|
|
|
|
let benefits = benefitIDs.compactMap { included.benefits[$0] }.map(Benefit.init(response:))
|
|
|
|
|
self.benefits = benefits
|
|
|
|
|
}
|
2019-08-28 11:13:22 -07:00
|
|
|
}
|
|
|
|
|
}
|