Files
SideStore/Sources/SideStoreCore/Model/PatreonAccount.swift

66 lines
1.7 KiB
Swift
Raw Normal View History

//
// PatreonAccount.swift
// AltStore
//
// Created by Riley Testut on 8/20/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
import CoreData
2023-03-01 00:48:36 -05:00
extension PatreonAPI {
struct AccountResponse: Decodable {
struct Data: Decodable {
struct Attributes: Decodable {
var first_name: String?
var full_name: String
}
2023-03-01 00:48:36 -05:00
var id: String
var attributes: Attributes
}
2023-03-01 00:48:36 -05:00
var data: Data
var included: [PatronResponse]?
}
}
@objc(PatreonAccount)
2023-03-01 00:48:36 -05:00
public class PatreonAccount: NSManagedObject, Fetchable {
@NSManaged public var identifier: String
2023-03-01 00:48:36 -05:00
@NSManaged public var name: String
@NSManaged public var firstName: String?
2023-03-01 00:48:36 -05:00
@NSManaged public var isPatron: Bool
2023-03-01 00:48:36 -05:00
override private init(entity: NSEntityDescription, insertInto context: NSManagedObjectContext?) {
super.init(entity: entity, insertInto: context)
}
2023-03-01 00:48:36 -05:00
init(response: PatreonAPI.AccountResponse, context: NSManagedObjectContext) {
super.init(entity: PatreonAccount.entity(), insertInto: context)
2023-03-01 00:48:36 -05:00
identifier = response.data.id
name = response.data.attributes.full_name
firstName = response.data.attributes.first_name
// if let patronResponse = response.included?.first
// {
// let patron = Patron(response: patronResponse)
// self.isPatron = (patron.status == .active)
// }
// else
// {
// self.isPatron = false
// }
2023-03-01 00:48:36 -05:00
isPatron = true
}
}
2023-03-01 00:48:36 -05:00
public extension PatreonAccount {
@nonobjc class func fetchRequest() -> NSFetchRequest<PatreonAccount> {
NSFetchRequest<PatreonAccount>(entityName: "PatreonAccount")
}
}