From e565ecf673eb3dc81b58b9d69a701a343149bb31 Mon Sep 17 00:00:00 2001 From: Mohamed Yousif Date: Sun, 17 Dec 2023 00:07:55 +0400 Subject: [PATCH] Small changes to noebs lib --- .DS_Store | Bin 6148 -> 6148 bytes gradle.properties | 2 +- .../main/java/com/tuti/api/TutiApiClient.kt | 36 +++++++++--------- .../main/java/com/tuti/model/Operations.kt | 2 + lib/src/main/java/com/tuti/model/data.kt | 19 +++++++++ .../java/com/tuti/api/TutiApiClientTest.kt | 34 +++++++++++++++++ 6 files changed, 74 insertions(+), 19 deletions(-) diff --git a/.DS_Store b/.DS_Store index fe166a6f025dec5122c7aa2c0449a2e69ddd86cf..97e65dc26fce18544a207473c1b1738511a476da 100644 GIT binary patch delta 415 zcmZoMXffEJ$`Z%p&&I&Oz`~%%kj{|FP?DSP;*yk;p9B=+__|O~_(%UyM^yO~yz&JZ zhQZ1CxdlKy3=HxgCO5MvGO?vjUdAHFo^$+_@XOYtlRvTuPrk>(gT!}Ymgx$eY{n|b z&g|}%m)du9awDto;sUQtU#A$GNdr1G9>1tBiY4Z5r`^_>=S1_k%*fU zz&=6JpPP^H3w9OAzF}ryI51h6Z7;jU8;C!iv&q8Q-0T*1=TC+LUBJwc19V>!vh5G~ hPId!54hl!OEW&1}?Bqsv38tq86BBbbvvd6A2LO>Hc)0)o delta 415 zcmZoMXffEJ$`Z$U@IM0s0}F#5LpnnyLrHGFi%U{YeiBfOqxt^^*BghAIHJm@;FT}P zFbq!4&n*DzVPFttnB2^w$i$jEc^Qiw`?E*CT(dSGnf#GOc=A0K9wfdKGus@M$!4r_ z?7w>4N`O{QZe$gnoX5(8#8;?i4*;3T3Up~ELkdGGLt;)kl3fg%{;0CZK4~h{YlQj) zNq=rW!Y|lWAp3@yfnmaAWwyQSa=#${c+MsZXLGY#*u_~r1iFBkAqVKbBxKvSAHKYG e?>2Ba!etRQLuDs7vP&=(7)(se+04%ImmdHl%z)nj diff --git a/gradle.properties b/gradle.properties index d210508..d3d5135 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=23.12.3 +version=23.12.10 diff --git a/lib/src/main/java/com/tuti/api/TutiApiClient.kt b/lib/src/main/java/com/tuti/api/TutiApiClient.kt index e5ed25c..0587de6 100644 --- a/lib/src/main/java/com/tuti/api/TutiApiClient.kt +++ b/lib/src/main/java/com/tuti/api/TutiApiClient.kt @@ -22,9 +22,7 @@ import okhttp3.logging.HttpLoggingInterceptor import java.io.IOException import java.util.concurrent.TimeUnit -class TutiApiClient { - var serverURL: String? = null - private set +class TutiApiClient(val serverURL: String = "https://beta.app.st.sd/consumer/") { var isSingleThreaded = false var authToken: String = "" var ipinUsername: String = "" @@ -35,21 +33,6 @@ class TutiApiClient { val entertainmentServer = "https://plus.2t.sd/" val dapiServer = "https://dapi.nil.sd/" - @Deprecated("") - constructor(isDevelopment: Boolean) { - serverURL = getServerURL(isDevelopment) - } - - - constructor() { - serverURL = getServerURL(false) - } - - private fun getServerURL(development: Boolean): String { - val developmentHost = "https://beta.app.2t.sd/consumer/" - val productionHost = "https://beta.app.2t.sd/consumer/" - return if (development) developmentHost else productionHost - } private fun fillRequestFields(card: Card, ipin: String, amount: Float): EBSRequest { val request = EBSRequest() @@ -1186,6 +1169,23 @@ class TutiApiClient { ) } + + fun retrieveLedgerTransactions( + accountId: String, + onResponse: (List) -> Unit, + onError: (TutiResponse?, Exception?) -> Unit + ) { + sendRequest( + RequestMethods.GET, + serverURL + Operations.LEDGER_TRANSACTIONS, + "", + onResponse, + onError, + null, + runOnOwnThread = true, "account_id", accountId + ) + } + inline fun sendRequest( method: RequestMethods, URL: String, diff --git a/lib/src/main/java/com/tuti/model/Operations.kt b/lib/src/main/java/com/tuti/model/Operations.kt index d9f5a29..e5b17d4 100644 --- a/lib/src/main/java/com/tuti/model/Operations.kt +++ b/lib/src/main/java/com/tuti/model/Operations.kt @@ -62,4 +62,6 @@ object Operations { const val DAPI_GET_TRANSACTIONS = "transactions" const val NOEBS_WALLET_BALANCE = "noebs-balance" const val NOEBS_CARD_TRANSFER = "transfer" + // transactions + const val LEDGER_TRANSACTIONS = "nil/transactions" } \ No newline at end of file diff --git a/lib/src/main/java/com/tuti/model/data.kt b/lib/src/main/java/com/tuti/model/data.kt index eddae45..48a1c49 100644 --- a/lib/src/main/java/com/tuti/model/data.kt +++ b/lib/src/main/java/com/tuti/model/data.kt @@ -96,3 +96,22 @@ data class DapiTransaction( data class DapiResponse( val data: List ) + +@Serializable +data class LedgerResponse( + val data: List +) + +@Serializable +data class Ledger( + @SerialName("account_id") + val AccountID: String, + @SerialName("transaction_id") + val TransactionID: String, + @SerialName("amount") + val Amount: Float, + @SerialName("type") + val Type: String, + @SerialName("time") + val Time: Long, +) diff --git a/lib/src/test/java/com/tuti/api/TutiApiClientTest.kt b/lib/src/test/java/com/tuti/api/TutiApiClientTest.kt index f48ae2f..e760ff7 100644 --- a/lib/src/test/java/com/tuti/api/TutiApiClientTest.kt +++ b/lib/src/test/java/com/tuti/api/TutiApiClientTest.kt @@ -5,6 +5,8 @@ import com.tuti.api.authentication.SignInRequest import com.tuti.api.data.TutiResponse import com.tuti.api.ebs.EBSRequest import com.tuti.api.ebs.NoebsTransfer +import com.tuti.model.Ledger +import com.tuti.model.LedgerResponse import com.tuti.model.NotificationFilters import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNull @@ -172,6 +174,38 @@ internal class TutiApiClientTest { fail("The call to inquireNoebsWallet did not complete within the expected time.") } } + + @Test + fun retrieveLedgerTransactions() { + val tutiApiClient = TutiApiClient(serverURL = "https://blue-violet-2528-icy-frog-2586.fly.dev/") + tutiApiClient.authToken = "yourTestAuthToken" + val expectedResponse = 121342212 + + val latch = CountDownLatch(1) // Initialize CountDownLatch with count 1 + + var responseReceived: List?= null + var errorOccurred: Exception? = null + + // Call the method + tutiApiClient.retrieveLedgerTransactions("249_ACCT_1", { response -> + responseReceived = response + latch.countDown() // Decrease the count of the latch, releasing the wait in test + }, { _, error -> + errorOccurred = error + latch.countDown() // Ensure to count down in case of error too + }) + + // Wait for the operation to complete or timeout + val callCompleted = latch.await(10, TimeUnit.SECONDS) + + // Assertions + if (callCompleted) { + assertEquals(expectedResponse, responseReceived) + assertNull(errorOccurred) + } else { + fail("The call to inquireNoebsWallet did not complete within the expected time.") + } + } }