diff --git a/.DS_Store b/.DS_Store index fe166a6..97e65dc 100644 Binary files a/.DS_Store and b/.DS_Store differ 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.") + } + } }