Skip to content

Commit

Permalink
Update app version up
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Nov 4, 2024
1 parent 6906db1 commit 648c47a
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 188 deletions.
201 changes: 21 additions & 180 deletions Sources/OversizeAppStoreServices/Models/AgeRatingDeclaration.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Copyright © 2024 Alexander Romanov
// AgeRatingDeclaration.swift, created on 04.11.2024
//
//

import AppStoreAPI
import AppStoreConnect
Expand Down Expand Up @@ -34,184 +34,25 @@ public struct AgeRatingDeclaration: Sendable {
public init?(schema: AppStoreAPI.AgeRatingDeclaration) {
guard let attributes = schema.attributes else { return nil }
id = schema.id

}

}

/*
import AppStoreAPI
import AppStoreConnect
import Foundation

public struct AgeRatingDeclaration: Codable, Equatable, Identifiable, Sendable {
public var type: `Type`
public var id: String
public var attributes: Attributes?
public var links: ResourceLinks?

public enum `Type`: String, CaseIterable, Codable, Sendable {
case ageRatingDeclarations
}

public struct Attributes: Codable, Equatable, Sendable {
public var alcoholTobaccoOrDrugUseOrReferences: AlcoholTobaccoOrDrugUseOrReferences?
public var contests: Contests?
public var isGamblingAndContests: Bool?
public var isGambling: Bool?
public var gamblingSimulated: GamblingSimulated?
public var kidsAgeBand: KidsAgeBand?
public var isLootBox: Bool?
public var medicalOrTreatmentInformation: MedicalOrTreatmentInformation?
public var profanityOrCrudeHumor: ProfanityOrCrudeHumor?
public var sexualContentGraphicAndNudity: SexualContentGraphicAndNudity?
public var sexualContentOrNudity: SexualContentOrNudity?
public var horrorOrFearThemes: HorrorOrFearThemes?
public var matureOrSuggestiveThemes: MatureOrSuggestiveThemes?
public var isUnrestrictedWebAccess: Bool?
public var violenceCartoonOrFantasy: ViolenceCartoonOrFantasy?
public var violenceRealisticProlongedGraphicOrSadistic: ViolenceRealisticProlongedGraphicOrSadistic?
public var violenceRealistic: ViolenceRealistic?
public var ageRatingOverride: AgeRatingOverride?
public var koreaAgeRatingOverride: KoreaAgeRatingOverride?
public var isSeventeenPlus: Bool?

public enum AlcoholTobaccoOrDrugUseOrReferences: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case infrequentOrMild = "INFREQUENT_OR_MILD"
case frequentOrIntense = "FREQUENT_OR_INTENSE"
}

public enum Contests: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case infrequentOrMild = "INFREQUENT_OR_MILD"
case frequentOrIntense = "FREQUENT_OR_INTENSE"
}

public enum GamblingSimulated: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case infrequentOrMild = "INFREQUENT_OR_MILD"
case frequentOrIntense = "FREQUENT_OR_INTENSE"
}

public enum MedicalOrTreatmentInformation: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case infrequentOrMild = "INFREQUENT_OR_MILD"
case frequentOrIntense = "FREQUENT_OR_INTENSE"
}

public enum ProfanityOrCrudeHumor: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case infrequentOrMild = "INFREQUENT_OR_MILD"
case frequentOrIntense = "FREQUENT_OR_INTENSE"
}

public enum SexualContentGraphicAndNudity: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case infrequentOrMild = "INFREQUENT_OR_MILD"
case frequentOrIntense = "FREQUENT_OR_INTENSE"
}

public enum SexualContentOrNudity: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case infrequentOrMild = "INFREQUENT_OR_MILD"
case frequentOrIntense = "FREQUENT_OR_INTENSE"
}

public enum HorrorOrFearThemes: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case infrequentOrMild = "INFREQUENT_OR_MILD"
case frequentOrIntense = "FREQUENT_OR_INTENSE"
}

public enum MatureOrSuggestiveThemes: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case infrequentOrMild = "INFREQUENT_OR_MILD"
case frequentOrIntense = "FREQUENT_OR_INTENSE"
}

public enum ViolenceCartoonOrFantasy: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case infrequentOrMild = "INFREQUENT_OR_MILD"
case frequentOrIntense = "FREQUENT_OR_INTENSE"
}

public enum ViolenceRealisticProlongedGraphicOrSadistic: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case infrequentOrMild = "INFREQUENT_OR_MILD"
case frequentOrIntense = "FREQUENT_OR_INTENSE"
}

public enum ViolenceRealistic: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case infrequentOrMild = "INFREQUENT_OR_MILD"
case frequentOrIntense = "FREQUENT_OR_INTENSE"
}

public enum AgeRatingOverride: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case seventeenPlus = "SEVENTEEN_PLUS"
case unrated = "UNRATED"
}

public enum KoreaAgeRatingOverride: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case fifteenPlus = "FIFTEEN_PLUS"
case nineteenPlus = "NINETEEN_PLUS"
}

public init(alcoholTobaccoOrDrugUseOrReferences: AlcoholTobaccoOrDrugUseOrReferences? = nil, contests: Contests? = nil, isGamblingAndContests: Bool? = nil, isGambling: Bool? = nil, gamblingSimulated: GamblingSimulated? = nil, kidsAgeBand: KidsAgeBand? = nil, isLootBox: Bool? = nil, medicalOrTreatmentInformation: MedicalOrTreatmentInformation? = nil, profanityOrCrudeHumor: ProfanityOrCrudeHumor? = nil, sexualContentGraphicAndNudity: SexualContentGraphicAndNudity? = nil, sexualContentOrNudity: SexualContentOrNudity? = nil, horrorOrFearThemes: HorrorOrFearThemes? = nil, matureOrSuggestiveThemes: MatureOrSuggestiveThemes? = nil, isUnrestrictedWebAccess: Bool? = nil, violenceCartoonOrFantasy: ViolenceCartoonOrFantasy? = nil, violenceRealisticProlongedGraphicOrSadistic: ViolenceRealisticProlongedGraphicOrSadistic? = nil, violenceRealistic: ViolenceRealistic? = nil, ageRatingOverride: AgeRatingOverride? = nil, koreaAgeRatingOverride: KoreaAgeRatingOverride? = nil, isSeventeenPlus: Bool? = nil) {
self.alcoholTobaccoOrDrugUseOrReferences = alcoholTobaccoOrDrugUseOrReferences
self.contests = contests
self.isGamblingAndContests = isGamblingAndContests
self.isGambling = isGambling
self.gamblingSimulated = gamblingSimulated
self.kidsAgeBand = kidsAgeBand
self.isLootBox = isLootBox
self.medicalOrTreatmentInformation = medicalOrTreatmentInformation
self.profanityOrCrudeHumor = profanityOrCrudeHumor
self.sexualContentGraphicAndNudity = sexualContentGraphicAndNudity
self.sexualContentOrNudity = sexualContentOrNudity
self.horrorOrFearThemes = horrorOrFearThemes
self.matureOrSuggestiveThemes = matureOrSuggestiveThemes
self.isUnrestrictedWebAccess = isUnrestrictedWebAccess
self.violenceCartoonOrFantasy = violenceCartoonOrFantasy
self.violenceRealisticProlongedGraphicOrSadistic = violenceRealisticProlongedGraphicOrSadistic
self.violenceRealistic = violenceRealistic
self.ageRatingOverride = ageRatingOverride
self.koreaAgeRatingOverride = koreaAgeRatingOverride
self.isSeventeenPlus = isSeventeenPlus
}

private enum CodingKeys: String, CodingKey {
case alcoholTobaccoOrDrugUseOrReferences
case contests
case isGamblingAndContests = "gamblingAndContests"
case isGambling = "gambling"
case gamblingSimulated
case kidsAgeBand
case isLootBox = "lootBox"
case medicalOrTreatmentInformation
case profanityOrCrudeHumor
case sexualContentGraphicAndNudity
case sexualContentOrNudity
case horrorOrFearThemes
case matureOrSuggestiveThemes
case isUnrestrictedWebAccess = "unrestrictedWebAccess"
case violenceCartoonOrFantasy
case violenceRealisticProlongedGraphicOrSadistic
case violenceRealistic
case ageRatingOverride
case koreaAgeRatingOverride
case isSeventeenPlus = "seventeenPlus"
}
}

public init(type: `Type` = .ageRatingDeclarations, id: String, attributes: Attributes? = nil, links: ResourceLinks? = nil) {
self.type = type
self.id = id
self.attributes = attributes
self.links = links
alcoholTobaccoOrDrugUseOrReferences = attributes.alcoholTobaccoOrDrugUseOrReferences.flatMap { AppStoreAgeRatingDeclaration(rawValue: $0.rawValue) }
contests = attributes.contests.flatMap { AppStoreAgeRatingDeclaration(rawValue: $0.rawValue) }
isGamblingAndContests = attributes.isGamblingAndContests
isGambling = attributes.isGambling
gamblingSimulated = attributes.gamblingSimulated.flatMap { AppStoreAgeRatingDeclaration(rawValue: $0.rawValue) }
kidsAgeBand = attributes.kidsAgeBand.flatMap { KidsAgeBand(rawValue: $0.rawValue) }
isLootBox = attributes.isLootBox
medicalOrTreatmentInformation = attributes.medicalOrTreatmentInformation.flatMap { AppStoreAgeRatingDeclaration(rawValue: $0.rawValue) }
profanityOrCrudeHumor = attributes.profanityOrCrudeHumor.flatMap { AppStoreAgeRatingDeclaration(rawValue: $0.rawValue) }
sexualContentGraphicAndNudity = attributes.sexualContentGraphicAndNudity.flatMap { AppStoreAgeRatingDeclaration(rawValue: $0.rawValue) }
sexualContentOrNudity = attributes.sexualContentOrNudity.flatMap { AppStoreAgeRatingDeclaration(rawValue: $0.rawValue) }
horrorOrFearThemes = attributes.horrorOrFearThemes.flatMap { AppStoreAgeRatingDeclaration(rawValue: $0.rawValue) }
matureOrSuggestiveThemes = attributes.matureOrSuggestiveThemes.flatMap { AppStoreAgeRatingDeclaration(rawValue: $0.rawValue) }
isUnrestrictedWebAccess = attributes.isUnrestrictedWebAccess
violenceCartoonOrFantasy = attributes.violenceCartoonOrFantasy.flatMap { AppStoreAgeRatingDeclaration(rawValue: $0.rawValue) }
violenceRealisticProlongedGraphicOrSadistic = attributes.violenceRealisticProlongedGraphicOrSadistic.flatMap { AppStoreAgeRatingDeclaration(rawValue: $0.rawValue) }
violenceRealistic = attributes.violenceRealistic.flatMap { AppStoreAgeRatingDeclaration(rawValue: $0.rawValue) }
ageRatingOverride = attributes.ageRatingOverride.flatMap { AgeRatingOverride(rawValue: $0.rawValue) }
koreaAgeRatingOverride = attributes.koreaAgeRatingOverride.flatMap { KoreaAgeRatingOverride(rawValue: $0.rawValue) }
isSeventeenPlus = attributes.isSeventeenPlus
}
}
*/
17 changes: 13 additions & 4 deletions Sources/OversizeAppStoreServices/Models/AppInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ public struct AppInfo: Sendable {

relationships = .init(
primaryCategoryId: schema.relationships?.primaryCategory?.data?.id,
secondaryCategoryId: schema.relationships?.secondaryCategory?.data?.id
secondaryCategoryId: schema.relationships?.secondaryCategory?.data?.id,
ageRatingDeclarationId: schema.relationships?.ageRatingDeclaration?.data?.id
)

var appCategories: [AppStoreAPI.AppCategory] = []
var ageRatingDeclarations: [AppStoreAPI.AgeRatingDeclaration] = []

if let includedItems = included {
for includedItem in includedItems {
switch includedItem {
case let .appCategory(appCategory):
appCategories.append(appCategory)
case let .ageRatingDeclaration(ageRatingDeclaration):
ageRatingDeclarations.append(ageRatingDeclaration)
default:
continue
}
Expand All @@ -57,11 +61,15 @@ public struct AppInfo: Sendable {
.first {
$0.id == schema.relationships?.secondaryCategory?.data?.id
}

let ageRatingDeclaration: AppStoreAPI.AgeRatingDeclaration? = ageRatingDeclarations
.first {
$0.id == schema.relationships?.ageRatingDeclaration?.data?.id
}
if let primaryCategory, let seconaryCategory {
self.included = .init(
primaryCategory: .init(schema: primaryCategory),
secondaryCategory: .init(schema: seconaryCategory)
secondaryCategory: .init(schema: seconaryCategory),
ageRatingDeclaration: ageRatingDeclaration != nil ? .init(schema: ageRatingDeclaration!) : nil
)
} else {
self.included = nil
Expand All @@ -74,11 +82,12 @@ public struct AppInfo: Sendable {
public struct Relationships: Sendable {
public let primaryCategoryId: String?
public let secondaryCategoryId: String?
public let ageRatingDeclarationId: String?
}

public struct Included: Sendable {
public let primaryCategory: AppCategory?
public let secondaryCategory: AppCategory?
//public let ageRatingDeclaration: AgeRatingDeclaration?
public let ageRatingDeclaration: AgeRatingDeclaration?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public struct AppStoreVersion: Sendable, Identifiable {
public let state: AppVersionState
public let copyright: String
public let reviewType: ReviewType?
public let releaseType: ReviewType?
public let releaseType: ReleaseType?
public let earliestReleaseDate: Date?
public let isDownloadable: Bool?
public let createdDate: Date?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ public enum KoreaAgeRating: String, CaseIterable, Codable, Sendable {
}

public enum AppStoreAgeRatingDeclaration: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case none = "NONE"
case infrequentOrMild = "INFREQUENT_OR_MILD"
case frequentOrIntense = "FREQUENT_OR_INTENSE"
}

public enum AgeRatingOverride: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case none = "NONE"
case seventeenPlus = "SEVENTEEN_PLUS"
case unrated = "UNRATED"
}

public enum KoreaAgeRatingOverride: String, CaseIterable, Codable, Sendable {
case `none` = "NONE"
case none = "NONE"
case fifteenPlus = "FIFTEEN_PLUS"
case nineteenPlus = "NINETEEN_PLUS"
}
25 changes: 25 additions & 0 deletions Sources/OversizeAppStoreServices/Models/Typs/ReleaseType.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Copyright © 2024 Alexander Romanov
// ReleaseType.swift, created on 04.11.2024
//

import Foundation

public enum ReleaseType: String, CaseIterable, Codable, Sendable, Identifiable {
case manual = "MANUAL"
case afterApproval = "AFTER_APPROVAL"
case scheduled = "SCHEDULED"

public var id: String { rawValue }

public var displayName: String {
switch self {
case .manual:
return "Manually release this version"
case .afterApproval:
return "Automatically release this version"
case .scheduled:
return "Automatically release this version after App Review, no earlier than"
}
}
}
40 changes: 40 additions & 0 deletions Sources/OversizeAppStoreServices/Services/VersionsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,46 @@ public actor VersionsService {
return .failure(.network(type: .noResponse))
}
}

public func patchVersion(
versionId: String,
versionString: String? = nil,
copyright: String? = nil,
reviewType: ReviewType? = nil,
releaseType: ReleaseType? = nil,
earliestReleaseDate _: Date? = nil,
isDownloadable: Bool? = nil
) async -> Result<AppStoreVersion, AppError> {
guard let client = client else { return .failure(.network(type: .unauthorized)) }

let requestAttributes: AppStoreVersionUpdateRequest.Data.Attributes = .init(
versionString: versionString,
copyright: copyright,
reviewType: .init(rawValue: reviewType?.rawValue ?? ""),
releaseType: .init(rawValue: releaseType?.rawValue ?? ""),
// earliestReleaseDate: earliestReleaseDate,
isDownloadable: isDownloadable
)

let requestData: AppStoreVersionUpdateRequest.Data = .init(
type: .appStoreVersions,
id: versionId,
attributes: requestAttributes
)

let request = Resources.v1.appStoreVersions.id(versionId).patch(.init(data: requestData))

do {
let data = try await client.send(request).data
guard let versionLocalization: AppStoreVersion = .init(schema: data) else {
return .failure(.network(type: .decode))
}
return .success(versionLocalization)
} catch {
print(error)
return .failure(.network(type: .noResponse))
}
}
}

public extension VersionsService {
Expand Down

0 comments on commit 648c47a

Please sign in to comment.