Search in sources :

Example 1 with HttpResponse

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());
}
Also used : Mosaic(io.nem.sdk.model.mosaic.Mosaic) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) MalformedURLException(java.net.MalformedURLException) AggregateTransaction(io.nem.sdk.model.transaction.AggregateTransaction) HashMap(java.util.HashMap) NetworkType(io.nem.sdk.model.blockchain.NetworkType) Collectors(java.util.stream.Collectors) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) BodyCodec(io.vertx.reactivex.ext.web.codec.BodyCodec) Function(io.reactivex.functions.Function) io.nem.sdk.model.account(io.nem.sdk.model.account) Map(java.util.Map) Optional(java.util.Optional) Transaction(io.nem.sdk.model.transaction.Transaction) Observable(io.reactivex.Observable) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) MosaicId(io.nem.sdk.model.mosaic.MosaicId) NetworkType(io.nem.sdk.model.blockchain.NetworkType) MosaicId(io.nem.sdk.model.mosaic.MosaicId) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Mosaic(io.nem.sdk.model.mosaic.Mosaic)

Example 2 with HttpResponse

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();
}
Also used : JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) BodyCodec(io.vertx.reactivex.ext.web.codec.BodyCodec) MalformedURLException(java.net.MalformedURLException) Observable(io.reactivex.Observable) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Collectors(java.util.stream.Collectors) io.nem.sdk.model.transaction(io.nem.sdk.model.transaction) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference)

Example 3 with HttpResponse

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();
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) BodyCodec(io.vertx.reactivex.ext.web.codec.BodyCodec) MalformedURLException(java.net.MalformedURLException) Observable(io.reactivex.Observable) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Collectors(java.util.stream.Collectors) io.nem.sdk.model.transaction(io.nem.sdk.model.transaction) JsonObject(io.vertx.core.json.JsonObject)

Example 4 with HttpResponse

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));
}
Also used : HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) WebClient(io.vertx.reactivex.ext.web.client.WebClient)

Example 5 with HttpResponse

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());
}
Also used : HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) MalformedURLException(java.net.MalformedURLException) MosaicName(io.nem.sdk.model.mosaic.MosaicName) MosaicInfo(io.nem.sdk.model.mosaic.MosaicInfo) NetworkType(io.nem.sdk.model.blockchain.NetworkType) Collectors(java.util.stream.Collectors) UInt64(io.nem.sdk.model.transaction.UInt64) List(java.util.List) PublicAccount(io.nem.sdk.model.account.PublicAccount) BodyCodec(io.vertx.reactivex.ext.web.codec.BodyCodec) MosaicProperties(io.nem.sdk.model.mosaic.MosaicProperties) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) Optional(java.util.Optional) Observable(io.reactivex.Observable) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) MosaicId(io.nem.sdk.model.mosaic.MosaicId) MosaicInfo(io.nem.sdk.model.mosaic.MosaicInfo) NetworkType(io.nem.sdk.model.blockchain.NetworkType) MosaicId(io.nem.sdk.model.mosaic.MosaicId) PublicAccount(io.nem.sdk.model.account.PublicAccount) JsonObject(io.vertx.core.json.JsonObject) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) List(java.util.List) NamespaceId(io.nem.sdk.model.namespace.NamespaceId)

Aggregations

HttpResponse (io.vertx.reactivex.ext.web.client.HttpResponse)11 TypeReference (com.fasterxml.jackson.core.type.TypeReference)7 Observable (io.reactivex.Observable)7 JsonObject (io.vertx.core.json.JsonObject)7 BodyCodec (io.vertx.reactivex.ext.web.codec.BodyCodec)7 MalformedURLException (java.net.MalformedURLException)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 NetworkType (io.nem.sdk.model.blockchain.NetworkType)5 Optional (java.util.Optional)5 PublicAccount (io.nem.sdk.model.account.PublicAccount)4 NamespaceId (io.nem.sdk.model.namespace.NamespaceId)4 UInt64 (io.nem.sdk.model.transaction.UInt64)4 MosaicId (io.nem.sdk.model.mosaic.MosaicId)3 JsonArray (io.vertx.core.json.JsonArray)3 Address (io.nem.sdk.model.account.Address)2 MosaicInfo (io.nem.sdk.model.mosaic.MosaicInfo)2 MosaicName (io.nem.sdk.model.mosaic.MosaicName)2 MosaicProperties (io.nem.sdk.model.mosaic.MosaicProperties)2 NamespaceInfo (io.nem.sdk.model.namespace.NamespaceInfo)2