Skip to content

Commit

Permalink
Merge pull request #26 from alvasw/migrate_to_webclient
Browse files Browse the repository at this point in the history
CryptoYa: Migrate to WebClient
  • Loading branch information
gabernard authored Sep 4, 2023
2 parents e5dff18 + bf935e6 commit 72082ea
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ dependencies {
exclude group: 'ch.qos.logback'
exclude group: 'org.slf4j'
}
implementation(libs.spring.boot.starter.webflux)

testAnnotationProcessor libs.lombok
testCompileOnly libs.lombok
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ mockito-core = { module = 'org.mockito:mockito-core', version.ref = 'mockito-lib
slf4j-api = { module = 'org.slf4j:slf4j-api', version.ref = 'slf4j-lib' }
spring-dependency-management-plugin = { module = 'io.spring.gradle:dependency-management-plugin', version.ref = 'spring-dependency-management-plugin-lib' }
spring-boot-starter-web = { module = 'org.springframework.boot:spring-boot-starter-web', version.ref = 'spring-boot-starter-web-lib' }
spring-boot-starter-webflux = { module = 'org.springframework.boot:spring-boot-starter-webflux', version.ref = 'spring-boot-starter-web-lib' }

[bundles]
knowm-xchange-libs = [
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/bisq/price/spot/providers/CryptoYa.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import bisq.price.spot.ExchangeRateProvider;
import bisq.price.util.cryptoya.CryptoYaMarketData;
import org.springframework.core.env.Environment;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.function.client.WebClient;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.OptionalDouble;
import java.util.Set;
Expand All @@ -41,7 +43,7 @@ class CryptoYa extends ExchangeRateProvider {

private static final String CRYPTO_YA_BTC_ARS_API_URL = "https://criptoya.com/api/btc/ars/0.1";

private final RestTemplate restTemplate = new RestTemplate();
private final WebClient webClient = WebClient.create();

public CryptoYa(Environment env) {
super(env, "CRYPTOYA", "cryptoya", Duration.ofMinutes(1));
Expand All @@ -65,6 +67,11 @@ public Set<ExchangeRate> doGet() {
}

private CryptoYaMarketData fetchArsBlueMarketData() {
return restTemplate.getForObject(CRYPTO_YA_BTC_ARS_API_URL, CryptoYaMarketData.class);
return webClient.get()
.uri(CRYPTO_YA_BTC_ARS_API_URL)
.accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(CryptoYaMarketData.class)
.block(Duration.of(30, ChronoUnit.SECONDS));
}
}

0 comments on commit 72082ea

Please sign in to comment.