Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add async account functions #17

Merged
merged 2 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/kotlin/Account.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ public data class WithdrawTransaction(
)

@Serializable
public data class AccountList(public val accounts: List<Account>) : List<Account> by accounts
public data class AccountListResponse(public val accounts: List<Account>) : List<Account> by accounts

public suspend fun WooviSDK.getAccount(id: String): Account {
return client.get("/api/v1/account/{$id}").body<Account>()
}

public suspend fun WooviSDK.allAccounts(): AccountList {
return client.get("/api/v1/account").body<AccountList>()
public suspend fun WooviSDK.allAccounts(): AccountListResponse {
return client.get("/api/v1/account").body<AccountListResponse>()
}

public suspend fun WooviSDK.withdraw(id: String, value: Int): WithdrawResponse {
Expand Down
12 changes: 12 additions & 0 deletions src/main/kotlin/WooviSdk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ public class WooviSDK(
createPixQrCode(builder) {}
}

public fun getAccountAsync(id: String): Future<Account> = future {
getAccount(id)
}

public fun allAccountsAsync(): Future<AccountListResponse> = future {
allAccounts()
}

public fun withdrawAsync(id: String, value: Int): Future<WithdrawResponse> = future {
withdraw(id, value)
}

// Java util functions

public fun configureLenientJson(value: Boolean = true): WooviSDK = apply {
Expand Down
Loading