Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using old completion based MullvadREST interface #5470

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 16 additions & 36 deletions ios/MullvadREST/RESTAPIProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ public protocol APIQuerying {
receiptString: Data
) -> any RESTRequestExecutor<REST.CreateApplePaymentResponse>

func createApplePayment(
accountNumber: String,
receiptString: Data,
retryStrategy: REST.RetryStrategy,
completionHandler: @escaping ProxyCompletionHandler<REST.CreateApplePaymentResponse>
) -> Cancellable

func sendProblemReport(
_ body: REST.ProblemReportRequest,
retryStrategy: REST.RetryStrategy,
Expand Down Expand Up @@ -79,13 +72,13 @@ extension REST {
with: responseDecoder
)

return addOperation(
let executor = makeRequestExecutor(
name: "get-api-addrs",
retryStrategy: retryStrategy,
requestHandler: requestHandler,
responseHandler: responseHandler,
completionHandler: completionHandler
responseHandler: responseHandler
)

return executor.execute(retryStrategy: retryStrategy, completionHandler: completionHandler)
}

public func getRelays(
Expand Down Expand Up @@ -136,13 +129,13 @@ extension REST {
}
}

return addOperation(
let executor = makeRequestExecutor(
name: "get-relays",
retryStrategy: retryStrategy,
requestHandler: requestHandler,
responseHandler: responseHandler,
completionHandler: completionHandler
responseHandler: responseHandler
)

return executor.execute(retryStrategy: retryStrategy, completionHandler: completionHandler)
}

public func createApplePayment(
Expand Down Expand Up @@ -202,19 +195,6 @@ extension REST {
)
}

@available(*, deprecated, message: "Use createApplePayment(accountNumber:, receiptString:) instead")
public func createApplePayment(
accountNumber: String,
receiptString: Data,
retryStrategy: REST.RetryStrategy,
completionHandler: @escaping ProxyCompletionHandler<CreateApplePaymentResponse>
) -> Cancellable {
return createApplePayment(accountNumber: accountNumber, receiptString: receiptString).execute(
retryStrategy: retryStrategy,
completionHandler: completionHandler
)
}

public func sendProblemReport(
_ body: ProblemReportRequest,
retryStrategy: REST.RetryStrategy,
Expand Down Expand Up @@ -246,13 +226,13 @@ extension REST {
}
}

return addOperation(
let executor = makeRequestExecutor(
name: "send-problem-report",
retryStrategy: retryStrategy,
requestHandler: requestHandler,
responseHandler: responseHandler,
completionHandler: completionHandler
responseHandler: responseHandler
)

return executor.execute(retryStrategy: retryStrategy, completionHandler: completionHandler)
}

public func submitVoucher(
Expand Down Expand Up @@ -290,13 +270,13 @@ extension REST {
}
}

return addOperation(
let executor = makeRequestExecutor(
name: "submit-voucher",
retryStrategy: retryStrategy,
requestHandler: requestHandler,
responseHandler: responseHandler,
completionHandler: completionHandler
responseHandler: responseHandler
)

return executor.execute(retryStrategy: retryStrategy, completionHandler: completionHandler)
}
}

Expand Down
34 changes: 8 additions & 26 deletions ios/MullvadREST/RESTAccountsProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ public protocol RESTAccountHandling {

func getAccountData(accountNumber: String) -> any RESTRequestExecutor<Account>

func getAccountData(
accountNumber: String,
retryStrategy: REST.RetryStrategy,
completion: @escaping ProxyCompletionHandler<Account>
) -> Cancellable

func deleteAccount(
accountNumber: String,
retryStrategy: REST.RetryStrategy,
Expand Down Expand Up @@ -61,13 +55,13 @@ extension REST {
with: responseDecoder
)

return addOperation(
let executor = makeRequestExecutor(
name: "create-account",
retryStrategy: retryStrategy,
requestHandler: requestHandler,
responseHandler: responseHandler,
completionHandler: completion
responseHandler: responseHandler
)

return executor.execute(retryStrategy: retryStrategy, completionHandler: completion)
}

public func getAccountData(accountNumber: String) -> any RESTRequestExecutor<Account> {
Expand Down Expand Up @@ -98,18 +92,6 @@ extension REST {
)
}

@available(*, deprecated, message: "Use getAccountData(accountNumber:) instead")
public func getAccountData(
accountNumber: String,
retryStrategy: REST.RetryStrategy,
completion: @escaping ProxyCompletionHandler<Account>
) -> Cancellable {
return getAccountData(accountNumber: accountNumber).execute(
retryStrategy: retryStrategy,
completionHandler: completion
)
}

public func deleteAccount(
accountNumber: String,
retryStrategy: RetryStrategy,
Expand Down Expand Up @@ -143,13 +125,13 @@ extension REST {
}
}

return addOperation(
let executor = makeRequestExecutor(
name: "delete-my-account",
retryStrategy: retryStrategy,
requestHandler: requestHandler,
responseHandler: responseHandler,
completionHandler: completion
responseHandler: responseHandler
)

return executor.execute(retryStrategy: retryStrategy, completionHandler: completion)
}
}

Expand Down
8 changes: 4 additions & 4 deletions ios/MullvadREST/RESTAuthenticationProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ extension REST {
with: responseDecoder
)

return addOperation(
let executor = makeRequestExecutor(
name: "get-access-token",
retryStrategy: retryStrategy,
requestHandler: requestHandler,
responseHandler: responseHandler,
completionHandler: completion
responseHandler: responseHandler
)

return executor.execute(retryStrategy: retryStrategy, completionHandler: completion)
}
}

Expand Down
40 changes: 20 additions & 20 deletions ios/MullvadREST/RESTDevicesProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ extension REST {
}
}

