Skip to content

Commit 2d5d2bb

Browse files
erenalpaslanmehmet6parmakappcent
authored andcommitted
#31 Creates request classes for hotspot api (#51)
Co-authored-by: Eren <[email protected]>
1 parent 8d087cc commit 2d5d2bb

24 files changed

+886
-497
lines changed

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

Lines changed: 35 additions & 466 deletions
Large diffs are not rendered by default.
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,43 @@
11
package mobi.appcent.helium.api;
22

3+
import mobi.appcent.helium.request.hotspot.*;
34
import org.jetbrains.annotations.NotNull;
45

56
import java.io.IOException;
67

78
public interface IHotspotApi {
8-
public HotspotApi.APIgetHotspotsRequest getHotspots() throws IOException;
9+
HotspotsRequest getHotspots() throws IOException;
910

10-
public HotspotApi.APIgetHotspotByGivenAdressRequest getHotspotByGivenAdress() throws IOException;
11+
HotspotByGivenAddressRequest getHotspotByGivenAddress() throws IOException;
1112

12-
public HotspotApi.APIgetHotspotsByGivenNameRequest getHotspotsByGivenName() throws IOException;
13+
HotspotsByGivenNameRequest getHotspotsByGivenName(String name) throws IOException;
1314

14-
public HotspotApi.APIsearchHotspotsByGivenNameRequest searchHotspotsByGivenName() throws IOException;
15+
SearchHotspotsByGivenNameRequest searchHotspotsByGivenName() throws IOException;
1516

16-
public HotspotApi.APIsearchHotspotsByLocationDistanceRequest searchHotspotsByLocationDistance() throws IOException;
17+
SearchHotspotsByLocationDistanceRequest searchHotspotsByLocationDistance() throws IOException;
1718

18-
public HotspotApi.APIsearchHotspotsByLocationBoxRequest searchHotspotsByLocationBox() throws IOException;
19+
SearchHotspotsByLocationBoxRequest searchHotspotsByLocationBox() throws IOException;
1920

20-
public HotspotApi.APIgetHotspotsByGivenH3IndexRequest getHotspotsByGivenH3Index(String index) throws IOException;
21+
HotspotsByGivenH3IndexRequest getHotspotsByGivenH3Index(String index) throws IOException;
2122

22-
public HotspotApi.APIgetHotspotRolesRequest getHotspotRoles(@NotNull String address) throws IOException;
23+
HotspotRolesRequest getHotspotRoles(@NotNull String address) throws IOException;
2324

24-
public HotspotApi.APIgetHotspotsRolesCountRequest getHotspotsRolesCount(@NotNull String address) throws IOException;
25+
HotspotsRolesCountRequest getHotspotsRolesCount(@NotNull String address) throws IOException;
2526

26-
public HotspotApi.APIgetHotspotElectionsRequest getHotspotElections(@NotNull String address) throws IOException;
27+
HotspotElectionsRequest getHotspotElections(@NotNull String address) throws IOException;
2728

28-
public HotspotApi.APIgetElectedHotspotsRequest getElectedHotspots() throws IOException;
29+
ElectedHotspotsRequest getElectedHotspots() throws IOException;
2930

30-
public HotspotApi.APIgetHotspotChallangesRequest getHotspotChallanges(@NotNull String address) throws IOException;
31+
HotspotChallengesRequest getHotspotChallanges(@NotNull String address) throws IOException;
3132

32-
public HotspotApi.APIgetRewardsForHotspotRequest getRewardsForHotspot(@NotNull String address) throws IOException;
33+
RewardsForHotspotsRequest getRewardsForHotspot(@NotNull String address) throws IOException;
3334

34-
public HotspotApi.APIgetRewardsForHotspotByGivenRewardBlockRequest getRewardsForHotspotByGivenRewardBlock(@NotNull String address) throws IOException;
35+
RewardsForHotspotsByGivenRewardBlockRequest getRewardsForHotspotByGivenRewardBlock(@NotNull String address) throws IOException;
3536

36-
public HotspotApi.APIgetTotalRewardForHotspotRequest getTotalRewardForHotspot(@NotNull String address) throws IOException;
37+
TotalRewardForHotspotRequest getTotalRewardForHotspot(@NotNull String address) throws IOException;
3738

38-
public HotspotApi.APIgetWitnessesForHotspotRequest getWitnessesForHotspot(@NotNull String address) throws IOException;
39+
WitnessesForHotspotRequest getWitnessesForHotspot(@NotNull String address) throws IOException;
3940

40-
public HotspotApi.APIgetWitnessedForHotspotRequest getWitnessedForHotspot(@NotNull String address) throws IOException;
41+
WitnessedForHotspotRequest getWitnessedForHotspot(@NotNull String address) throws IOException;
4142

4243
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,11 @@ public class FieldConstant {
1313
public static final String FILTER_TYPES = "filter_types";
1414
public static final String MAX_BLOCK = "max_block";
1515
public static final String SEARCH = "search";
16+
public static final String LAT = "lat";
17+
public static final String LON = "lon";
18+
public static final String DISTANCE = "distance";
19+
public static final String SWLAT = "swlat";
20+
public static final String SWLON = "swlon";
21+
public static final String NELAT = "nelat";
22+
public static final String NELON = "nelon";
1623
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ 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 HOTSPOTS_PATH = BASE_PATH + "/hotspots";
2223
public static final String BLOCKS_PATH = BASE_PATH + "/blocks";
2324
}

src/main/java/mobi/appcent/helium/request/BaseRequest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package mobi.appcent.helium.request;
22

3-
import com.google.gson.Gson;
4-
import com.google.gson.JsonParseException;
3+
import com.google.gson.*;
54
import com.google.gson.stream.JsonReader;
65
import okhttp3.Call;
76
import okhttp3.Response;
@@ -51,4 +50,15 @@ public static <T> T deserialize(String body, Type returnType) {
5150
}
5251
}
5352
}
53+
54+
public static JsonObject convertToJsonArray(JsonObject obj, JsonElement data) {
55+
JsonArray arr = new JsonArray();
56+
arr.add(data.getAsJsonObject());
57+
obj.add("data", arr);
58+
return obj;
59+
}
60+
61+
public static Boolean isJsonArray(JsonElement element) {
62+
return element.isJsonArray();
63+
}
5464
}

