Skip to content

Commit

Permalink
Add patchAppInfoLocalization
Browse files Browse the repository at this point in the history
  • Loading branch information
aromanov91 committed Dec 4, 2024
1 parent 98bf89e commit 1fa00e8
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
15 changes: 15 additions & 0 deletions Sources/OversizeAppStoreServices/Models/AppInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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) }
Expand Down Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion Sources/OversizeAppStoreServices/Models/Build.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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
Expand Down
39 changes: 39 additions & 0 deletions Sources/OversizeAppStoreServices/Services/AppInfoService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<AppInfoLocalization, AppError> {
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))
}
}
}
21 changes: 20 additions & 1 deletion Sources/OversizeAppStoreServices/Services/VersionsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 1fa00e8

Please sign in to comment.