use of io.vertx.reactivex.ext.web.client.HttpResponse in project nem2-sdk-java by nemtech.
the class AccountHttp method getAccountsInfo.
@Override
public Observable<List<AccountInfo>> getAccountsInfo(List<Address> addresses) {
JsonObject requestBody = new JsonObject();
requestBody.put("addresses", addresses.stream().map(address -> address.plain()).collect(Collectors.toList()));
Observable<NetworkType> networkTypeResolve = getNetworkTypeObservable();
return networkTypeResolve.flatMap(networkType -> this.client.postAbs(this.url.toString()).as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<AccountInfoDTO>>readValue(json.toString(), new TypeReference<List<AccountInfoDTO>>() {
})).flatMapIterable(item -> item).map(AccountInfoDTO::getAccount).map(accountDTO -> new AccountInfo(Address.createFromRawAddress(accountDTO.getAddressEncoded()), accountDTO.getAddressHeight().extractIntArray(), accountDTO.getPublicKey(), accountDTO.getPublicKeyHeight().extractIntArray(), accountDTO.getImportance().extractIntArray(), accountDTO.getImportanceHeight().extractIntArray(), accountDTO.getMosaics().stream().map(mosaicDTO -> new Mosaic(new MosaicId(mosaicDTO.getId().extractIntArray()), mosaicDTO.getAmount().extractIntArray())).collect(Collectors.toList()))).toList().toObservable());
}
use of io.vertx.reactivex.ext.web.client.HttpResponse in project nem2-sdk-java by nemtech.
the class TransactionHttp method getTransactionStatuses.
@Override
public Observable<List<TransactionStatus>> getTransactionStatuses(List<String> transactionHashes) {
JsonObject requestBody = new JsonObject();
requestBody.put("hashes", transactionHashes);
return this.client.postAbs(this.url + "/statuses").as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<TransactionStatusDTO>>readValue(json.toString(), new TypeReference<List<TransactionStatusDTO>>() {
})).flatMapIterable(item -> item).map(transactionStatusDTO -> new TransactionStatus(transactionStatusDTO.getGroup(), transactionStatusDTO.getStatus(), transactionStatusDTO.getHash(), new Deadline(transactionStatusDTO.getDeadline().extractIntArray()), transactionStatusDTO.getHeight().extractIntArray())).toList().toObservable();
}
use of io.vertx.reactivex.ext.web.client.HttpResponse in project nem2-sdk-java by nemtech.
the class TransactionHttp method getTransactions.
@Override
public Observable<List<Transaction>> getTransactions(List<String> transactionHashes) {
JsonObject requestBody = new JsonObject();
requestBody.put("transactionIds", transactionHashes);
return this.client.postAbs(this.url.toString()).as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> new JsonArray(json.toString()).stream().map(s -> (JsonObject) s).collect(Collectors.toList())).flatMapIterable(item -> item).map(new TransactionMapping()).toList().toObservable();
}
use of io.vertx.reactivex.ext.web.client.HttpResponse in project vertx-examples by vert-x3.
the class Client method start.
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
Single<HttpResponse<Data>> request = client.get(8080, "localhost", "/").as(BodyCodec.json(Data.class)).rxSend();
// Fire the request
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
// Again
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
// And again
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
}
use of io.vertx.reactivex.ext.web.client.HttpResponse in project nem2-sdk-java by nemtech.
the class MosaicHttp method getMosaics.
@Override
public Observable<List<MosaicInfo>> getMosaics(List<MosaicId> mosaicIds) {
JsonObject requestBody = new JsonObject();
requestBody.put("mosaicIds", mosaicIds.stream().map(id -> UInt64.bigIntegerToHex(id.getId())).collect(Collectors.toList()));
Observable<NetworkType> networkTypeResolve = getNetworkTypeObservable();
return networkTypeResolve.flatMap(networkType -> this.client.postAbs(this.url + "/mosaic").as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<MosaicInfoDTO>>readValue(json.toString(), new TypeReference<List<MosaicInfoDTO>>() {
})).flatMapIterable(item -> item).map(mosaicInfoDTO -> new MosaicInfo(mosaicInfoDTO.getMeta().isActive(), mosaicInfoDTO.getMeta().getIndex(), mosaicInfoDTO.getMeta().getId(), new NamespaceId(mosaicInfoDTO.getMosaic().getNamespaceId().extractIntArray()), new MosaicId(mosaicInfoDTO.getMosaic().getMosaicId().extractIntArray()), mosaicInfoDTO.getMosaic().getSupply().extractIntArray(), mosaicInfoDTO.getMosaic().getHeight().extractIntArray(), new PublicAccount(mosaicInfoDTO.getMosaic().getOwner(), networkType), extractMosaicProperties(mosaicInfoDTO.getMosaic().getProperties()))).toList().toObservable());
}
Aggregations