From 1fa00e85941e1d8ba2a7750fd165d008c24f9d53 Mon Sep 17 00:00:00 2001 From: Alexandr Romanov Date: Wed, 4 Dec 2024 23:26:50 +0300 Subject: [PATCH] Add patchAppInfoLocalization --- Package.swift | 8 ++-- .../Models/AppInfo.swift | 15 +++++++ .../Models/AppInfoLocalization.swift | 2 +- .../Models/Build.swift | 2 +- .../Models/VersionLocalization.swift | 4 +- .../Services/AppInfoService.swift | 39 +++++++++++++++++++ .../Services/VersionsService.swift | 21 +++++++++- 7 files changed, 82 insertions(+), 9 deletions(-) diff --git a/Package.swift b/Package.swift index e011f88..41fd71f 100644 --- a/Package.swift +++ b/Package.swift @@ -8,19 +8,19 @@ let commonDependencies: [PackageDescription.Package.Dependency] = [ .package(url: "https://github.com/aaronsky/asc-swift.git", .upToNextMajor(from: "1.0.1")), .package(url: "https://github.com/hmlongco/Factory.git", .upToNextMajor(from: "2.1.3")), .package(url: "https://github.com/1024jp/GzipSwift", .upToNextMajor(from: "6.1.0")), - .package(url: "https://github.com/dehesa/CodableCSV.git", .upToNextMajor(from: "0.6.7")) + .package(url: "https://github.com/dehesa/CodableCSV.git", .upToNextMajor(from: "0.6.7")), ] let remoteDependencies: [PackageDescription.Package.Dependency] = commonDependencies + [ .package(url: "https://github.com/oversizedev/OversizeCore.git", .upToNextMajor(from: "1.3.0")), .package(url: "https://github.com/oversizedev/OversizeServices.git", .upToNextMajor(from: "1.4.0")), - .package(url: "https://github.com/oversizedev/OversizeModels.git", .upToNextMajor(from: "0.1.0")) + .package(url: "https://github.com/oversizedev/OversizeModels.git", .upToNextMajor(from: "0.1.0")), ] let localDependencies: [PackageDescription.Package.Dependency] = commonDependencies + [ .package(name: "OversizeCore", path: "../OversizeCore"), .package(name: "OversizeModels", path: "../OversizeModels"), - .package(name: "OversizeServices", path: "../OversizeServices") + .package(name: "OversizeServices", path: "../OversizeServices"), ] var dependencies: [PackageDescription.Package.Dependency] = localDependencies @@ -54,7 +54,7 @@ let package = Package( .product(name: "OversizeModels", package: "OversizeModels"), .product(name: "OversizeServices", package: "OversizeServices"), .product(name: "Gzip", package: "GzipSwift"), - .product(name: "CodableCSV", package: "CodableCSV") + .product(name: "CodableCSV", package: "CodableCSV"), ] ), .testTarget( diff --git a/Sources/OversizeAppStoreServices/Models/AppInfo.swift b/Sources/OversizeAppStoreServices/Models/AppInfo.swift index 6249e97..3bb83b4 100644 --- a/Sources/OversizeAppStoreServices/Models/AppInfo.swift +++ b/Sources/OversizeAppStoreServices/Models/AppInfo.swift @@ -11,6 +11,7 @@ public struct AppInfo: Sendable { public let id: String public var appStoreState: AppStoreVersionState? + public var state: State? public let appStoreAgeRating: AppStoreAgeRating? public let australiaAgeRating: AustraliaAgeRating? public let brazilAgeRating: BrazilAgeRating? @@ -25,6 +26,7 @@ public struct AppInfo: Sendable { guard let attributes = schema.attributes else { return nil } id = schema.id appStoreState = attributes.appStoreState.flatMap { .init(rawValue: $0.rawValue) } + state = attributes.state.flatMap { .init(rawValue: $0.rawValue) } appStoreAgeRating = attributes.appStoreAgeRating.flatMap { AppStoreAgeRating(rawValue: $0.rawValue) } australiaAgeRating = attributes.australiaAgeRating.flatMap { AustraliaAgeRating(rawValue: $0.rawValue) } brazilAgeRating = attributes.brazilAgeRating.flatMap { BrazilAgeRating(rawValue: $0.rawValue) } @@ -90,4 +92,17 @@ public struct AppInfo: Sendable { public let secondaryCategory: AppCategory? public let ageRatingDeclaration: AgeRatingDeclaration? } + + public enum State: String, CaseIterable, Codable, Sendable { + case accepted = "ACCEPTED" + case developerRejected = "DEVELOPER_REJECTED" + case inReview = "IN_REVIEW" + case pendingRelease = "PENDING_RELEASE" + case prepareForSubmission = "PREPARE_FOR_SUBMISSION" + case readyForDistribution = "READY_FOR_DISTRIBUTION" + case readyForReview = "READY_FOR_REVIEW" + case rejected = "REJECTED" + case replacedWithNewInfo = "REPLACED_WITH_NEW_INFO" + case waitingForReview = "WAITING_FOR_REVIEW" + } } diff --git a/Sources/OversizeAppStoreServices/Models/AppInfoLocalization.swift b/Sources/OversizeAppStoreServices/Models/AppInfoLocalization.swift index a1af447..e6b57df 100644 --- a/Sources/OversizeAppStoreServices/Models/AppInfoLocalization.swift +++ b/Sources/OversizeAppStoreServices/Models/AppInfoLocalization.swift @@ -7,7 +7,7 @@ import AppStoreAPI import AppStoreConnect import Foundation -public struct AppInfoLocalization: Sendable { +public struct AppInfoLocalization: Sendable, Hashable, Identifiable { public let id: String public let locale: AppStoreLanguage? public let name: String? diff --git a/Sources/OversizeAppStoreServices/Models/Build.swift b/Sources/OversizeAppStoreServices/Models/Build.swift index 0dd4f6e..d5dd4b6 100644 --- a/Sources/OversizeAppStoreServices/Models/Build.swift +++ b/Sources/OversizeAppStoreServices/Models/Build.swift @@ -19,7 +19,7 @@ public struct Build: Sendable, Identifiable, Equatable { public let computedMinMacOsVersion: String? public let processingState: ProcessingState? public let buildAudienceType: BuildAudienceType? - + public let relationships: Relationships public init?(schema: AppStoreAPI.Build) { diff --git a/Sources/OversizeAppStoreServices/Models/VersionLocalization.swift b/Sources/OversizeAppStoreServices/Models/VersionLocalization.swift index e5a7708..7f93411 100644 --- a/Sources/OversizeAppStoreServices/Models/VersionLocalization.swift +++ b/Sources/OversizeAppStoreServices/Models/VersionLocalization.swift @@ -12,7 +12,7 @@ public struct VersionLocalization: Identifiable, Hashable, Sendable { public let id: String public let locale: AppStoreLanguage public let description: String? - public let keywords: String? + public let keywords: String public let marketingURL: URL? public let promotionalText: String? public let supportURL: URL? @@ -24,7 +24,7 @@ public struct VersionLocalization: Identifiable, Hashable, Sendable { id = schema.id self.locale = locale description = schema.attributes?.description - keywords = schema.attributes?.keywords + keywords = schema.attributes?.keywords ?? "" marketingURL = schema.attributes?.marketingURL promotionalText = schema.attributes?.promotionalText supportURL = schema.attributes?.supportURL diff --git a/Sources/OversizeAppStoreServices/Services/AppInfoService.swift b/Sources/OversizeAppStoreServices/Services/AppInfoService.swift index 7e2ce0e..825cd62 100644 --- a/Sources/OversizeAppStoreServices/Services/AppInfoService.swift +++ b/Sources/OversizeAppStoreServices/Services/AppInfoService.swift @@ -141,4 +141,43 @@ public actor AppInfoService { return .failure(.network(type: .noResponse)) } } + + public func patchAppInfoLocalization( + localizationId: String, + name: String? = nil, + subtitle: String? = nil, + privacyPolicyURL: String? = nil, + privacyChoicesURL: String? = nil, + privacyPolicyText: String? = nil + ) async -> Result { + guard let client else { return .failure(.network(type: .unauthorized)) } + + let requestAttributes: AppInfoLocalizationUpdateRequest.Data.Attributes = .init( + name: name, + subtitle: subtitle, + privacyPolicyURL: privacyPolicyURL, + privacyChoicesURL: privacyChoicesURL, + privacyPolicyText: privacyPolicyText + ) + + let requestData: AppInfoLocalizationUpdateRequest.Data = .init( + type: .appInfoLocalizations, + id: localizationId, + attributes: requestAttributes + ) + + let request = Resources.v1.appInfoLocalizations.id(localizationId).patch( + .init(data: requestData) + ) + + do { + let data = try await client.send(request).data + guard let versionLocalization: AppInfoLocalization = .init(schema: data) else { + return .failure(.network(type: .decode)) + } + return .success(versionLocalization) + } catch { + return .failure(.network(type: .noResponse)) + } + } } diff --git a/Sources/OversizeAppStoreServices/Services/VersionsService.swift b/Sources/OversizeAppStoreServices/Services/VersionsService.swift index 12d79d6..b252ce1 100644 --- a/Sources/OversizeAppStoreServices/Services/VersionsService.swift +++ b/Sources/OversizeAppStoreServices/Services/VersionsService.swift @@ -30,6 +30,25 @@ public actor VersionsService { } } + public func fetchEditableAppVersions(appId: String) async -> Result<[AppStoreVersion], AppError> { + guard let client else { return .failure(.network(type: .unauthorized)) } + let request = Resources.v1.apps.id(appId).appStoreVersions.get( + filterAppVersionState: [ + .prepareForSubmission, + .metadataRejected, + .developerRejected, + .rejected, + .invalidBinary, + ] + ) + do { + let data = try await client.send(request).data + return .success(data.compactMap { .init(schema: $0) }) + } catch { + return .failure(.network(type: .noResponse)) + } + } + public func fetchRelisedAppVersions(appId: String) async -> Result<[AppStoreVersion], AppError> { guard let client else { return .failure(.network(type: .unauthorized)) } let request = Resources.v1.apps.id(appId).appStoreVersions.get( @@ -107,7 +126,7 @@ public actor VersionsService { } } - public func fetchAppVersionLocalizations(forVersion versionId: String) async -> Result<[VersionLocalization], AppError> { + public func fetchAppVersionLocalizations(versionId: String) async -> Result<[VersionLocalization], AppError> { guard let client else { return .failure(.network(type: .unauthorized)) } let request = Resources.v1.appStoreVersions.id(versionId).appStoreVersionLocalizations.get() do {