Renamed getAccountData() to getAccountDataAsync() and added extensions methods for blocking calls to it

This commit is contained in:
dankito 2022-02-21 23:42:45 +01:00
parent ee68dd09b2
commit 3368c70202
8 changed files with 45 additions and 18 deletions

View File

@ -36,7 +36,7 @@ open class Presenter {
open fun retrieveAccountData(bankCode: String, loginName: String, password: String, retrievedResult: (GetAccountDataResponse) -> Unit) {
GlobalScope.launch(Dispatchers.IO) {
val response = fintsClient.getAccountData(GetAccountDataParameter(bankCode, loginName, password))
val response = fintsClient.getAccountDataAsync(GetAccountDataParameter(bankCode, loginName, password))
log.info("Retrieved response from ${response.customerAccount?.bankName} for ${response.customerAccount?.customerName}")
withContext(Dispatchers.Main) {

View File

@ -34,7 +34,7 @@ open class Presenter {
open fun retrieveAccountData(bankCode: String, loginName: String, password: String, retrievedResult: (GetAccountDataResponse) -> Unit) {
GlobalScope.launch(Dispatchers.Unconfined) {
val response = fintsClient.getAccountData(GetAccountDataParameter(bankCode, loginName, password))
val response = fintsClient.getAccountDataAsync(GetAccountDataParameter(bankCode, loginName, password))
log.info("Retrieved response from ${response.customerAccount?.bankName} for ${response.customerAccount?.customerName}")

View File

@ -19,7 +19,7 @@ class Presenter : ObservableObject {
func getAccountData(_ bankCode: String, _ customerId: String, _ pin: String, _ finTs3ServerAddress: String, _ callback: @escaping (GetAccountDataResponse) -> Void) {
self.fintsClient.getAccountData(parameter: GetAccountDataParameter(bankCode: bankCode, customerId: customerId, pin: pin, finTs3ServerAddress: finTs3ServerAddress), callback: callback)
self.fintsClient.getAccountDataAsync(parameter: GetAccountDataParameter(bankCode: bankCode, customerId: customerId, pin: pin, finTs3ServerAddress: finTs3ServerAddress), callback: callback)
}

View File

@ -37,11 +37,11 @@ open class FinTsClient @JvmOverloads constructor(
protected open val mapper = FinTsModelMapper()
open suspend fun getAccountData(bankCode: String, loginName: String, password: String): GetAccountDataResponse {
return getAccountData(GetAccountDataParameter(bankCode, loginName, password))
open suspend fun getAccountDataAsync(bankCode: String, loginName: String, password: String): GetAccountDataResponse {
return getAccountDataAsync(GetAccountDataParameter(bankCode, loginName, password))
}
open suspend fun getAccountData(param: GetAccountDataParameter): GetAccountDataResponse {
open suspend fun getAccountDataAsync(param: GetAccountDataParameter): GetAccountDataResponse {
val finTsServerAddress = finTsServerAddressFinder.findFinTsServerAddress(param.bankCode)
if (finTsServerAddress.isNullOrBlank()) {
return GetAccountDataResponse(ErrorCode.BankDoesNotSupportFinTs3, "Either bank does not FinTS 3.0 or we don't know its FinTS server address", null, listOf())

View File

@ -20,9 +20,9 @@ open class iOSFinTsClient(
}
open fun getAccountData(parameter: GetAccountDataParameter, callback: (GetAccountDataResponse) -> Unit) {
open fun getAccountDataAsync(parameter: GetAccountDataParameter, callback: (GetAccountDataResponse) -> Unit) {
GlobalScope.launch(Dispatchers.Main) { // do not block UI thread as with runBlocking { } but stay on UI thread as passing mutable state between threads currently doesn't work in Kotlin/Native
callback(fintsClient.getAccountData(parameter))
callback(fintsClient.getAccountDataAsync(parameter))
}
}

View File

@ -0,0 +1,14 @@
package net.dankito.banking.fints
import kotlinx.coroutines.runBlocking
import net.dankito.banking.client.model.parameter.GetAccountDataParameter
import net.dankito.banking.client.model.response.GetAccountDataResponse
fun FinTsClient.getAccountData(bankCode: String, loginName: String, password: String): GetAccountDataResponse {
return runBlocking { getAccountDataAsync(bankCode, loginName, password) }
}
fun FinTsClient.getAccountData(param: GetAccountDataParameter): GetAccountDataResponse {
return runBlocking { getAccountDataAsync(param) }
}

View File

@ -5,6 +5,7 @@ import net.dankito.banking.client.model.CustomerAccount
import net.dankito.banking.client.model.parameter.GetAccountDataParameter
import net.dankito.banking.fints.FinTsClient
import net.dankito.banking.fints.callback.SimpleFinTsClientCallback
import net.dankito.banking.fints.getAccountData
import net.dankito.banking.fints.model.TanChallenge
import net.dankito.utils.multiplatform.extensions.*
import platform.posix.exit
@ -22,20 +23,18 @@ fun main(args: Array<String>) {
class Application {
fun retrieveAccountData(bankCode: String, loginName: String, password: String) {
runBlocking {
val client = FinTsClient(SimpleFinTsClientCallback { tanChallenge -> enterTan(tanChallenge) })
val client = FinTsClient(SimpleFinTsClientCallback { tanChallenge -> enterTan(tanChallenge) })
val response = client.getAccountData(GetAccountDataParameter(bankCode, loginName, password))
val response = client.getAccountData(GetAccountDataParameter(bankCode, loginName, password))
if (response.error != null) {
println("An error occurred: ${response.error}${response.errorMessage?.let { " $it" }}")
}
if (response.error != null) {
println("An error occurred: ${response.error}${response.errorMessage?.let { " $it" }}")
}
response.customerAccount?.let { account ->
println("Retrieved response from ${account.bankName} for ${account.customerName}")
response.customerAccount?.let { account ->
println("Retrieved response from ${account.bankName} for ${account.customerName}")
displayRetrievedAccountData(account)
}
displayRetrievedAccountData(account)
}
}

View File

@ -0,0 +1,14 @@
package net.dankito.banking.fints
import kotlinx.coroutines.runBlocking
import net.dankito.banking.client.model.parameter.GetAccountDataParameter
import net.dankito.banking.client.model.response.GetAccountDataResponse
fun FinTsClient.getAccountData(bankCode: String, loginName: String, password: String): GetAccountDataResponse {
return runBlocking { getAccountDataAsync(bankCode, loginName, password) }
}
fun FinTsClient.getAccountData(param: GetAccountDataParameter): GetAccountDataResponse {
return runBlocking { getAccountDataAsync(param) }
}