Skip to content

Instantly share code, notes, and snippets.

@matiasdim
Created March 4, 2021 23:55
Show Gist options
  • Save matiasdim/92df51ad58ef62f0fa8b5147adc5181a to your computer and use it in GitHub Desktop.
Save matiasdim/92df51ad58ef62f0fa8b5147adc5181a to your computer and use it in GitHub Desktop.
file.swift
//
// CustomAccountsUseCase.swift
// Banesco
//
// Created by Matías Gil Echavarría on 4/03/21.
//
import Foundation
import RetailAccountsAndTransactionsJourney
import Resolver
import Backbase
import ArrangementsClient2
class CustomAccountsUseCase: AccountsUseCase {
func retrieveAccounts(params: RetailAccountsAndTransactionsJourney.ProductSummary.GetRequestParameters?, completion: @escaping RetrieveAccountsHandler) {
let delay: TimeInterval = 0
do {
let call = try client.getProductSummaryCall(contentLanguage: params?.contentLanguage,
debitAccount: params?.debitAccount,
creditAccount: params?.creditAccount,
maskIndicator: params?.maskIndicator)
call.execute { /*[weak self] */ result in
// guard let self = self else { return }
switch result {
case let .success(response):
guard let productSummary = response.body as? RetailAccountsAndTransactionsJourney.ProductSummary? else {
return completion(.failure(ErrorResponse(error: AccountsAndTransactions.Error.invalidResponse)))
}
// ArrangementsClient2.ProductSummary
// RetailAccountsAndTransactionsJourney.ProductSummary
DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
// completion(.success( RetailAccountsAndTransactionsJourney.ProductSummary.init()))
completion(.success(ProductSummary(aggregatedBalance: productSummary)))
}
// completion(.success(ProductSummary(aggregatedBalance: productSummary)))
case let .failure(response):
completion(.failure(RetailAccountsAndTransactionsJourney.ErrorResponse(error: response)))
}
}
} catch {
completion(.failure(ErrorResponse(error: error)))
}
}
// MARK: - Private
private lazy var client: ProductSummaryAPIProtocol = {
guard let serverURL: URL = URL(string: Backbase.configuration().backbase.serverURL) else {
fatalError("Invalid or no serverURL found in the SDK configuration.")
}
let newServerURL = serverURL
.appendingPathComponent("api")
.appendingPathComponent("arrangement-manager")
if let dbsClient = Backbase.registered(client: ProductSummaryAPI.self),
let client = dbsClient as? ProductSummaryAPI {
return client
} else if let client = Resolver.optional(ProductSummaryAPI.self) {
return client
} else {
let client = ProductSummaryAPI()
client.baseURL = newServerURL
if let dataProvider = Resolver.optional(DBSDataProvider.self) {
client.dataProvider = dataProvider
return client
} else {
try? Backbase.register(client: client)
guard let dbsClient = Backbase.registered(client: ProductSummaryAPI.self),
let client = dbsClient as? ProductSummaryAPI else {
fatalError("Failed to retrieve Arrangements client")
}
return client
}
}
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment