This library provides RxJava extensions for TokenD SDK.
For Gradle add following lines to your project's build.gradle
:
allprojects {
repositories {
...
maven { url "https://maven.tokend.io" }
}
}
dependencies {
...
compile "org.tokend:rx-sdk:2.5.0"
}
ApiRequest
can be converted to a lazy Single
or Completable
.
Source request will be executed on subscription
and can be canceled by disposing of it.
Kotlin:
api
.v3
.info
.getInfo()
.toSingle()
.subscribe(
{ systemInfo ->
System.out.println(systemInfo.passphrase)
},
{ error ->
error.printStackTrace()
}
)
Java:
ApiRequest<SystemInfo> request = api.v3.info.getInfo();
RxApiRequest.toSingle(request)
.subscribe(new BiConsumer<SystemInfo, Throwable>() {
@Override
public void accept(SystemInfo systemInfo, Throwable throwable) throws Exception {
if (throwable != null) {
throwable.printStackTrace();
} else {
System.out.println(systemInfo.getPassphrase());
}
}
});
You can use corresponding Kotlin extensions for Account
methods
or wrap methods calls with RxAccount
in Java.
Kotlin:
val seed = "SCJMKEDU62OECGGNF2D4C5IBOPV66ZYLVMLPLWCJMH2NXQ4FM27H35UN"
.toCharArray()
Account
.fromSecretSeedSingle(seed)
.subscribe(
{ account ->
System.out.println(account.accountId)
},
{ error ->
error.printStackTrace()
}
)
Java:
char[] seed = "SCJMKEDU62OECGGNF2D4C5IBOPV66ZYLVMLPLWCJMH2NXQ4FM27H35UN"
.toCharArray();
RxAccount
.fromSecretSeedSingle(seed)
.subscribe(new BiConsumer<Account, Throwable>() {
@Override
public void accept(Account account, Throwable throwable) throws Exception {
if (throwable != null) {
throwable.printStackTrace();
} else {
System.out.println(account.getAccountId());
}
}
});
You can get password-based OTP generation for TFA verification result
as a Single
:
Kotlin:
PasswordTfaOtpGenerator()
.generateSingle(tfaException, email, password)
.subscribe { otp ->
System.out.println(otp)
}
Java:
RxPasswordTfaOtpGenerator
.generateSingle(
new PasswordTfaOtpGenerator(),
tfaException,
email,
password
)
.subscribe(new BiConsumer<String, Throwable>() {
@Override
public void accept(String otp, Throwable throwable) throws Exception {
if (throwable != null) {
throwable.printStackTrace();
} else {
System.out.println(otp);
}
}
});
There are Kotlin extensions for WalletEncryption
and WalletKeyDerivation
and Java wrappers RxWalletEncryption
and RxWalletKeyDerivation
Kotlin:
val streamer = SimpleRxPagedResourceStreamer({ nextCursor ->
api.v3.transactions.get(
TransactionsPageParams(
pagingParams = PagingParamsV2(page = nextCursor)
)
)
})
streamer
.observable
.subscribe { /* ... */ }
Java:
RxPagedResourceStreamer streamer = new RxPagedResourceStreamer<TransactionResource>() {
@NotNull
@Override
protected ApiRequest<DataPage<TransactionResource>> getPageRequest(@Nullable String s) {
return api.getV3().getTransactions().get(
new TransactionsPageParams.Builder()
.withPagingParams(new PagingParamsV2.Builder()
.withPage(s)
.build())
.build()
);
}
@Override
protected boolean isErrorFatal(@NotNull Throwable throwable) {
return false;
}
};
streamer
.getObservable()
.subscribe(/* ... */);