Renamed getAccountData() to getAccountDataAsync() and added extensions methods for blocking calls to it
This commit is contained in:
parent
ee68dd09b2
commit
3368c70202
|
@ -36,7 +36,7 @@ open class Presenter {
|
||||||
|
|
||||||
open fun retrieveAccountData(bankCode: String, loginName: String, password: String, retrievedResult: (GetAccountDataResponse) -> Unit) {
|
open fun retrieveAccountData(bankCode: String, loginName: String, password: String, retrievedResult: (GetAccountDataResponse) -> Unit) {
|
||||||
GlobalScope.launch(Dispatchers.IO) {
|
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}")
|
log.info("Retrieved response from ${response.customerAccount?.bankName} for ${response.customerAccount?.customerName}")
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
|
|
|
@ -34,7 +34,7 @@ open class Presenter {
|
||||||
|
|
||||||
open fun retrieveAccountData(bankCode: String, loginName: String, password: String, retrievedResult: (GetAccountDataResponse) -> Unit) {
|
open fun retrieveAccountData(bankCode: String, loginName: String, password: String, retrievedResult: (GetAccountDataResponse) -> Unit) {
|
||||||
GlobalScope.launch(Dispatchers.Unconfined) {
|
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}")
|
log.info("Retrieved response from ${response.customerAccount?.bankName} for ${response.customerAccount?.customerName}")
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Presenter : ObservableObject {
|
||||||
|
|
||||||
|
|
||||||
func getAccountData(_ bankCode: String, _ customerId: String, _ pin: String, _ finTs3ServerAddress: String, _ callback: @escaping (GetAccountDataResponse) -> Void) {
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,11 +37,11 @@ open class FinTsClient @JvmOverloads constructor(
|
||||||
protected open val mapper = FinTsModelMapper()
|
protected open val mapper = FinTsModelMapper()
|
||||||
|
|
||||||
|
|
||||||
open suspend fun getAccountData(bankCode: String, loginName: String, password: String): GetAccountDataResponse {
|
open suspend fun getAccountDataAsync(bankCode: String, loginName: String, password: String): GetAccountDataResponse {
|
||||||
return getAccountData(GetAccountDataParameter(bankCode, loginName, password))
|
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)
|
val finTsServerAddress = finTsServerAddressFinder.findFinTsServerAddress(param.bankCode)
|
||||||
if (finTsServerAddress.isNullOrBlank()) {
|
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())
|
return GetAccountDataResponse(ErrorCode.BankDoesNotSupportFinTs3, "Either bank does not FinTS 3.0 or we don't know its FinTS server address", null, listOf())
|
||||||
|
|
|
@ -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
|
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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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) }
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import net.dankito.banking.client.model.CustomerAccount
|
||||||
import net.dankito.banking.client.model.parameter.GetAccountDataParameter
|
import net.dankito.banking.client.model.parameter.GetAccountDataParameter
|
||||||
import net.dankito.banking.fints.FinTsClient
|
import net.dankito.banking.fints.FinTsClient
|
||||||
import net.dankito.banking.fints.callback.SimpleFinTsClientCallback
|
import net.dankito.banking.fints.callback.SimpleFinTsClientCallback
|
||||||
|
import net.dankito.banking.fints.getAccountData
|
||||||
import net.dankito.banking.fints.model.TanChallenge
|
import net.dankito.banking.fints.model.TanChallenge
|
||||||
import net.dankito.utils.multiplatform.extensions.*
|
import net.dankito.utils.multiplatform.extensions.*
|
||||||
import platform.posix.exit
|
import platform.posix.exit
|
||||||
|
@ -22,20 +23,18 @@ fun main(args: Array<String>) {
|
||||||
class Application {
|
class Application {
|
||||||
|
|
||||||
fun retrieveAccountData(bankCode: String, loginName: String, password: String) {
|
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) {
|
if (response.error != null) {
|
||||||
println("An error occurred: ${response.error}${response.errorMessage?.let { " $it" }}")
|
println("An error occurred: ${response.error}${response.errorMessage?.let { " $it" }}")
|
||||||
}
|
}
|
||||||
|
|
||||||
response.customerAccount?.let { account ->
|
response.customerAccount?.let { account ->
|
||||||
println("Retrieved response from ${account.bankName} for ${account.customerName}")
|
println("Retrieved response from ${account.bankName} for ${account.customerName}")
|
||||||
|
|
||||||
displayRetrievedAccountData(account)
|
displayRetrievedAccountData(account)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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) }
|
||||||
|
}
|
Loading…
Reference in New Issue