Skip to content

Commit 7a4073f

Browse files
committed
getGlobalDisplayName() full release and HttpUtils re-structuring
1 parent cee578d commit 7a4073f

File tree

12 files changed

+63
-24
lines changed

12 files changed

+63
-24
lines changed

src/main/java/material/DestinyAPI.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,23 @@ public class DestinyAPI {
3232
private static String oauthCode = null;
3333
private static String accessToken = null;
3434
private static String refreshToken = null;
35+
3536
private static OAuthManager oam = null;
3637
private static boolean debugEnabled = false;
3738

39+
private static HttpUtils httpUtils;
40+
41+
/**
42+
* Set the api key used by the DestinyAPI
43+
*/
3844
public DestinyAPI setApiKey(String apiKey) {
3945
DestinyAPI.apiKey = apiKey;
4046
if(hasOauthManager()) {
4147
oam.setAPIToken(apiKey);
4248
}
49+
50+
httpUtils = new HttpUtils(apiKey);
51+
4352
return this;
4453
}
4554

@@ -74,12 +83,19 @@ public DestinyAPI setRefreshToken(String refreshToken) {
7483
return this;
7584
}
7685

86+
/**
87+
* Debug mode prints all requests and their responses to the console
88+
* This is very useful for feature development
89+
*/
7790
public DestinyAPI enableDebugMode() {
7891
DestinyAPI.debugEnabled = true;
7992

8093
return this;
8194
}
8295

96+
/**
97+
* Disable debug mode
98+
*/
8399
public DestinyAPI disableDebugMode() {
84100
DestinyAPI.debugEnabled = false;
85101

@@ -123,7 +139,7 @@ public static BungieUser getMemberFromSteamID(String steamID) {
123139
* Currently only works with Steam IDs (see getMemberFromSteamID())
124140
*/
125141
private static BungieUser getMemberFromPlatformID(String platformName, String platformID) {
126-
JsonObject jsonObject = new HttpUtils().urlRequestGET("https://www.bungie.net/Platform/User/GetMembershipFromHardLinkedCredential/" + platformName + "/" + platformID + "/").getAsJsonObject("Response");
142+
JsonObject jsonObject = getHttpUtils().urlRequestGET("https://www.bungie.net/Platform/User/GetMembershipFromHardLinkedCredential/" + platformName + "/" + platformID + "/").getAsJsonObject("Response");
127143

128144
return new BungieUser(jsonObject.get("membershipId").getAsString());
129145
}
@@ -139,7 +155,7 @@ private static BungieUser getMemberFromPlatformID(String platformName, String pl
139155
public static UserCredential[] getUserCredentials(BungieUser bungieUser) {
140156
List<UserCredential> list = new LinkedList<>();
141157

142-
for(JsonElement je : new HttpUtils().urlRequestGETOauth("https://www.bungie.net/Platform/User/GetCredentialTypesForTargetAccount/" + bungieUser.getBungieMembershipID() + "/").getAsJsonArray("Response")) {
158+
for(JsonElement je : getHttpUtils().urlRequestGETOauth("https://www.bungie.net/Platform/User/GetCredentialTypesForTargetAccount/" + bungieUser.getBungieMembershipID() + "/").getAsJsonArray("Response")) {
143159
JsonObject jo = je.getAsJsonObject();
144160

145161
if(jo.has("credentialDisplayName")) {
@@ -178,7 +194,7 @@ public static UserCredential getUserCredential(UserCredentialType type, BungieUs
178194
* If you only know their name, use searchBungieGlobalDisplayNames()
179195
*/
180196
public static List<BungieUser> getUsersWithName(String name) {
181-
HttpUtils hu = new HttpUtils();
197+
HttpUtils hu = getHttpUtils();
182198
List<BungieUser> temp = new ArrayList<>();
183199
List<String> ids = new ArrayList<>();
184200

@@ -224,7 +240,7 @@ public static List<BungieUser> searchGlobalDisplayNames(String prefix) {
224240

225241
List<BungieUser> bungieUsers = new ArrayList<>();
226242

227-
JsonArray jsonArray = new HttpUtils().urlRequestGET("https://www.bungie.net/Platform/User/Search/Prefix/" + prefix + "/0/").getAsJsonObject("Response").getAsJsonArray("searchResults");
243+
JsonArray jsonArray = getHttpUtils().urlRequestGET("https://www.bungie.net/Platform/User/Search/Prefix/" + prefix + "/0/").getAsJsonObject("Response").getAsJsonArray("searchResults");
228244

229245
for(JsonElement jsonElement : jsonArray) {
230246
JsonObject jsonObject = jsonElement.getAsJsonObject();
@@ -266,4 +282,8 @@ public static String getRefreshToken() {
266282

267283
public static boolean isDebugEnabled() { return DestinyAPI.debugEnabled; }
268284

285+
public static HttpUtils getHttpUtils() {
286+
return httpUtils;
287+
}
288+
269289
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
public class Clan extends ContentFramework {
2727

2828
private String apiKey = DestinyAPI.getApiKey();
29-
private HttpUtils hu = new HttpUtils();
29+
private HttpUtils hu = DestinyAPI.getHttpUtils();
3030
private JsonObject jo, cjo; // The entire Clan response
3131

3232
private long clanId = -1;

src/main/java/material/clan/ClanManagement.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import com.google.gson.JsonArray;
1212
import com.google.gson.JsonElement;
13+
import material.DestinyAPI;
1314
import material.user.BungieUser;
1415
import utils.HttpUtils;
1516

@@ -23,7 +24,7 @@
2324
*/
2425
public class ClanManagement {
2526

26-
HttpUtils hu = new HttpUtils();
27+
HttpUtils hu = DestinyAPI.getHttpUtils();
2728

2829
private Clan clan;
2930
private List<BungieUser> bannedMembers;

src/main/java/material/inventory/DestinyItem.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import com.google.gson.JsonElement;
1212
import com.google.gson.JsonObject;
13+
import material.DestinyAPI;
1314
import material.manifest.ManifestEntityTypes;
1415
import utils.HttpUtils;
1516
import utils.framework.ContentInterface;
@@ -22,7 +23,7 @@
2223
*/
2324
public class DestinyItem implements ContentInterface {
2425

25-
HttpUtils hu = new HttpUtils();
26+
HttpUtils hu = DestinyAPI.getHttpUtils();
2627

2728
private String hashID, name, icon, description;
2829
private boolean hasIcon;
@@ -159,7 +160,7 @@ public enum ItemTier {
159160
* Return a list of all items that contain or match the name provided
160161
*/
161162
public static List<DestinyItem> searchForItems(String itemName) {
162-
HttpUtils httpUtils = new HttpUtils();
163+
HttpUtils httpUtils = DestinyAPI.getHttpUtils();
163164
List<DestinyItem> destinyItemList = new ArrayList<>();
164165
itemName = itemName.replace(" ", "%20");
165166

src/main/java/material/manifest/DestinyManifest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package material.manifest;
1010

1111
import com.google.gson.JsonObject;
12+
import material.DestinyAPI;
1213
import utils.HttpUtils;
1314
import utils.framework.ContentFramework;
1415

@@ -61,7 +62,7 @@ public String getJsonWorldContentPath(Language language) {
6162
}
6263

6364
public JsonObject getWorldContent(Language language) {
64-
return new HttpUtils().urlRequestGET("https://www.bungie.net" + getJsonWorldContentPath(language));
65+
return DestinyAPI.getHttpUtils().urlRequestGET("https://www.bungie.net" + getJsonWorldContentPath(language));
6566
}
6667

6768
/**
@@ -75,7 +76,7 @@ public JsonObject getDefinitionLibrary(ManifestEntityTypes manifestEntityTypes)
7576

7677
public JsonObject getDefinitionLibrary(Language language, ManifestEntityTypes manifestEntityTypes) {
7778
if(!worldComponents.containsKey(manifestEntityTypes.getBungieEntityValue())) {
78-
worldComponents.put(manifestEntityTypes.getBungieEntityValue(), new HttpUtils().urlRequestGET("https://www.bungie.net" + getJO().getAsJsonObject("jsonWorldComponentContentPaths").getAsJsonObject(language.getCode()).get(manifestEntityTypes.getBungieEntityValue()).getAsString()));
79+
worldComponents.put(manifestEntityTypes.getBungieEntityValue(), DestinyAPI.getHttpUtils().urlRequestGET("https://www.bungie.net" + getJO().getAsJsonObject("jsonWorldComponentContentPaths").getAsJsonObject(language.getCode()).get(manifestEntityTypes.getBungieEntityValue()).getAsString()));
7980
}
8081

8182
return worldComponents.get(manifestEntityTypes.getBungieEntityValue());

src/main/java/material/stats/activities/Activity.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import com.google.gson.JsonElement;
1212
import com.google.gson.JsonObject;
13+
import material.DestinyAPI;
1314
import utils.HttpUtils;
1415
import utils.StringUtils;
1516
import utils.framework.ContentFramework;
@@ -25,7 +26,7 @@
2526
*/
2627
public class Activity extends ContentFramework {
2728

28-
private HttpUtils hu = new HttpUtils();
29+
private HttpUtils hu = DestinyAPI.getHttpUtils();
2930

3031
private Date time;
3132
private String activityId, referenceId, directoryActivityHash, instanceId;

src/main/java/material/stats/activities/ActivityHistoryReview.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.google.gson.JsonArray;
1212
import com.google.gson.JsonElement;
1313
import com.google.gson.JsonObject;
14+
import material.DestinyAPI;
1415
import material.clan.Clan;
1516
import material.manifest.ManifestEntityTypes;
1617
import material.user.BungieUser;
@@ -22,7 +23,7 @@
2223

2324
public class ActivityHistoryReview {
2425

25-
private HttpUtils httpUtils = new HttpUtils();
26+
private HttpUtils httpUtils = DestinyAPI.getHttpUtils();
2627

2728
public LinkedHashMap<String, Activity> getMostUnrecentAttempts(Clan clan, ActivityIdentifier activityIdentifier) {
2829
HashMap<String, Activity> map = new HashMap<>();

src/main/java/material/stats/character/UserStats.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package material.stats.character;
1010

1111
import com.google.gson.JsonObject;
12+
import material.DestinyAPI;
1213
import material.user.BungieUser;
1314
import material.user.DestinyCharacter;
1415
import utils.HttpUtils;
@@ -17,7 +18,7 @@
1718

1819
public class UserStats {
1920

20-
HttpUtils hu = new HttpUtils();
21+
HttpUtils hu = DestinyAPI.getHttpUtils();
2122
BungieUser bungieUser;
2223
DestinyCharacter destinyCharacter;
2324
JsonObject jo;

src/main/java/material/user/BungieUser.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.google.gson.JsonArray;
1212
import com.google.gson.JsonElement;
1313
import com.google.gson.JsonObject;
14+
import material.DestinyAPI;
1415
import material.clan.Clan;
1516
import material.inventory.CollectionsManager;
1617
import material.inventory.InventoryManager;
@@ -36,7 +37,7 @@ public class BungieUser extends ContentFramework {
3637
private String bungieMembershipID, displayName, globalDisplayName, supplementalDisplayName, discriminator;
3738
private Date lastPlayed;
3839
private JsonObject je; // The JsonObject of the profile used to get most information
39-
private HttpUtils hu = new HttpUtils();
40+
private HttpUtils hu = DestinyAPI.getHttpUtils();
4041

4142
private ArrayList<Integer> applicableMembershipTypes = new ArrayList<>();
4243

@@ -125,6 +126,7 @@ public boolean isValidUser() {
125126
* Gets the display name of the user
126127
* Prefers returning the name of their account on steam, if they have one
127128
*/
129+
@Deprecated
128130
public String getDisplayName() {
129131
getJE();
130132
if (displayName == null) {
@@ -135,16 +137,17 @@ public String getDisplayName() {
135137

136138
/**
137139
* Returns the Global Display Name of the user across all Destiny Platforms
138-
* Should be used instead of getDisplayName
140+
* Should be used instead of getDisplayName()
141+
*
142+
* Please note, an empty string will be returned if a user has not logged in since the
143+
* start of Season of The Lost
139144
*/
140145
public String getGlobalDisplayName() {
141-
getJE();
142-
143146
if(globalDisplayName == null) {
144147

145148
// LinkedProfiles is not populated with bungieGlobalDisplayName as of 8/29/2021: github issue #1511
146149
// As far as I know, getSupplementalDisplayName is also the bungieGlobalDisplayName
147-
globalDisplayName = getSupplementalDisplayName().split("#")[0];
150+
globalDisplayName = getJE().get("bungieGlobalDisplayName").getAsString();
148151
}
149152

150153
return globalDisplayName;

src/main/java/material/user/DestinyCharacter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.google.gson.JsonArray;
1212
import com.google.gson.JsonElement;
1313
import com.google.gson.JsonObject;
14+
import material.DestinyAPI;
1415
import material.inventory.DestinyItem;
1516
import material.manifest.ManifestEntityTypes;
1617
import material.stats.activities.Activity;
@@ -38,7 +39,7 @@ public class DestinyCharacter extends ContentFramework {
3839

3940
private List<Activity> allActivities;
4041

41-
HttpUtils hu = new HttpUtils();
42+
HttpUtils hu = DestinyAPI.getHttpUtils();
4243

4344
public DestinyCharacter(BungieUser bungieUser, String characterID) {
4445
super("https://www.bungie.net/Platform/Destiny2/" + bungieUser.getMembershipType() + "/Profile/" + bungieUser.getBungieMembershipID() + "/Character/" + characterID + "/?components=200",
@@ -184,7 +185,7 @@ public String getEmblemHash() {
184185
* Get a list of the currently equipped items of this character
185186
*/
186187
public List<DestinyItem> getEquippedItems() {
187-
JsonArray jsonArray = new HttpUtils().urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + getMembershipType() + "/Profile/" + bungieUser.getBungieMembershipID() + "/Character/"
188+
JsonArray jsonArray = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + getMembershipType() + "/Profile/" + bungieUser.getBungieMembershipID() + "/Character/"
188189
+ getCharacterID() + "/?components=205").getAsJsonObject("Response").getAsJsonObject("equipment").getAsJsonObject("data").getAsJsonArray("items");
189190

190191
List<DestinyItem> destinyItems = new ArrayList<>();

0 commit comments

Comments
 (0)