Skip to content

Commit 345a1db

Browse files
committed
Use built-in Result type
1 parent f0aa521 commit 345a1db

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

iProovAPIClient.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'iProovAPIClient'
3-
s.version = '1.0.1'
3+
s.version = '1.1.0'
44
s.summary = 'iOS API Client for iProov REST API v2'
55
s.homepage = 'https://github.com/iproov/ios-api-client'
66
s.license = { :type => 'BSD-3', :file => 'LICENSE' }

iProovAPIClient/Classes/APIClient.swift

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ public enum AssuranceType: String {
2222
case liveness
2323
}
2424

25-
public enum Result<T> {
26-
case success(T)
27-
case failure(Error)
28-
}
29-
3025
public class APIClient {
3126
private let baseURL: String
3227
private let apiKey: String
@@ -76,7 +71,7 @@ public class APIClient {
7671
type: ClaimType,
7772
userID: String,
7873
additionalOptions: [String: Any] = [:],
79-
completion: @escaping (Result<String>) -> Void) {
74+
completion: @escaping (Result<String, Swift.Error>) -> Void) {
8075

8176
let url = String(format: "%@/claim/%@/token", baseURL, type.rawValue)
8277

@@ -101,7 +96,7 @@ public class APIClient {
10196
public func enrolPhoto(token: String,
10297
image: UIImage,
10398
source: PhotoSource,
104-
completion: @escaping (Result<String>) -> Void) {
99+
completion: @escaping (Result<String, Swift.Error>) -> Void) {
105100

106101
let url = String(format: "%@/claim/enrol/image", baseURL)
107102

@@ -126,7 +121,7 @@ public class APIClient {
126121

127122
public func validate(token: String,
128123
userID: String,
129-
completion: @escaping (Result<ValidationResult>) -> Void) {
124+
completion: @escaping (Result<ValidationResult, Swift.Error>) -> Void) {
130125

131126
let url = String(format: "%@/claim/verify/validate", baseURL)
132127

@@ -171,7 +166,7 @@ public extension APIClient {
171166
private struct ErrorSink<T> {
172167
let failure: (Swift.Error) -> Void
173168

174-
func onSuccess(_ next: @escaping (T) -> Void) -> (Result<T>) -> Void {
169+
func onSuccess(_ next: @escaping (T) -> Void) -> (Result<T, Swift.Error>) -> Void {
175170
return { result in
176171
switch result {
177172
case let .success(value):
@@ -187,7 +182,7 @@ public extension APIClient {
187182
func enrolPhotoAndGetVerifyToken(userID: String,
188183
image: UIImage,
189184
source: PhotoSource,
190-
completion: @escaping (Result<String>) -> Void) {
185+
completion: @escaping (Result<String, Swift.Error>) -> Void) {
191186

192187
let errorSink = ErrorSink<String> { completion(.failure($0)) }
193188

@@ -203,7 +198,7 @@ public extension APIClient {
203198
extension DataRequest {
204199

205200
@discardableResult
206-
public func responseToken(completionHandler: @escaping (Result<String>) -> Void) -> Self {
201+
public func responseToken(completionHandler: @escaping (Result<String, Swift.Error>) -> Void) -> Self {
207202

208203
responseJSON { response in
209204
switch response.result {

0 commit comments

Comments
 (0)