@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(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<List<MosaicName>> getMosaicNames(List<MosaicId> mosaicIds) { JsonObject requestBody = new JsonObject(); requestBody.put("mosaicIds", mosaicIds.stream().map(id -> UInt64.bigIntegerToHex(id.getId())).collect(Collectors.toList())); return this.client .postAbs(this.url + "/mosaic/names") .as(BodyCodec.jsonArray()) .rxSendJson(requestBody) .toObservable() .map(Http::mapJsonArrayOrError) .map(json -> objectMapper.<List<MosaicNameDTO>>readValue(json.toString(), new TypeReference<List<MosaicNameDTO>>() { })) .flatMapIterable(item -> item) .map(mosaicNameDTO -> new MosaicName(new MosaicId(mosaicNameDTO.getMosaicId().extractIntArray()), mosaicNameDTO.getName(), new NamespaceId(mosaicNameDTO.getParentId().extractIntArray()))) .toList() .toObservable(); }
private Maybe<String> authenticate(Authentication authentication) { // prepare body request parameters List<NameValuePair> urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair(CLIENT_ID, configuration.getClientId())); urlParameters.add(new BasicNameValuePair(CLIENT_SECRET, configuration.getClientSecret())); urlParameters.add(new BasicNameValuePair(REDIRECT_URI, (String) authentication.getAdditionalInformation().get(REDIRECT_URI))); urlParameters.add(new BasicNameValuePair(CODE, (String) authentication.getCredentials())); urlParameters.add(new BasicNameValuePair(GRANT_TYPE, "authorization_code")); String bodyRequest = URLEncodedUtils.format(urlParameters); return client.postAbs(configuration.getAccessTokenUri()) .putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(bodyRequest.length())) .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED) .rxSendBuffer(Buffer.buffer(bodyRequest)) .toMaybe() .map(httpResponse -> { if (httpResponse.statusCode() != 200) { throw new BadCredentialsException(httpResponse.statusMessage()); } return httpResponse.bodyAsJsonObject().getString("access_token"); }); }
private Maybe<String> authenticate(Authentication authentication) { // prepare body request parameters List<NameValuePair> urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair(CLIENT_ID, configuration.getClientId())); urlParameters.add(new BasicNameValuePair(CLIENT_SECRET, configuration.getClientSecret())); urlParameters.add(new BasicNameValuePair(REDIRECT_URI, (String) authentication.getAdditionalInformation().get(REDIRECT_URI))); urlParameters.add(new BasicNameValuePair(CODE, (String) authentication.getCredentials())); urlParameters.add(new BasicNameValuePair(GRANT_TYPE, "authorization_code")); String bodyRequest = URLEncodedUtils.format(urlParameters); return client.postAbs(configuration.getAccessTokenUri()) .putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(bodyRequest.length())) .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED) .rxSendBuffer(Buffer.buffer(bodyRequest)) .toMaybe() .map(httpResponse -> { if (httpResponse.statusCode() != 200) { throw new BadCredentialsException(httpResponse.statusMessage()); } return httpResponse.bodyAsJsonObject().getString("access_token"); }); }
private Maybe<String> authenticate(Authentication authentication) { // prepare body request parameters List<NameValuePair> urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair(CLIENT_ID, configuration.getClientId())); urlParameters.add(new BasicNameValuePair(CLIENT_SECRET, configuration.getClientSecret())); urlParameters.add(new BasicNameValuePair(REDIRECT_URI, (String) authentication.getAdditionalInformation().get(REDIRECT_URI))); urlParameters.add(new BasicNameValuePair(CODE, (String) authentication.getCredentials())); String bodyRequest = URLEncodedUtils.format(urlParameters); return client.postAbs(configuration.getAccessTokenUri()) .putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(bodyRequest.length())) .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED) .rxSendBuffer(Buffer.buffer(bodyRequest)) .toMaybe() .map(httpResponse -> { if (httpResponse.statusCode() != 200) { throw new BadCredentialsException(httpResponse.statusMessage()); } Map<String, String> bodyResponse = URLEncodedUtils.format(httpResponse.bodyAsString()); return bodyResponse.get("access_token"); }); }
private Maybe<String> authenticate(Authentication authentication) { // prepare body request parameters List<NameValuePair> urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair(CLIENT_ID, configuration.getClientId())); urlParameters.add(new BasicNameValuePair(CLIENT_SECRET, configuration.getClientSecret())); urlParameters.add(new BasicNameValuePair(REDIRECT_URI, (String) authentication.getAdditionalInformation().get(REDIRECT_URI))); urlParameters.add(new BasicNameValuePair(CODE, (String) authentication.getCredentials())); String bodyRequest = URLEncodedUtils.format(urlParameters); return client.postAbs(configuration.getAccessTokenUri()) .putHeader(HttpHeaders.CONTENT_LENGTH, String.valueOf(bodyRequest.length())) .putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED) .rxSendBuffer(Buffer.buffer(bodyRequest)) .toMaybe() .map(httpResponse -> { if (httpResponse.statusCode() != 200) { throw new BadCredentialsException(httpResponse.statusMessage()); } Map<String, String> bodyResponse = URLEncodedUtils.format(httpResponse.bodyAsString()); return bodyResponse.get("access_token"); }); }
@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(Http::mapJsonArrayOrError) .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()); }
@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(Http::mapJsonArrayOrError) .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(); }
@Override public Observable<List<NamespaceName>> getNamespaceNames(List<NamespaceId> namespaceIds) { JsonObject requestBody = new JsonObject(); requestBody.put("namespaceIds", namespaceIds.stream().map(id -> UInt64.bigIntegerToHex(id.getId())).collect(Collectors.toList())); return this.client .postAbs(this.url + "/namespace/names") .as(BodyCodec.jsonArray()) .rxSendJson(requestBody) .toObservable() .map(Http::mapJsonArrayOrError) .map(json -> objectMapper.<List<NamespaceNameDTO>>readValue(json.toString(), new TypeReference<List<NamespaceNameDTO>>() { })) .flatMapIterable(item -> item) .map(namespaceNameDTO -> { if (namespaceNameDTO.getParentId() != null) { return new NamespaceName( new NamespaceId(namespaceNameDTO.getNamespaceId().extractIntArray()), namespaceNameDTO.getName(), new NamespaceId(namespaceNameDTO.getParentId().extractIntArray())); } else { return new NamespaceName( new NamespaceId(namespaceNameDTO.getNamespaceId().extractIntArray()), namespaceNameDTO.getName()); } }) .toList() .toObservable(); }
private Observable<List<NamespaceInfo>> getNamespacesFromAccounts(List<Address> addresses, Optional<QueryParams> queryParams) { 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 + "/account/namespaces" + (queryParams.isPresent() ? queryParams.get().toUrl() : "")) .as(BodyCodec.jsonArray()) .rxSendJson(requestBody) .toObservable() .map(Http::mapJsonArrayOrError) .map(json -> objectMapper.<List<NamespaceInfoDTO>>readValue(json.toString(), new TypeReference<List<NamespaceInfoDTO>>() { })) .flatMapIterable(item -> item) .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() )) .toList() .toObservable()); }
@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(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()); }
httpRequest = webClient.postAbs(request.getUrl());