Skip to content

Commit 19f62a1

Browse files
erenalpaslanmehmet6parmakappcent
authored andcommitted
#31 Creates request classes for stat api (#54)
Co-authored-by: Eren <[email protected]>
1 parent 1ab0e83 commit 19f62a1

File tree

5 files changed

+85
-38
lines changed

5 files changed

+85
-38
lines changed
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package mobi.appcent.helium.api;
22

3+
import mobi.appcent.helium.request.stat.BlockchainStatsRequest;
4+
import mobi.appcent.helium.request.stat.TokenSupplyRequest;
5+
36
import java.io.IOException;
47

58
/**
69
* Created by erenalpaslan on 28.10.2022
710
*/
811
public interface IStatApi {
9-
public StatApi.APIgetBlockchainStatsRequest getBlockchainStats() throws IOException;
12+
BlockchainStatsRequest getBlockchainStats() throws IOException;
1013

11-
public StatApi.APIgetTokenSupplyRequest getTokenSupply() throws IOException;
14+
TokenSupplyRequest getTokenSupply() throws IOException;
1215
}

src/main/java/mobi/appcent/helium/api/StatApi.java

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.google.gson.reflect.TypeToken;
44
import mobi.appcent.helium.httpClient.HttpMethod;
5+
import mobi.appcent.helium.request.stat.BlockchainStatsRequest;
6+
import mobi.appcent.helium.request.stat.TokenSupplyRequest;
57
import mobi.appcent.helium.response.block.BlockchainStatsResponse;
68
import mobi.appcent.helium.model.Pair;
79
import mobi.appcent.helium.response.stat.TokenSupplyResponse;
@@ -27,44 +29,12 @@ String path() {
2729
}
2830

2931
@Override
30-
public APIgetBlockchainStatsRequest getBlockchainStats() throws IOException {
31-
return new APIgetBlockchainStatsRequest();
32-
}
33-
34-
public class APIgetBlockchainStatsRequest {
35-
36-
public APIgetBlockchainStatsRequest() {}
37-
38-
public BlockchainStatsResponse execute() throws IOException {
39-
Call call = sdkClient.buildCall(path(), HttpMethod.GET, Collections.emptyList(), null, null);
40-
Type type = TypeToken.get(BlockchainStatsResponse.class).getType();
41-
return StatApi.this.execute(call, type);
42-
}
32+
public BlockchainStatsRequest getBlockchainStats() throws IOException {
33+
return new BlockchainStatsRequest(sdkClient);
4334
}
4435

4536
@Override
46-
public APIgetTokenSupplyRequest getTokenSupply() throws IOException {
47-
return new APIgetTokenSupplyRequest();
48-
}
49-
50-
public class APIgetTokenSupplyRequest {
51-
52-
private String format;
53-
54-
public APIgetTokenSupplyRequest() {}
55-
56-
public APIgetTokenSupplyRequest format(String format) {
57-
this.format = format;
58-
return this;
59-
}
60-
61-
public TokenSupplyResponse execute() throws IOException {
62-
String path = path() + "/token_supply";
63-
ArrayList<Pair> queryParams = new ArrayList<>();
64-
queryParams.add(Pair.create("format", format));
65-
Call call = sdkClient.buildCall(path, HttpMethod.GET, Collections.emptyList(), null, null);
66-
Type type = TypeToken.get(TokenSupplyResponse.class).getType();
67-
return StatApi.this.execute(call, type);
68-
}
37+
public TokenSupplyRequest getTokenSupply() throws IOException {
38+
return new TokenSupplyRequest(sdkClient);
6939
}
7040
}

src/main/java/mobi/appcent/helium/common/UrlConstant.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class UrlConstant {
1919
public static final String ASSERT_LOCATIONS_PATH = BASE_PATH + "/assert_locations";
2020
public static final String ELECTIONS_PATH = BASE_PATH + "/elections";
2121
public static final String TRANSACTIONS_PATH = BASE_PATH + "/transactions";
22+
public static final String STAT_PATH = BASE_PATH + "/stats";
2223
public static final String CITY_PATH = BASE_PATH + "/cities";
2324
public static final String HOTSPOTS_PATH = BASE_PATH + "/hotspots";
2425
public static final String BLOCKS_PATH = BASE_PATH + "/blocks";
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package mobi.appcent.helium.request.stat;
2+
3+
import com.google.gson.reflect.TypeToken;
4+
import mobi.appcent.helium.HeliumSdkClient;
5+
import mobi.appcent.helium.api.StatApi;
6+
import mobi.appcent.helium.common.UrlConstant;
7+
import mobi.appcent.helium.httpClient.HttpMethod;
8+
import mobi.appcent.helium.request.BaseRequest;
9+
import mobi.appcent.helium.response.block.BlockchainStatsResponse;
10+
import okhttp3.Call;
11+
12+
import java.io.IOException;
13+
import java.lang.reflect.Type;
14+
import java.util.Collections;
15+
16+
/**
17+
* Created by erenalpaslan on 4.12.2022
18+
*/
19+
public class BlockchainStatsRequest extends BaseRequest {
20+
private final HeliumSdkClient client;
21+
22+
public BlockchainStatsRequest(HeliumSdkClient client) {
23+
this.client = client;
24+
}
25+
26+
public BlockchainStatsResponse execute() throws IOException {
27+
Call call = client.buildCall(UrlConstant.STAT_PATH, HttpMethod.GET, Collections.emptyList(), null, null);
28+
Type type = TypeToken.get(BlockchainStatsResponse.class).getType();
29+
return execute(call, type);
30+
}
31+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package mobi.appcent.helium.request.stat;
2+
3+
import com.google.gson.reflect.TypeToken;
4+
import mobi.appcent.helium.HeliumSdkClient;
5+
import mobi.appcent.helium.api.StatApi;
6+
import mobi.appcent.helium.common.UrlConstant;
7+
import mobi.appcent.helium.httpClient.HttpMethod;
8+
import mobi.appcent.helium.model.Pair;
9+
import mobi.appcent.helium.request.BaseRequest;
10+
import mobi.appcent.helium.response.stat.TokenSupplyResponse;
11+
import okhttp3.Call;
12+
13+
import java.io.IOException;
14+
import java.lang.reflect.Type;
15+
import java.util.ArrayList;
16+
import java.util.Collections;
17+
18+
/**
19+
* Created by erenalpaslan on 4.12.2022
20+
*/
21+
public class TokenSupplyRequest extends BaseRequest {
22+
private final HeliumSdkClient client;
23+
private String format;
24+
25+
public TokenSupplyRequest(HeliumSdkClient client) {
26+
this.client = client;
27+
}
28+
29+
public TokenSupplyRequest format(String format) {
30+
this.format = format;
31+
return this;
32+
}
33+
34+
public TokenSupplyResponse execute() throws IOException {
35+
String path = UrlConstant.STAT_PATH + "/token_supply";
36+
ArrayList<Pair> queryParams = new ArrayList<>();
37+
queryParams.add(Pair.create("format", format));
38+
Call call = client.buildCall(path, HttpMethod.GET, Collections.emptyList(), null, null);
39+
Type type = TypeToken.get(TokenSupplyResponse.class).getType();
40+
return execute(call, type);
41+
}
42+
}

0 commit comments

Comments
 (0)