src/main/java/mobi/appcent/helium/request/dc/DCBurnTotalsRequest.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,4 @@ public <T> T handleResponse(Response response, Type returnType) throws IOExcepti
7171
}
7272
return null;
7373
}
74-
75-
private static JsonObject convertToJsonArray(JsonObject obj, JsonElement data) {
76-
JsonArray arr = new JsonArray();
77-
arr.add(data.getAsJsonObject());
78-
obj.add("data", arr);
79-
return obj;
80-
}
81-
82-
public static Boolean isJsonArray(JsonElement element) {
83-
return element.isJsonArray();
84-
}
8574
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package mobi.appcent.helium.request.hotspot;
2+
3+
import com.google.gson.reflect.TypeToken;
4+
import mobi.appcent.helium.HeliumSdkClient;
5+
import mobi.appcent.helium.api.HotspotApi;
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.hotspot.HotspotsResponse;
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 3.12.2022
18+
*/
19+
public class ElectedHotspotsRequest extends BaseRequest {
20+
private final HeliumSdkClient client;
21+
22+
public ElectedHotspotsRequest(HeliumSdkClient client) {
23+
this.client = client;
24+
}
25+
26+
public HotspotsResponse execute() throws IOException {
27+
String path = UrlConstant.HOTSPOTS_PATH +"/elected";
28+
Call call = client.buildCall(path, HttpMethod.GET, Collections.emptyList(), null, null);
29+
Type type = TypeToken.get(HotspotsResponse.class).getType();
30+
return execute(call, type);
31+
}
32+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package mobi.appcent.helium.request.hotspot;
2+
3+
import com.google.gson.reflect.TypeToken;
4+
import mobi.appcent.helium.HeliumSdkClient;
5+
import mobi.appcent.helium.common.UrlConstant;
6+
import mobi.appcent.helium.httpClient.HttpMethod;
7+
import mobi.appcent.helium.request.BaseRequest;
8+
import mobi.appcent.helium.response.hotspot.HotspotResponse;
9+
import okhttp3.Call;
10+
11+
import java.io.IOException;
12+
import java.lang.reflect.Type;
13+
import java.util.Collections;
14+
15+
/**
16+
* Created by erenalpaslan on 3.12.2022
17+
*/
18+
public class HotspotByGivenAddressRequest extends BaseRequest {
19+
private final HeliumSdkClient client;
20+
private String address;
21+
22+
public HotspotByGivenAddressRequest(HeliumSdkClient client) {
23+
this.client = client;
24+
}
25+
26+
public HotspotByGivenAddressRequest address(String address) {
27+
this.address = address;
28+
return this;
29+
}
30+
31+
public HotspotResponse execute() throws IOException {
32+
String path = UrlConstant.HOTSPOTS_PATH + "/" + address;
33+
Call call = client.buildCall(path, HttpMethod.GET, Collections.emptyList(), null, null);
34+
Type type = TypeToken.get(HotspotResponse.class).getType();
35+
return execute(call, type);
36+
}
37+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package mobi.appcent.helium.request.hotspot;
2+
3+
import com.google.gson.reflect.TypeToken;
4+
import mobi.appcent.helium.HeliumSdkClient;
5+
import mobi.appcent.helium.common.FieldConstant;
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.challenge.ChallengesResponse;
11+
import okhttp3.Call;
12+
13+
import java.io.IOException;
14+
import java.lang.reflect.Type;
15+
import java.util.ArrayList;
16+
17+
/**
18+
* Created by erenalpaslan on 3.12.2022
19+
*/
20+
public class HotspotChallengesRequest extends BaseRequest {
21+
private final HeliumSdkClient client;
22+
private final String address;
23+
private String cursor;
24+
private String minTime;
25+
private String maxTime;
26+
private Integer limit;
27+
28+
public HotspotChallengesRequest cursor(String cursor) {
29+
this.cursor = cursor;
30+
return this;
31+
}
32+
33+
public HotspotChallengesRequest maxTime(String maxTime) {
34+
this.maxTime = maxTime;
35+
return this;
36+
}
37+
public HotspotChallengesRequest limit(int limit) {
38+
this.limit = limit;
39+
return this;
40+
}
41+
public HotspotChallengesRequest minTime(String minTime) {
42+
this.minTime = minTime;
43+
return this;
44+
}
45+
public HotspotChallengesRequest(HeliumSdkClient client, String address) {
46+
this.client = client;
47+
this.address = address; }
48+
49+
public ChallengesResponse execute() throws IOException {
50+
String path = UrlConstant.HOTSPOTS_PATH +"/"+address+"/challenges";
51+
ArrayList<Pair> queryParams = new ArrayList<>();
52+
queryParams.add(Pair.create(FieldConstant.CURSOR, cursor));
53+
queryParams.add(Pair.create(FieldConstant.MIN_TIME, minTime));
54+
queryParams.add(Pair.create(FieldConstant.MAX_TIME, maxTime));
55+
queryParams.add(Pair.create(FieldConstant.LIMIT, limit));
56+
Call call = client.buildCall(path, HttpMethod.GET, queryParams, null, null);
57+
Type type = TypeToken.get(ChallengesResponse.class).getType();
58+
return execute(call, type);
59+
}
60+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package mobi.appcent.helium.request.hotspot;
2+
3+
import com.google.gson.reflect.TypeToken;
4+
import mobi.appcent.helium.HeliumSdkClient;
5+
import mobi.appcent.helium.api.HotspotApi;
6+
import mobi.appcent.helium.common.FieldConstant;
7+
import mobi.appcent.helium.common.UrlConstant;
8+
import mobi.appcent.helium.httpClient.HttpMethod;
9+
import mobi.appcent.helium.model.Pair;
10+
import mobi.appcent.helium.request.BaseRequest;
11+
import mobi.appcent.helium.response.election.ListOfElectionsResponse;
12+
import okhttp3.Call;
13+
14+
import java.io.IOException;
15+
import java.lang.reflect.Type;
16+
import java.util.ArrayList;
17+
18+
/**
19+
* Created by erenalpaslan on 3.12.2022
20+
*/
21+
public class HotspotElectionsRequest extends BaseRequest {
22+
private final HeliumSdkClient client;
23+
private final String address;
24+
private String cursor;
25+
private String minTime;
26+
private String maxTime;
27+
private Integer limit;
28+
29+
public HotspotElectionsRequest cursor(String cursor) {
30+
this.cursor = cursor;
31+
return this;
32+
}
33+
34+
public HotspotElectionsRequest maxTime(String maxTime) {
35+
this.maxTime = maxTime;
36+
return this;
37+
}
38+
public HotspotElectionsRequest limit(int limit) {
39+
this.limit = limit;
40+
return this;
41+
}
42+
public HotspotElectionsRequest minTime(String minTime) {
43+
this.minTime = minTime;
44+
return this;
45+
}
46+
public HotspotElectionsRequest(HeliumSdkClient client, String address) {
47+
this.client = client;
48+
this.address = address;
49+
}
50+
51+
public ListOfElectionsResponse execute() throws IOException {
52+
String path = UrlConstant.HOTSPOTS_PATH +"/"+address+"/elections";
53+
ArrayList<Pair> queryParams = new ArrayList<>();
54+
queryParams.add(Pair.create(FieldConstant.CURSOR, cursor));
55+
queryParams.add(Pair.create(FieldConstant.MIN_TIME, minTime));
56+
queryParams.add(Pair.create(FieldConstant.MAX_TIME, maxTime));
57+
queryParams.add(Pair.create(FieldConstant.LIMIT, limit));
58+
Call call = client.buildCall(path, HttpMethod.GET, queryParams, null, null);
59+
Type type = TypeToken.get(ListOfElectionsResponse.class).getType();
60+
return execute(call, type);
61+
}
62+
}

0 commit comments

Comments
 (0)