Skip to content

Commit a639228

Browse files
committed
Update getClanStats()
1 parent ba97403 commit a639228

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

src/main/java/material/clan/Clan.java

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.google.gson.JsonElement;
1313
import com.google.gson.JsonObject;
1414
import material.DestinyAPI;
15+
import material.stats.ActivityMode;
1516
import material.user.BungieUser;
1617
import utils.HttpUtils;
1718
import utils.StringUtils;
@@ -216,14 +217,11 @@ private int[] splitIntoParts(int whole, int parts) {
216217
return arr;
217218
}
218219

220+
/**
221+
* Returns if this BungieUser is a member of the clan
222+
*/
219223
public boolean isMember(BungieUser bungieUser) {
220-
for (BungieUser bungieUser1 : getMembers()) {
221-
if (bungieUser1.getBungieMembershipID().equals(bungieUser.getBungieMembershipID())) {
222-
return true;
223-
}
224-
}
225-
226-
return false;
224+
return isMember(bungieUser.getBungieMembershipID());
227225
}
228226

229227
public boolean isMember(String bungieID) {
@@ -236,10 +234,23 @@ public boolean isMember(String bungieID) {
236234
return false;
237235
}
238236

239-
public JsonObject getClanStats() {
240-
return hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/Stats/AggregateClanStats/" + getClanID() + "/?modes=4");
237+
/**
238+
* Retrieve a JsonObject depicting the top stats of the clna
239+
* Unfortunately does not say who has those top stats
240+
*/
241+
public JsonObject getClanStats(ActivityMode... filter) {
242+
String queryString = "/?modes=";
243+
for(ActivityMode activityMode : filter) {
244+
queryString = queryString.concat(activityMode.getBungieValue() + ",");
245+
}
246+
queryString = queryString.substring(0, queryString.length() - 2); // Remove the last comma
247+
248+
return hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/Stats/AggregateClanStats/" + getClanID() + queryString);
241249
}
242250

251+
/**
252+
* Get the date that this user joined the clan
253+
*/
243254
public Date getJoinDate(BungieUser member) {
244255
if (jj == null) {
245256
jj = hu.urlRequestGET("https://www.bungie.net/Platform/GroupV2/" + clanId + "/Members/").get("Response").getAsJsonObject();
@@ -255,6 +266,9 @@ public Date getJoinDate(BungieUser member) {
255266
return null; // Return null if there were no matching users found
256267
}
257268

269+
/**
270+
* Get the management class for this clan
271+
*/
258272
public ClanManagement getClanManagement() {
259273
if (clanManagement != null) { return clanManagement; }
260274
clanManagement = new ClanManagement(this);

src/main/java/utils/HttpUtils.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,16 @@ public JsonObject urlRequestGET(String url) {
5353
return parse.getAsJsonObject();
5454
}
5555

56-
public String urlRequestGETstring(String url) {
56+
public Object urlRequestGETstring(String url) throws ExecutionException, InterruptedException {
5757
HttpClient client = HttpClient.newHttpClient();
5858
HttpRequest request = HttpRequest.newBuilder()
5959
.uri(URI.create(url))
6060
.timeout(Duration.ofMinutes(1))
6161
.header("X-API-KEY", apiKey)
6262
.GET()
6363
.build();
64-
CompletableFuture<String> response = client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).thenApplyAsync(HttpResponse::body);
65-
try {
66-
return response.get();
67-
} catch (InterruptedException | ExecutionException e) {
68-
e.printStackTrace();
69-
}
70-
return null;
64+
HttpResponse<String> response = client.sendAsync(request, HttpResponse.BodyHandlers.ofString()).get();
65+
return response;
7166
}
7267

7368
public JsonObject urlRequestGETOauth(String url) {

0 commit comments

Comments
 (0)