Skip to content

Commit 2ed55b1

Browse files
committed
Create ReadBundleIdOperation and EnableBundleIdCapabilityOperation
2 parents 77524e3 + 7e7503b commit 2ed55b1

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed
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 bundleId: '\(bundleId)'."
21+
case .bundleIdNotUnique(let serial):
22+
return "The bundleId your provided '\(serial)' 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)