-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathApiRunner.java
41 lines (32 loc) · 1.17 KB
/
ApiRunner.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
package io.goodforgod.api.etherscan;
import io.goodforgod.api.etherscan.manager.RequestQueueManager;
import java.util.Map;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
public class ApiRunner extends Assertions {
private static final String DEFAULT_KEY = "YourApiKeyToken";
private static final String API_KEY;
private static final EtherScanAPI API;
static {
API_KEY = System.getenv().entrySet().stream()
.filter(e -> e.getKey().startsWith("ETHERSCAN_API_KEY"))
.map(Map.Entry::getValue)
.findFirst()
.orElse(DEFAULT_KEY);
final RequestQueueManager queueManager = (DEFAULT_KEY.equals(API_KEY))
? RequestQueueManager.anonymous()
: RequestQueueManager.planFree();
API = EtherScanAPI.builder()
.withApiKey(ApiRunner.API_KEY)
.withNetwork(EthNetworks.MAINNET)
.withQueue(queueManager)
.build();
}
public static EtherScanAPI getApi() {
return API;
}
@AfterAll
public static void cleanup() throws Exception {
API.close();
}
}