public Observable<NetworkType> getNetworkType() { return this.client .getAbs(this.url.toString()) .as(BodyCodec.jsonObject()) .rxSend() .toObservable() .map(Http::mapJsonObjectOrError) .map(json -> json.getString("name")) .map(name -> { if (name.equalsIgnoreCase("mijinTest")) return NetworkType.MIJIN_TEST; else { throw new IllegalArgumentException("network " + name + " is not supported yet by the sdk"); } }); } }
public Observable<BigInteger> getBlockchainScore() { return this.client .getAbs(this.url + "/chain/score") .as(BodyCodec.jsonObject()) .rxSend() .toObservable() .map(Http::mapJsonObjectOrError) .map(json -> objectMapper.readValue(json.toString(), BlockchainScoreDTO.class)) .map(blockchainScoreDTO -> blockchainScoreDTO.extractIntArray()); }
@Override public Observable<Transaction> getTransaction(String transactionHash) { return this.client .getAbs(this.url + transactionHash) .as(BodyCodec.jsonObject()) .rxSend() .toObservable() .map(Http::mapJsonObjectOrError) .map(json -> new JsonObject(json.toString())) .map(new TransactionMapping()); }
private Observable<List<Transaction>> getBlockTransactions(BigInteger height, Optional<QueryParams> queryParams) { return this.client .getAbs(this.url + "/block/" + height + "/transactions" + (queryParams.isPresent() ? queryParams.get().toUrl() : "")) .as(BodyCodec.jsonArray()) .rxSend() .toObservable() .map(Http::mapJsonArrayOrError) .map(json -> new JsonArray(json.toString()).stream().map(s -> (JsonObject) s).collect(Collectors.toList())) .flatMapIterable(item -> item) .map(new TransactionMapping()) .toList() .toObservable(); }
@Override public Observable<BigInteger> getBlockchainHeight() { return this.client .getAbs(this.url + "/chain/height") .as(BodyCodec.jsonObject()) .rxSend() .toObservable() .map(Http::mapJsonObjectOrError) .map(json -> objectMapper.readValue(json.toString(), HeightDTO.class)) .map(blockchainHeight -> blockchainHeight.getHeight().extractIntArray()); }
private Observable<List<Transaction>> findTransactions(PublicAccount publicAccount, Optional<QueryParams> queryParams, String path) { return this.client .getAbs(this.url + publicAccount.getPublicKey() + path + (queryParams.isPresent() ? queryParams.get().toUrl() : "")) .as(BodyCodec.jsonArray()) .rxSend() .toObservable() .map(Http::mapJsonArrayOrError) .map(json -> new JsonArray(json.toString()).stream().map(s -> (JsonObject) s).collect(Collectors.toList())) .flatMapIterable(item -> item) .map(new TransactionMapping()) .toList() .toObservable(); }
@Override public Observable<MultisigAccountInfo> getMultisigAccountInfo(Address address) { Observable<NetworkType> networkTypeResolve = getNetworkTypeObservable(); return networkTypeResolve .flatMap(networkType -> this.client .getAbs(this.url + address.plain() + "/multisig") .as(BodyCodec.jsonObject()) .rxSend() .toObservable() .map(Http::mapJsonObjectOrError) .map(json -> objectMapper.readValue(json.toString(), MultisigAccountInfoDTO.class)) .map(MultisigAccountInfoDTO::getMultisig) .map(transfromMultisigAccountInfoDTO(networkType))); }
@Override public Observable<BlockchainStorageInfo> getBlockchainStorage() { return this.client .getAbs(this.url + "/diagnostic/storage") .as(BodyCodec.jsonObject()) .rxSend() .toObservable() .map(Http::mapJsonObjectOrError) .map(json -> objectMapper.readValue(json.toString(), BlockchainStorageInfoDTO.class)) .map(blockchainStorageInfoDTO -> new BlockchainStorageInfo(blockchainStorageInfoDTO.getNumAccounts(), blockchainStorageInfoDTO.getNumBlocks(), blockchainStorageInfoDTO.getNumBlocks())); } }
private Single<Buffer> sendGetRequest(String mbAlbumId) { return webClient .getAbs("http://coverartarchive.org") .uri("/release/" + mbAlbumId + "/front") .as(BodyCodec.buffer()) .rxSend() .map(HttpResponse::body); }
@Override public Observable<TransactionStatus> getTransactionStatus(String transactionHash) { return this.client .getAbs(this.url + transactionHash + "/status") .as(BodyCodec.jsonObject()) .rxSend() .toObservable() .map(Http::mapJsonObjectOrError) .map(json -> objectMapper.readValue(json.toString(), TransactionStatusDTO.class)) .map(transactionStatusDTO -> new TransactionStatus(transactionStatusDTO.getGroup(), transactionStatusDTO.getStatus(), transactionStatusDTO.getHash(), new Deadline(transactionStatusDTO.getDeadline().extractIntArray()), transactionStatusDTO.getHeight().extractIntArray())); }
@Override public Observable<AccountInfo> getAccountInfo(Address address) { return this.client .getAbs(this.url + address.plain()) .as(BodyCodec.jsonObject()) .rxSend() .toObservable() .map(Http::mapJsonObjectOrError) .map(json -> objectMapper.readValue(json.toString(), AccountInfoDTO.class)) .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()))); }
@Override public Maybe<JWKSet> getKeys(String jwksUri) { try{ return client.getAbs(UriBuilder.fromHttpUrl(jwksUri).build().toString()) .rxSend() .map(HttpResponse::bodyAsString) .map(new JWKSetDeserializer()::convert) .flatMapMaybe(jwkSet -> { if(jwkSet!=null && jwkSet.isPresent()) { return Maybe.just(jwkSet.get()); } return Maybe.empty(); }) .onErrorResumeNext(Maybe.error(new InvalidClientMetadataException("Unable to parse jwks from : " + jwksUri))); } catch(IllegalArgumentException | URISyntaxException ex) { return Maybe.error(new InvalidClientMetadataException(jwksUri+" is not valid.")); } catch(InvalidClientMetadataException ex) { return Maybe.error(ex); } }
@Override public Maybe<JWKSet> getKeys(String jwksUri) { try{ return client.getAbs(UriBuilder.fromHttpUrl(jwksUri).build().toString()) .rxSend() .map(HttpResponse::bodyAsString) .map(new JWKSetDeserializer()::convert) .flatMapMaybe(jwkSet -> { if(jwkSet!=null && jwkSet.isPresent()) { return Maybe.just(jwkSet.get()); } return Maybe.empty(); }) .onErrorResumeNext(Maybe.error(new InvalidClientMetadataException("Unable to parse jwks from : " + jwksUri))); } catch(IllegalArgumentException | URISyntaxException ex) { return Maybe.error(new InvalidClientMetadataException(jwksUri+" is not valid.")); } catch(InvalidClientMetadataException ex) { return Maybe.error(ex); } }
private Maybe<User> profile(String accessToken) { return client.getAbs(configuration.getUserProfileUri()) .putHeader(HttpHeaders.AUTHORIZATION, "token " + accessToken) .rxSend() .toMaybe() .map(httpClientResponse -> { if (httpClientResponse.statusCode() != 200) { throw new BadCredentialsException(httpClientResponse.statusMessage()); } return createUser(httpClientResponse.bodyAsJsonObject()); }); }
private Maybe<User> profile(String accessToken) { return client.getAbs(configuration.getUserProfileUri()) .putHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken) .rxSend() .toMaybe() .map(httpClientResponse -> { if (httpClientResponse.statusCode() != 200) { throw new BadCredentialsException(httpClientResponse.statusMessage()); } return createUser(httpClientResponse.bodyAsJsonObject()); }); }
private Maybe<User> profile(String accessToken) { return client.getAbs(configuration.getUserProfileUri()) .putHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken) .rxSend() .toMaybe() .map(httpClientResponse -> { if (httpClientResponse.statusCode() != 200) { throw new BadCredentialsException(httpClientResponse.statusMessage()); } return createUser(httpClientResponse.bodyAsJsonObject()); }); }
private Maybe<User> profile(String accessToken) { return client.getAbs(configuration.getUserProfileUri()) .putHeader(HttpHeaders.AUTHORIZATION, "token " + accessToken) .rxSend() .toMaybe() .map(httpClientResponse -> { if (httpClientResponse.statusCode() != 200) { throw new BadCredentialsException(httpClientResponse.statusMessage()); } return createUser(httpClientResponse.bodyAsJsonObject()); }); }
private Observable<List<MosaicInfo>> getMosaicsFromNamespace(NamespaceId namespaceId, Optional<QueryParams> queryParams) { Observable<NetworkType> networkTypeResolve = getNetworkTypeObservable(); return networkTypeResolve .flatMap(networkType -> this.client .getAbs(this.url + "/namespace/" + UInt64.bigIntegerToHex(namespaceId.getId()) + "/mosaics" + (queryParams.isPresent() ? queryParams.get().toUrl() : "")) .as(BodyCodec.jsonArray()) .rxSend() .toObservable() .map(Http::mapJsonArrayOrError) .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()); }
@Override public Observable<NamespaceInfo> getNamespace(NamespaceId namespaceId) { Observable<NetworkType> networkTypeResolve = getNetworkTypeObservable(); return networkTypeResolve .flatMap(networkType -> this.client .getAbs(this.url + "/namespace/" + UInt64.bigIntegerToHex(namespaceId.getId())) .as(BodyCodec.jsonObject()) .rxSend() .toObservable() .map(Http::mapJsonObjectOrError) .map(json -> objectMapper.readValue(json.toString(), NamespaceInfoDTO.class)) .map(namespaceInfoDTO -> new NamespaceInfo(namespaceInfoDTO.getMeta().isActive(), namespaceInfoDTO.getMeta().getIndex(), namespaceInfoDTO.getMeta().getId(), NamespaceType.rawValueOf(namespaceInfoDTO.getNamespace().getType()), namespaceInfoDTO.getNamespace().getDepth(), extractLevels(namespaceInfoDTO), new NamespaceId(namespaceInfoDTO.getNamespace().getParentId().extractIntArray()), new PublicAccount(namespaceInfoDTO.getNamespace().getOwner(), networkType), namespaceInfoDTO.getNamespace().getStartHeight().extractIntArray(), namespaceInfoDTO.getNamespace().getEndHeight().extractIntArray() ))); }
@Override public Observable<MosaicInfo> getMosaic(MosaicId mosaicId) { Observable<NetworkType> networkTypeResolve = getNetworkTypeObservable(); return networkTypeResolve .flatMap(networkType -> this.client .getAbs(this.url + "/mosaic/" + UInt64.bigIntegerToHex(mosaicId.getId())) .as(BodyCodec.jsonObject()) .rxSend() .toObservable() .map(Http::mapJsonObjectOrError) .map(json -> objectMapper.readValue(json.toString(), MosaicInfoDTO.class)) .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()) ))); }