Skip to content

Commit

Permalink
Add patch methods
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Nov 3, 2024
1 parent 73195f2 commit 6906db1
Show file tree
Hide file tree
Showing 8 changed files with 430 additions and 5 deletions.
217 changes: 217 additions & 0 deletions Sources/OversizeAppStoreServices/Models/AgeRatingDeclaration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
//
// Copyright © 2024 Alexander Romanov
// AgeRatingDeclaration.swift, created on 04.11.2024
//

import AppStoreAPI
import AppStoreConnect
import OversizeCore

public struct AgeRatingDeclaration: Sendable {
public let id: String

public var alcoholTobaccoOrDrugUseOrReferences: AppStoreAgeRatingDeclaration?
public var contests: AppStoreAgeRatingDeclaration?
public var isGamblingAndContests: Bool?
public var isGambling: Bool?
public var gamblingSimulated: AppStoreAgeRatingDeclaration?
public var kidsAgeBand: KidsAgeBand?
public var isLootBox: Bool?
public var medicalOrTreatmentInformation: AppStoreAgeRatingDeclaration?
public var profanityOrCrudeHumor: AppStoreAgeRatingDeclaration?
public var sexualContentGraphicAndNudity: AppStoreAgeRatingDeclaration?
public var sexualContentOrNudity: AppStoreAgeRatingDeclaration?
public var horrorOrFearThemes: AppStoreAgeRatingDeclaration?
public var matureOrSuggestiveThemes: AppStoreAgeRatingDeclaration?
public var isUnrestrictedWebAccess: Bool?
public var violenceCartoonOrFantasy: AppStoreAgeRatingDeclaration?
public var violenceRealisticProlongedGraphicOrSadistic: AppStoreAgeRatingDeclaration?
public var violenceRealistic: AppStoreAgeRatingDeclaration?
public var ageRatingOverride: AgeRatingOverride?
public var koreaAgeRatingOverride: KoreaAgeRatingOverride?
public var isSeventeenPlus: Bool?

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
}
}
*/
3 changes: 2 additions & 1 deletion Sources/OversizeAppStoreServices/Models/AppInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import AppStoreConnect
import OversizeCore

public struct AppInfo: Sendable {
public let id: String?
public let id: String

public var appStoreState: AppStoreVersionState?
public let appStoreAgeRating: AppStoreAgeRating?
Expand Down Expand Up @@ -79,5 +79,6 @@ public struct AppInfo: Sendable {
public struct Included: Sendable {
public let primaryCategory: AppCategory?
public let secondaryCategory: AppCategory?
//public let ageRatingDeclaration: AgeRatingDeclaration?
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,21 @@ public enum KoreaAgeRating: String, CaseIterable, Codable, Sendable {
case nineteen = "NINETEEN"
case notApplicable = "NOT_APPLICABLE"
}

public enum AppStoreAgeRatingDeclaration: 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"
}
2 changes: 1 addition & 1 deletion Sources/OversizeAppStoreServices/ServiceRegistering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public extension Container {
var appStoreReviewService: Factory<AppStoreReviewService> {
self { AppStoreReviewService() }
}

var appCategoryService: Factory<AppCategoryService> {
self { AppCategoryService() }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Copyright © 2024 Alexander Romanov
// AppCategoryService.swift, created on 03.11.2024
//
//

import AppStoreAPI
import AppStoreConnect
Expand Down Expand Up @@ -60,4 +60,52 @@ public actor AppCategoryService {
return .failure(.network(type: .noResponse))
}
}

public func patchAppCategories(
appInfoId: String,
primaryCategoryId: String? = nil,
primarySubcategoryOneId: String? = nil,
primarySubcategoryTwoId: String? = nil,
secondaryCategoryId: String? = nil,
secondarySubcategoryOneId: String? = nil,
secondarySubcategoryTwoId: String? = nil
) async -> Result<AppInfo, AppError> {
guard let client = client else { return .failure(.network(type: .unauthorized)) }

let primaryCategory: AppInfoUpdateRequest.Data.Relationships.PrimaryCategory? = primaryCategoryId != nil ? .init(data: .init(id: primaryCategoryId!)) : nil
let primarySubcategoryOne: AppInfoUpdateRequest.Data.Relationships.PrimarySubcategoryOne? = primarySubcategoryOneId != nil ? .init(data: .init(id: primarySubcategoryOneId!)) : nil
let primarySubcategoryTwo: AppInfoUpdateRequest.Data.Relationships.PrimarySubcategoryTwo? = primarySubcategoryTwoId != nil ? .init(data: .init(id: primarySubcategoryTwoId!)) : nil
let secondaryCategory: AppInfoUpdateRequest.Data.Relationships.SecondaryCategory? = secondaryCategoryId != nil ? .init(data: .init(id: secondaryCategoryId!)) : nil
let secondarySubcategoryOne: AppInfoUpdateRequest.Data.Relationships.SecondarySubcategoryOne? = secondarySubcategoryOneId != nil ? .init(data: .init(id: secondarySubcategoryOneId!)) : nil
let secondarySubcategoryTwo: AppInfoUpdateRequest.Data.Relationships.SecondarySubcategoryTwo? = secondarySubcategoryTwoId != nil ? .init(data: .init(id: secondarySubcategoryTwoId!)) : nil

let requestRelationships: AppInfoUpdateRequest.Data.Relationships = .init(
primaryCategory: primaryCategory,
primarySubcategoryOne: primarySubcategoryOne,
primarySubcategoryTwo: primarySubcategoryTwo,
secondaryCategory: secondaryCategory,
secondarySubcategoryOne: secondarySubcategoryOne,
secondarySubcategoryTwo: secondarySubcategoryTwo
)

let requestData: AppInfoUpdateRequest.Data = .init(
type: .appInfos,
id: appInfoId,
relationships: requestRelationships
)

let request = Resources.v1.appInfos.id(appInfoId).patch(
.init(data: requestData)
)

do {
let data = try await client.send(request).data
guard let appStoreReviewDetail: AppInfo = .init(schema: data) else {
return .failure(.network(type: .decode))
}
return .success(appStoreReviewDetail)
} catch {
return .failure(.network(type: .noResponse))
}
}
}
Loading

0 comments on commit 6906db1

Please sign in to comment.