[AltStoreCore] Adds Pledge, PledgeReward, and PledgeTier

Allows us to cache pledges for current user, which can be used to determine if user has access to Patreon-only apps.
This commit is contained in:
Riley Testut
2023-11-20 13:55:28 -06:00
parent 7ed2dc8291
commit d59ced9208
10 changed files with 261 additions and 6 deletions

View File

@@ -15,6 +15,7 @@ extension PatreonAPI
struct TierAttributes: Decodable
{
var title: String
var amount_cents: Int32 // In USD
}
struct TierRelationships: Decodable
@@ -29,6 +30,7 @@ extension PatreonAPI
{
public var name: String
public var identifier: String
public var amount: Decimal
// Relationships
public var benefits: [Benefit] = []
@@ -38,6 +40,9 @@ extension PatreonAPI
self.name = response.attributes.title
self.identifier = response.id
let amount = Decimal(response.attributes.amount_cents) / 100
self.amount = amount
guard let included, let benefitIDs = response.relationships?.benefits?.data.map(\.id) else { return }
let benefits = benefitIDs.compactMap { included.benefits[$0] }.map(Benefit.init(response:))