-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathEthScanAPIBuilder.java
71 lines (60 loc) · 2.27 KB
/
EthScanAPIBuilder.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
70
71
package io.goodforgod.api.etherscan;
import io.goodforgod.api.etherscan.error.EtherScanKeyException;
import io.goodforgod.api.etherscan.executor.EthHttpClient;
import io.goodforgod.api.etherscan.executor.impl.UrlEthHttpClient;
import io.goodforgod.api.etherscan.manager.RequestQueueManager;
import io.goodforgod.api.etherscan.manager.impl.FakeRequestQueueManager;
import io.goodforgod.api.etherscan.util.BasicUtils;
import java.util.function.Supplier;
import org.jetbrains.annotations.NotNull;
/**
* @author Anton Kurako (GoodforGod)
* @since 11.05.2023
*/
final class EthScanAPIBuilder implements EtherScanAPI.Builder {
private static final Supplier<EthHttpClient> DEFAULT_SUPPLIER = UrlEthHttpClient::new;
private static final String DEFAULT_KEY = "YourApiKeyToken";
private String apiKey = DEFAULT_KEY;
private EthNetwork ethNetwork = EthNetworks.MAINNET;
private RequestQueueManager queueManager = RequestQueueManager.DEFAULT_KEY_QUEUE;
private Supplier<EthHttpClient> ethHttpClientSupplier = DEFAULT_SUPPLIER;
@NotNull
@Override
public EtherScanAPI.Builder withApiKey(@NotNull String apiKey) {
if (BasicUtils.isBlank(apiKey))
throw new EtherScanKeyException("API key can not be null or empty");
this.apiKey = apiKey;
if (!DEFAULT_KEY.equals(apiKey)) {
queueManager = new FakeRequestQueueManager();
}
return this;
}
@NotNull
@Override
public EtherScanAPI.Builder withNetwork(@NotNull EthNetwork network) {
this.ethNetwork = network;
return this;
}
@NotNull
@Override
public EtherScanAPI.Builder withNetwork(@NotNull EthNetworks network) {
this.ethNetwork = network;
return this;
}
@NotNull
@Override
public EtherScanAPI.Builder withQueue(@NotNull RequestQueueManager queueManager) {
this.queueManager = queueManager;
return this;
}
@NotNull
@Override
public EtherScanAPI.Builder withHttpClient(@NotNull Supplier<EthHttpClient> httpClientSupplier) {
this.ethHttpClientSupplier = httpClientSupplier;
return this;
}
@Override
public @NotNull EtherScanAPI build() {
return new EtherScanAPIProvider(apiKey, ethNetwork, ethHttpClientSupplier, queueManager);
}
}