return addOperation(
let executor = makeRequestExecutor(
name: "get-device",
retryStrategy: retryStrategy,
requestHandler: requestHandler,
responseHandler: responseHandler,
completionHandler: completion
responseHandler: responseHandler
)

return executor.execute(retryStrategy: retryStrategy, completionHandler: completion)
}

/// Fetch a list of created devices.
Expand Down Expand Up @@ -145,13 +145,13 @@ extension REST {
with: responseDecoder
)

return addOperation(
let executor = makeRequestExecutor(
name: "get-devices",
retryStrategy: retryStrategy,
requestHandler: requestHandler,
responseHandler: responseHandler,
completionHandler: completion
responseHandler: responseHandler
)

return executor.execute(retryStrategy: retryStrategy, completionHandler: completion)
}

/// Create new device.
Expand Down Expand Up @@ -184,13 +184,13 @@ extension REST {
with: responseDecoder
)

return addOperation(
let executor = makeRequestExecutor(
name: "create-device",
retryStrategy: retryStrategy,
requestHandler: requestHandler,
responseHandler: responseHandler,
completionHandler: completion
responseHandler: responseHandler
)

return executor.execute(retryStrategy: retryStrategy, completionHandler: completion)
}

/// Delete device by identifier.
Expand Down Expand Up @@ -247,13 +247,13 @@ extension REST {
}
}

return addOperation(
let executor = makeRequestExecutor(
name: "delete-device",
retryStrategy: retryStrategy,
requestHandler: requestHandler,
responseHandler: responseHandler,
completionHandler: completion
responseHandler: responseHandler
)

return executor.execute(retryStrategy: retryStrategy, completionHandler: completion)
}

/// Rotate device key
Expand Down Expand Up @@ -300,13 +300,13 @@ extension REST {
with: responseDecoder
)

return addOperation(
let executor = makeRequestExecutor(
name: "rotate-device-key",
retryStrategy: retryStrategy,
requestHandler: requestHandler,
responseHandler: responseHandler,
completionHandler: completion
responseHandler: responseHandler
)

return executor.execute(retryStrategy: retryStrategy, completionHandler: completion)
}
}

Expand Down
17 changes: 0 additions & 17 deletions ios/MullvadREST/RESTProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,6 @@ extension REST {
self.responseDecoder = responseDecoder
}

@available(*, deprecated, message: "Use makeRequestExecutor() instead")
func addOperation<Success>(
name: String,
retryStrategy: REST.RetryStrategy,
requestHandler: RESTRequestHandler,
responseHandler: some RESTResponseHandler<Success>,
completionHandler: @escaping ProxyCompletionHandler<Success>
) -> Cancellable {
let executor = makeRequestExecutor(
name: name,
requestHandler: requestHandler,
responseHandler: responseHandler
)

return executor.execute(retryStrategy: retryStrategy, completionHandler: completionHandler)
}

func makeRequestExecutor<Success>(
name: String,
requestHandler: RESTRequestHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ class SendStoreReceiptOperation: ResultOperation<REST.CreateApplePaymentResponse
private func sendReceipt(_ receiptData: Data) {
submitReceiptTask = apiProxy.createApplePayment(
accountNumber: accountNumber,
receiptString: receiptData,
retryStrategy: .noRetry
) { result in
receiptString: receiptData
).execute(retryStrategy: .noRetry) { result in
switch result {
case let .success(response):
self.logger.info(
Expand Down
5 changes: 2 additions & 3 deletions ios/MullvadVPN/StorePaymentManager/StorePaymentManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,9 @@ final class StorePaymentManager: NSObject, SKPaymentTransactionObserver {
completionHandler: @escaping (StorePaymentManagerError?) -> Void
) {
let accountOperation = ResultBlockOperation<Account>(dispatchQueue: .main) { finish in
self.accountsProxy.getAccountData(
accountNumber: accountNumber,
self.accountsProxy.getAccountData(accountNumber: accountNumber).execute(
retryStrategy: .default,
completion: finish
completionHandler: finish
)
}

Expand Down
35 changes: 18 additions & 17 deletions ios/MullvadVPN/TunnelManager/SetAccountOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,26 +239,27 @@ class SetAccountOperation: ResultOperation<StoredAccountData?> {
private func getAccount(accountNumber: String, completion: @escaping (Result<StoredAccountData, Error>) -> Void) {
logger.debug("Request account data...")

let task = accountsProxy
.getAccountData(accountNumber: accountNumber, retryStrategy: .default) { [self] result in
dispatchQueue.async { [self] in
let result = result.inspectError { error in
guard !error.isOperationCancellationError else { return }

logger.error(error: error, message: "Failed to receive account data.")
}.map { accountData -> StoredAccountData in
logger.debug("Received account data.")

return StoredAccountData(
identifier: accountData.id,
number: accountNumber,
expiry: accountData.expiry
)
}
let task = accountsProxy.getAccountData(accountNumber: accountNumber).execute(
retryStrategy: .default
) { [self] result in
dispatchQueue.async { [self] in
let result = result.inspectError { error in
guard !error.isOperationCancellationError else { return }

completion(result)
logger.error(error: error, message: "Failed to receive account data.")
}.map { accountData -> StoredAccountData in
logger.debug("Received account data.")

return StoredAccountData(
identifier: accountData.id,
number: accountNumber,
expiry: accountData.expiry
)
}

completion(result)
}
}

tasks.append(task)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class UpdateAccountDataOperation: ResultOperation<Void> {
return
}

task = accountsProxy.getAccountData(
accountNumber: accountData.number,
task = accountsProxy.getAccountData(accountNumber: accountData.number).execute(
retryStrategy: .default
) { result in
self.dispatchQueue.async {
Expand Down
Loading
Loading