Skip to content

Commit 007a2f1

Browse files
committed
HttpExecutor timeout read support
HttpExecutor better timeout exception handling README, POM improvements Travis CI integration & code analysis
1 parent 9bb3355 commit 007a2f1

File tree

9 files changed

+336
-49
lines changed

9 files changed

+336
-49
lines changed

.travis.yml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: java
2+
3+
dist: trusty
4+
sudo: false
5+
6+
script:
7+
- "mvn cobertura:cobertura"
8+
9+
after_success:
10+
- bash <(curl -s https://codecov.io/bash)
11+
12+
jdk:
13+
- oraclejdk8
14+
- openjdk8

README.md

+31-12
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
Library supports all available EtherScan *API* calls for all available *Ethereum Networks*.
66

7-
![](https://media.giphy.com/media/1msHfmVdtuwkXww4ZC/giphy.gif)
8-
97
## Dependency :rocket:
108
**Maven**
119
```xml
@@ -24,7 +22,8 @@ dependencies {
2422
```
2523

2624
## Content
27-
- [Overall](#overall)
25+
- [Ethereum Networks](#mainnet-and-testnets)
26+
- [Custom HttpClient](#custom-httpclient)
2827
- [API examples](#api-examples)
2928
- [Account](#account-api)
3029
- [Block](#block-api)
@@ -33,29 +32,49 @@ dependencies {
3332
- [Proxy](#proxy-api)
3433
- [Stats](#stats-api)
3534
- [Transactions](#transaction-api)
35+
- [Token](#token-api)
3636
- [Version History](#version-history)
3737

38-
## Api Examples
38+
## Mainnet and Testnets
39+
API support Ethereum: *[MAINNET](https://etherscan.io), [ROPSTEN](https://ropsten.etherscan.io),
40+
[KOVAN](https://kovan.etherscan.io), [RINKEBY](https://rinkeby.etherscan.io)* networks.
41+
```java
42+
EtherScanApi api = new EtherScanApi(EthNetwork.MAINTNET);
43+
EtherScanApi api = new EtherScanApi(EthNetwork.RINKEBY);
44+
EtherScanApi api = new EtherScanApi("YourApiKey", EthNetwork.KOVAN);
45+
```
46+
47+
## Custom HttpClient
48+
49+
In case you need to set custom timeout, custom headers or better implementation for HttpClient,
50+
just implement **IHttpExecutor** by your self or initialize it with your values.
51+
52+
```java
53+
int connectionTimeout = 10000;
54+
int readTimeout = 7000;
55+
Supplier<IHttpExecutor> supplier = () -> new HttpExecutor(connectionTimeout);
56+
Supplier<IHttpExecutor> supplierFull = () -> new HttpExecutor(connectionTimeout, readTimeout);
57+
58+
59+
EtherScanApi api = new EtherScanApi(EthNetwork.RINKEBY, supplier);
60+
EtherScanApi apiWithKey = new EtherScanApi("YourApiKey", EthNetwork.MAINNET, supplierFull);
61+
```
62+
63+
## API Examples
3964

4065
You can read about all API methods on [Etherscan](https://etherscan.io/apis)
4166

4267
*Library support all available EtherScan API.*
4368

4469
You can use API with you key or without key as well (Check API request\sec restrictions).
70+
Library support limit when used without key and will limit requests up to *5 req/sec by itself*.
4571
```java
4672
EtherScanApi api = new EtherScanApi();
4773
EtherScanApi api = new EtherScanApi("YourApiKey");
4874
```
4975

5076
Below there are examples for each API category.
5177

52-
### Mainnet and Testnets
53-
API support Ethereum: *[MAINNET](https://etherscan.io), [ROPSTEN](https://ropsten.etherscan.io), [KOVAN](https://kovan.etherscan.io), [RINKEBY](https://rinkeby.etherscan.io)* networks.
54-
```java
55-
EtherScanApi api = new EtherScanApi(EthNetwork.MAINNET);
56-
EtherScanApi api = new EtherScanApi("YourApiKey", EthNetwork.KOVAN);
57-
```
58-
5978
### Account Api
6079
**Get Ether Balance for a single Address**
6180
```java
@@ -129,7 +148,7 @@ Optional<Boolean> status = api.txs().receiptStatus("0x513c1ba0bebf66436b5fed86ab
129148
```
130149

131150
### Token Api
132-
You can read account API [here](https://etherscan.io/apis#accounts)
151+
You can read token API [here](https://etherscan.io/apis#tokens)
133152

134153
Token API methods migrated to [Account](#account-api) & [Stats](#stats-api) respectfully.
135154

pom.xml

+151-6
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,76 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55

6-
<groupId>io.api</groupId>
7-
<artifactId>etherscan</artifactId>
6+
<groupId>com.github.goodforgod</groupId>
7+
<artifactId>java-etherscan-api</artifactId>
88
<version>1.0.0</version>
9+
<packaging>jar</packaging>
910

10-
<name>java-etherscan-api</name>
11+
<name>${project.groupId}:${project.artifactId}</name>
12+
<description>Library is a wrapper for EtherScan API.</description>
13+
<url>http://maven.apache.org</url>
14+
15+
<licenses>
16+
<license>
17+
<name>MIT License</name>
18+
<url>https://github.com/GoodforGod/java-etherscan-api/blob/master/LICENSE</url>
19+
<distribution>repo</distribution>
20+
</license>
21+
</licenses>
22+
23+
<developers>
24+
<developer>
25+
<name>Anton Kurako</name>
26+
<email>goodforgod.dev@gmail.com</email>
27+
<organizationUrl>https://github.com/GoodforGod</organizationUrl>
28+
</developer>
29+
</developers>
30+
31+
<scm>
32+
<connection>scm:git:git://github.com/GoodforGod/java-etherscan-api.git</connection>
33+
<developerConnection>scm:git:ssh://GoodforGod/java-etherscan-api.git</developerConnection>
34+
<url>https://github.com/GoodforGod/java-etherscan-api/tree/master</url>
35+
</scm>
36+
37+
<distributionManagement>
38+
<snapshotRepository>
39+
<id>ossrh</id>
40+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
41+
</snapshotRepository>
42+
<repository>
43+
<id>ossrh</id>
44+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
45+
</repository>
46+
</distributionManagement>
1147

1248
<properties>
1349
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1450
<maven.compiler.source>1.8</maven.compiler.source>
1551
<maven.compiler.target>1.8</maven.compiler.target>
52+
53+
<maven-build-plugin-version>3.0.2</maven-build-plugin-version>
54+
<maven-gpg-plugin-version>1.6</maven-gpg-plugin-version>
55+
<maven-source-plugin-version>3.0.1</maven-source-plugin-version>
56+
<maven-javadoc-plugin-version>2.10.4</maven-javadoc-plugin-version>
57+
<maven-nexus-staging-maven-plugin-version>1.6.8</maven-nexus-staging-maven-plugin-version>
58+
<cobertura-plugin-version>2.7</cobertura-plugin-version>
59+
60+
<junit-version>4.12</junit-version>
61+
<gson-version>2.8.5</gson-version>
1662
</properties>
1763

1864
<dependencies>
1965
<dependency>
2066
<groupId>junit</groupId>
2167
<artifactId>junit</artifactId>
22-
<version>4.12</version>
68+
<version>${junit-version}</version>
2369
<scope>test</scope>
2470
</dependency>
2571

2672
<dependency>
2773
<groupId>com.google.code.gson</groupId>
2874
<artifactId>gson</artifactId>
29-
<version>2.8.5</version>
75+
<version>${gson-version}</version>
3076
</dependency>
3177

3278
<dependency>
@@ -36,7 +82,106 @@
3682
</dependency>
3783
</dependencies>
3884

39-
<build>
85+
<profiles>
86+
<profile>
87+
<id>release</id>
88+
<build>
89+
<plugins>
90+
<plugin>
91+
<groupId>org.sonatype.plugins</groupId>
92+
<artifactId>nexus-staging-maven-plugin</artifactId>
93+
<version>${maven-nexus-staging-maven-plugin-version}</version>
94+
<extensions>true</extensions>
95+
<configuration>
96+
<serverId>ossrh</serverId>
97+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
98+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
99+
</configuration>
100+
</plugin>
101+
</plugins>
102+
</build>
103+
</profile>
104+
105+
<profile>
106+
<id>sign</id>
107+
<build>
108+
<plugins>
109+
<plugin>
110+
<groupId>org.apache.maven.plugins</groupId>
111+
<artifactId>maven-gpg-plugin</artifactId>
112+
<version>${maven-gpg-plugin-version}</version>
113+
<executions>
114+
<execution>
115+
<id>sign-artifacts</id>
116+
<phase>verify</phase>
117+
<goals>
118+
<goal>sign</goal>
119+
</goals>
120+
</execution>
121+
</executions>
122+
</plugin>
123+
</plugins>
124+
</build>
125+
</profile>
126+
127+
<profile>
128+
<id>build-extras</id>
129+
<activation>
130+
<activeByDefault>true</activeByDefault>
131+
</activation>
132+
<build>
133+
<plugins>
134+
<plugin>
135+
<groupId>org.apache.maven.plugins</groupId>
136+
<artifactId>maven-source-plugin</artifactId>
137+
<version>${maven-source-plugin-version}</version>
138+
<executions>
139+
<execution>
140+
<id>attach-sources</id>
141+
<goals>
142+
<goal>jar-no-fork</goal>
143+
</goals>
144+
</execution>
145+
</executions>
146+
</plugin>
40147

148+
<plugin>
149+
<groupId>org.apache.maven.plugins</groupId>
150+
<artifactId>maven-javadoc-plugin</artifactId>
151+
<version>${maven-javadoc-plugin-version}</version>
152+
<executions>
153+
<execution>
154+
<id>attach-javadocs</id>
155+
<goals>
156+
<goal>jar</goal>
157+
</goals>
158+
</execution>
159+
</executions>
160+
</plugin>
161+
</plugins>
162+
</build>
163+
</profile>
164+
</profiles>
165+
166+
<build>
167+
<plugins>
168+
<plugin>
169+
<groupId>org.codehaus.mojo</groupId>
170+
<artifactId>cobertura-maven-plugin</artifactId>
171+
<version>${cobertura-plugin-version}</version>
172+
<configuration>
173+
<formats>
174+
<format>html</format>
175+
<format>xml</format>
176+
</formats>
177+
<check/>
178+
</configuration>
179+
</plugin>
180+
<plugin>
181+
<groupId>org.apache.maven.plugins</groupId>
182+
<artifactId>maven-jar-plugin</artifactId>
183+
<version>${maven-build-plugin-version}</version>
184+
</plugin>
185+
</plugins>
41186
</build>
42187
</project>

settings.xml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
5+
<servers>
6+
<server>
7+
<id>ossrh</id>
8+
<username>${env.OSSRH_JIRA_USERNAME}</username>
9+
<password>${env.OSSRH_JIRA_PASSWORD}</password>
10+
</server>
11+
</servers>
12+
13+
<profiles>
14+
<profile>
15+
<id>ossrh</id>
16+
<activation>
17+
<activeByDefault>true</activeByDefault>
18+
</activation>
19+
<properties>
20+
<gpg.executable>gpg</gpg.executable>
21+
<gpg.keyname>${env.GPG_KEY_NAME}</gpg.keyname>
22+
<gpg.passphrase>${env.GPG_PASSPHRASE}</gpg.passphrase>
23+
</properties>
24+
</profile>
25+
</profiles>
26+
</settings>
+12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
package io.api.etherscan;
22

3+
import io.api.etherscan.core.impl.EtherScanApi;
4+
import io.api.etherscan.executor.IHttpExecutor;
5+
import io.api.etherscan.executor.impl.HttpExecutor;
6+
import io.api.etherscan.model.EthNetwork;
7+
8+
import java.util.function.Supplier;
9+
310
public class App {
411
public static void main(String[] args) {
12+
int connectionTimeout = 10000;
13+
int readTimeout = 7000;
14+
Supplier<IHttpExecutor> supplier = () -> new HttpExecutor(connectionTimeout);
515

16+
EtherScanApi api = new EtherScanApi(EthNetwork.RINKEBY, supplier);
17+
EtherScanApi apiWithKey = new EtherScanApi("YourApiKey", EthNetwork.MAINNET, supplier);
618
}
719
}

0 commit comments

Comments
 (0)