Skip to content

Commit 5b1f554

Browse files
authored
Merge pull request #186 from ittybittyapps/bundleid/enable-capability
Implement Enable bundleId Capability Command
2 parents 6254bab + 146eafc commit 5b1f554

File tree

7 files changed

+191
-0
lines changed

7 files changed

+191
-0
lines changed

Sources/AppStoreConnectCLI/AppStoreConnectCLI.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public struct AppStoreConnectCLI: ParsableCommand {
1515
ReportsCommand.self,
1616
TestFlightCommand.self,
1717
UsersCommand.self,
18+
CapabilityCommand.self
1819
])
1920

2021
public init() {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2020 Itty Bitty Apps Pty Ltd
2+
3+
import ArgumentParser
4+
5+
struct CapabilityCommand: ParsableCommand {
6+
static var configuration = CommandConfiguration(
7+
commandName: "capability",
8+
abstract: "Manage the app capabilities for a bundle ID.",
9+
subcommands: [
10+
EnableBundleIdCapabilityCommand.self
11+
]
12+
)
13+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2020 Itty Bitty Apps Pty Ltd
2+
3+
import AppStoreConnect_Swift_SDK
4+
import ArgumentParser
5+
6+
struct EnableBundleIdCapabilityCommand: CommonParsableCommand {
7+
8+
public static var configuration = CommandConfiguration(
9+
commandName: "enable",
10+
abstract: "Enable a capability for a bundle ID."
11+
)
12+
13+
@OptionGroup()
14+
var common: CommonOptions
15+
16+
@Argument(help: "The reverse-DNS bundle ID identifier to delete. Must be unique. (eg. com.example.app)")
17+
var bundleId: String
18+
19+
@Argument(help: "Bundle Id capability type. \n \(CapabilityType.allCases)")
20+
var capabilityType: CapabilityType
21+
22+
// TODO: CapabilitySetting
23+
24+
func run() throws {
25+
let service = try makeService()
26+
27+
try service.enableBundleIdCapability(
28+
bundleId: bundleId, capabilityType: capabilityType
29+
)
30+
}
31+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2020 Itty Bitty Apps Pty Ltd
2+
3+
import AppStoreConnect_Swift_SDK
4+
import ArgumentParser
5+
import Foundation
6+
7+
extension CapabilityType: CaseIterable, ExpressibleByArgument, CustomStringConvertible {
8+
public typealias AllCases = [CapabilityType]
9+
10+
public static var allCases: AllCases {
11+
[
12+
.icloud,
13+
.inAppPurchase,
14+
.gameCenter,
15+
.pushNotifications,
16+
.wallet,
17+
.interAppAudio,
18+
.maps,
19+
.associatedDomains,
20+
.personalVpn,
21+
.appGroups,
22+
.healthkit,
23+
.homekit,
24+
.wirelessAccessoryConfiguration,
25+
.applePay,
26+
.dataProtection,
27+
.sirikit,
28+
.networkExtensions,
29+
.multipath,
30+
.hotSpot,
31+
.nfcTagReading,
32+
.classkit,
33+
.autofillCredentialProvider,
34+
.accessWifiInformation
35+
]
36+
}
37+
38+
public init?(argument: String) {
39+
self.init(rawValue: argument.uppercased())
40+
}
41+
42+
public var description: String {
43+
rawValue.lowercased()
44+
}
45+
}

Sources/AppStoreConnectCLI/Services/AppStoreConnectService.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,24 @@ class AppStoreConnectService {
722722
.await()
723723
}
724724

725+
func enableBundleIdCapability(
726+
bundleId: String,
727+
capabilityType: CapabilityType
728+
) throws {
729+
let bundleIdResourceId = try ReadBundleIdOperation(
730+
options: .init(bundleId: bundleId)
731+
)
732+
.execute(with: requestor)
733+
.await()
734+
.id
735+
736+
_ = try EnableBundleIdCapabilityOperation(
737+
options: .init(bundleIdResourceId: bundleIdResourceId, capabilityType: capabilityType)
738+
)
739+
.execute(with: requestor)
740+
.await()
741+
}
742+
725743
/// Make a request for something `Decodable`.
726744
///
727745
/// - Parameters:
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2020 Itty Bitty Apps Pty Ltd
2+
3+
import AppStoreConnect_Swift_SDK
4+
import Combine
5+
import Foundation
6+
7+
struct EnableBundleIdCapabilityOperation: APIOperation {
8+
9+
struct Options {
10+
let bundleIdResourceId: String
11+
let capabilityType: CapabilityType
12+
}
13+
14+
let option: Options
15+
16+
init(options: Options) {
17+
self.option = options
18+
}
19+
20+
func execute(with requestor: EndpointRequestor) -> AnyPublisher<BundleIdCapabilityResponse, Error> {
21+
requestor
22+
.request(
23+
.enableCapability(
24+
id: option.bundleIdResourceId,
25+
capabilityType: option.capabilityType
26+
)
27+
)
28+
.eraseToAnyPublisher()
29+
}
30+
31+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2020 Itty Bitty Apps Pty Ltd
2+
3+
import AppStoreConnect_Swift_SDK
4+
import Combine
5+
import Foundation
6+
7+
struct ReadBundleIdOperation: APIOperation {
8+
9+
struct Options {
10+
let bundleId: String
11+
}
12+
13+
enum Error: LocalizedError {
14+
case couldNotFindBundleId(String)
15+
case bundleIdNotUnique(String)
16+
17+
var errorDescription: String? {
18+
switch self {
19+
case .couldNotFindBundleId(let bundleId):
20+
return "Couldn't find Bundle ID: '\(bundleId)'."
21+
case .bundleIdNotUnique(let bundleId):
22+
return "The Bundle ID you provided '\(bundleId)' is not unique."
23+
}
24+
}
25+
}
26+
27+
private let options: Options
28+
29+
init(options: Options) {
30+
self.options = options
31+
}
32+
33+
func execute(with requestor: EndpointRequestor) -> AnyPublisher<BundleId, Swift.Error> {
34+
requestor.request(
35+
.listBundleIds(
36+
filter: [.identifier([options.bundleId])]
37+
)
38+
)
39+
.tryMap {
40+
switch $0.data.count {
41+
case 0:
42+
throw Error.couldNotFindBundleId(self.options.bundleId)
43+
case 1:
44+
return $0.data.first!
45+
default:
46+
throw Error.bundleIdNotUnique(self.options.bundleId)
47+
}
48+
}
49+
.eraseToAnyPublisher()
50+
}
51+
52+
}

0 commit comments

Comments
 (0)