Skip to content

Commit

Permalink
[2.0.0]
Browse files Browse the repository at this point in the history
BasicProvider simplified
StatisticPriceApiTests assert fixed
  • Loading branch information
GoodforGod committed May 15, 2023
1 parent b05bd8a commit e6bee19
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 28 deletions.
28 changes: 2 additions & 26 deletions src/main/java/io/goodforgod/api/etherscan/BasicProvider.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.goodforgod.api.etherscan;

import io.goodforgod.api.etherscan.error.EtherScanException;
import io.goodforgod.api.etherscan.error.EtherScanParseException;
import io.goodforgod.api.etherscan.error.EtherScanRateLimitException;
import io.goodforgod.api.etherscan.error.EtherScanResponseException;
Expand All @@ -9,7 +8,6 @@
import io.goodforgod.api.etherscan.model.response.StringResponseTO;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Map;

/**
* Base provider for API Implementations
Expand Down Expand Up @@ -64,36 +62,14 @@ <T> T convert(byte[] json, Class<T> tClass) {
}

final String jsonAsString = new String(json, StandardCharsets.UTF_8);
try {
final Map<String, Object> map = converter.fromJson(json, Map.class);
final Object result = map.get("result");
if (result instanceof String && ((String) result).startsWith(MAX_RATE_LIMIT_REACHED))
throw new EtherScanRateLimitException(((String) result));

throw new EtherScanParseException(e.getMessage() + ", for response: " + jsonAsString, e.getCause(), jsonAsString);
} catch (EtherScanException ex) {
throw ex;
} catch (Exception ex) {
throw new EtherScanParseException(e.getMessage() + ", for response: " + jsonAsString, e.getCause(), jsonAsString);
}
throw new EtherScanParseException(e.getMessage() + ", for response: " + jsonAsString, e.getCause(), jsonAsString);
}
}

byte[] getRequest(String urlParameters) {
queue.takeTurn();
final URI uri = URI.create(baseUrl + module + urlParameters);
final byte[] result = executor.get(uri);
if (result.length == 0) {
final StringResponseTO emptyResponse = StringResponseTO.builder()
.withStatus("0")
.withMessage("Server returned null value for GET request at URL - " + uri)
.withResult("")
.build();

throw new EtherScanResponseException(emptyResponse, "Server returned null value for GET request at URL - " + uri);
}

return result;
return executor.get(uri);
}

byte[] postRequest(String urlParameters, String dataToPost) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ void correct() {
assertNotNull(price);
assertNotNull(price.btcTimestamp());
assertNotNull(price.usdTimestamp());
assertNotEquals(0.0, price.inBtc());
assertNotEquals(0.0, price.inUsd());
assertNotEquals(0.0, price.inBtc().doubleValue());
assertNotEquals(0.0, price.inUsd().doubleValue());
assertNotNull(price.toString());

Price empty = Price.builder().build();
Expand Down

0 comments on commit e6bee19

Please sign in to comment.