@@ -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}
0 commit comments