-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathStatisticAPIProvider.java
69 lines (57 loc) · 2.52 KB
/
StatisticAPIProvider.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package io.goodforgod.api.etherscan;
import io.goodforgod.api.etherscan.error.EtherScanException;
import io.goodforgod.api.etherscan.error.EtherScanResponseException;
import io.goodforgod.api.etherscan.http.EthHttpClient;
import io.goodforgod.api.etherscan.manager.RequestQueueManager;
import io.goodforgod.api.etherscan.model.Price;
import io.goodforgod.api.etherscan.model.Supply;
import io.goodforgod.api.etherscan.model.response.PriceResponseTO;
import io.goodforgod.api.etherscan.model.response.StringResponseTO;
import io.goodforgod.api.etherscan.util.BasicUtils;
import java.math.BigInteger;
import org.jetbrains.annotations.NotNull;
/**
* Statistic API Implementation
*
* @see StatisticAPI
* @author GoodforGod
* @since 28.10.2018
*/
final class StatisticAPIProvider extends BasicProvider implements StatisticAPI {
private static final String ACT_SUPPLY_PARAM = ACT_PREFIX + "ethsupply";
private static final String ACT_TOKEN_SUPPLY_PARAM = ACT_PREFIX + "tokensupply";
private static final String ACT_LASTPRICE_PARAM = ACT_PREFIX + "ethprice";
private static final String CONTRACT_ADDRESS_PARAM = "&contractaddress=";
StatisticAPIProvider(RequestQueueManager queue,
String baseUrl,
EthHttpClient executor,
Converter converter) {
super(queue, "stats", baseUrl, executor, converter);
}
@NotNull
@Override
public Supply supply() throws EtherScanException {
final StringResponseTO response = getRequest(ACT_SUPPLY_PARAM, StringResponseTO.class);
if (response.getStatus() != 1)
throw new EtherScanResponseException(response);
return new Supply(new BigInteger(response.getResult()));
}
@NotNull
@Override
public BigInteger supply(String contract) throws EtherScanException {
BasicUtils.validateAddress(contract);
final String urlParams = ACT_TOKEN_SUPPLY_PARAM + CONTRACT_ADDRESS_PARAM + contract;
final StringResponseTO response = getRequest(urlParams, StringResponseTO.class);
if (response.getStatus() != 1)
throw new EtherScanResponseException(response);
return new BigInteger(response.getResult());
}
@NotNull
@Override
public Price lastPrice() throws EtherScanException {
final PriceResponseTO response = getRequest(ACT_LASTPRICE_PARAM, PriceResponseTO.class);
if (response.getStatus() != 1)
throw new EtherScanResponseException(response);
return response.getResult();
}
}