From 8780a9ff227b61c169b1b6818e3c0e29886b3367 Mon Sep 17 00:00:00 2001 From: dec4234 Date: Wed, 17 Apr 2024 22:06:39 -0400 Subject: [PATCH 1/5] #22 - Add BungieResponse, additional fixes and new exception structure --- pom.xml | 2 +- .../exceptions/APIException.java | 16 ++++ .../exceptions/APIOfflineException.java | 2 +- .../AccessTokenInvalidException.java | 2 +- .../exceptions/JsonParsingError.java | 11 +++ .../javadestinyapi/utils/BungieResponse.java | 81 +++++++++++++++++++ .../javadestinyapi/utils/HttpUtils.java | 2 +- .../javadestinyapi/utils/StringUtils.java | 4 +- 8 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 src/main/java/net/dec4234/javadestinyapi/exceptions/APIException.java create mode 100644 src/main/java/net/dec4234/javadestinyapi/exceptions/JsonParsingError.java create mode 100644 src/main/java/net/dec4234/javadestinyapi/utils/BungieResponse.java diff --git a/pom.xml b/pom.xml index f247203..0df2307 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ jar JavaDestinyAPI - A Java wrapper for bungie.net platform api, allowing users to get data about the video games Destiny and Destiny 2 + A Java wrapper for bungie.net platform API, allowing users to get data about the video games Destiny and Destiny 2 https://github.com/dec4234/JavaDestinyAPI diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/APIException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/APIException.java new file mode 100644 index 0000000..02079d2 --- /dev/null +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/APIException.java @@ -0,0 +1,16 @@ +package net.dec4234.javadestinyapi.exceptions; + +/** + * Base class for all exceptions generated when an issue occurs in the request pipeline to Bungie. + * This most common reason for this error would be when the API is offline, and all objects are misparsed. + */ +public abstract class APIException extends Exception { + + public APIException() { + + } + + public APIException(String errorMessage) { + super(errorMessage); + } +} diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/APIOfflineException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/APIOfflineException.java index 54b900f..16c0d68 100644 --- a/src/main/java/net/dec4234/javadestinyapi/exceptions/APIOfflineException.java +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/APIOfflineException.java @@ -11,7 +11,7 @@ /** * Indicates that the request returned error code 5 (The API has been disabled by Bungie) */ -public class APIOfflineException extends Exception { +public class APIOfflineException extends APIException { public APIOfflineException(String returnMessage) { super("The Bungie API returned this message: " + returnMessage); diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenInvalidException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenInvalidException.java index 1bc06b9..cea5635 100644 --- a/src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenInvalidException.java +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenInvalidException.java @@ -12,7 +12,7 @@ * Thrown whenever a 401 error is detected in the HTTP response * This error indicates that the OAuth access token used by the request was not accepted by the server */ -public class AccessTokenInvalidException extends Exception { +public class AccessTokenInvalidException extends APIException { public AccessTokenInvalidException() { } diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/JsonParsingError.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/JsonParsingError.java new file mode 100644 index 0000000..bfb97d5 --- /dev/null +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/JsonParsingError.java @@ -0,0 +1,11 @@ +package net.dec4234.javadestinyapi.exceptions; + +/** + * Malformed or non-json content found where JSON was expected. Usually at an API endpoint. + */ +public class JsonParsingError extends APIException { + + public JsonParsingError(String message) { + super(message); + } +} diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/BungieResponse.java b/src/main/java/net/dec4234/javadestinyapi/utils/BungieResponse.java new file mode 100644 index 0000000..b071ac6 --- /dev/null +++ b/src/main/java/net/dec4234/javadestinyapi/utils/BungieResponse.java @@ -0,0 +1,81 @@ +package net.dec4234.javadestinyapi.utils; + +import net.dec4234.javadestinyapi.exceptions.APIException; + +/** + * Describes a response received from any HTTP request to a Bungie endpoint. This should be used to properly pass + * errors to the place where calls are made, rather than upstream in {@link HttpUtils}. The goal is to reduce runtime + * exceptions by allowing users to properly handle error conditions in their code, or optionally (poor decision) to + * ignore them. + * @param The "parsed" object that is returned by the object. This could just be a JsonObject or it could be + * an api object like {@link net.dec4234.javadestinyapi.material.user.BungieUser} + */ +public class BungieResponse { + + private T parsedResponse; + private boolean isApiOnline = true; + private APIException apiException = null; + + public BungieResponse(T parsedResponse) { + this.parsedResponse = parsedResponse; + } + + public BungieResponse(boolean isApiOnline, APIException apiException) { + this.parsedResponse = null; + this.isApiOnline = isApiOnline; + this.apiException = apiException; + } + + /** + * Get the parsed object contained witihin, but only if {@link #isError} returns false + * @return The parsed object + */ + public T getParsedResponse() { + return parsedResponse; + } + + /** + * Is the API online? + * @return Returns true if the API is online. False if the bungie api returns an error that servers are offline + */ + public boolean isApiOnline() { + return isApiOnline; + } + + /** + * Was an error returned while trying to complete the request? + * @return True if an error was returned + */ + public boolean isError() { + return apiException != null; + } + + /** + * Get the error mentioned by {@link #isError()} + * @return An ApiException representing the error received while trying to complete the request + */ + public APIException getApiException() { + return apiException; + } + + /** + * "Inherit" the errors from a predecessor. Say when taking a BungieResponse and converting it to a + * BungieUser one, you want it to carry forward any error messages. + * @param other The previous BungieResponse that is being parsed and then repackaged + * @return The BungieResponse with inherited error conditions, if there are any + */ + public BungieResponse inherit(BungieResponse other) { + if(other == null) { + return null; + } + + this.update(other.getApiException(), other.isApiOnline); + + return this; + } + + private void update(APIException exception, boolean isApiOnline) { + this.apiException = exception; + this.isApiOnline = isApiOnline; + } +} diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java b/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java index d00ffb3..d1ff8b6 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java @@ -205,7 +205,7 @@ public boolean checkFor401(String input) { } private JsonObject getJsonObject(String stringResponse) { - JsonObject jsonObject = new JsonParser().parse(stringResponse).getAsJsonObject(); + JsonObject jsonObject = new JsonParser().parse(stringResponse).getAsJsonObject(); // TODO: JsonSyntaxException here // API Offline Check if(jsonObject.has("ErrorCode") && jsonObject.get("ErrorCode").getAsInt() == 5) { diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/StringUtils.java b/src/main/java/net/dec4234/javadestinyapi/utils/StringUtils.java index 2cfe989..cd4781e 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/StringUtils.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/StringUtils.java @@ -9,6 +9,8 @@ package net.dec4234.javadestinyapi.utils; import java.io.IOException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.text.DateFormat; import java.text.DecimalFormat; import java.text.ParseException; @@ -53,7 +55,7 @@ public static double getDaysSinceTime(Date date) { * Specific characters need to be encoded in order to have a successful request */ public static String httpEncode(String input) { - return input.replace(" ", "%20").replace("#", "%23").replace("^", "%5E"); + return URLEncoder.encode(input, StandardCharsets.UTF_8); } public static void executeCommandLine(String command) { From b6aceca9df2a5dffe5364d4c85cb2351101a2308 Mon Sep 17 00:00:00 2001 From: dec4234 Date: Tue, 23 Apr 2024 11:13:26 -0400 Subject: [PATCH 2/5] #22 - Throw APIException --- .../exceptions/APIException.java | 4 + .../exceptions/ConnectionException.java | 15 ++++ .../exceptions/JsonParsingError.java | 6 ++ .../javadestinyapi/material/DestinyAPI.java | 20 ++--- .../javadestinyapi/material/clan/Clan.java | 56 ++++++------- .../material/clan/ClanManagement.java | 31 +++---- .../inventory/CollectionsManager.java | 7 +- .../material/inventory/InventoryManager.java | 3 +- .../material/inventory/items/DestinyItem.java | 30 +++---- .../inventory/items/InventoryItem.java | 16 ++-- .../material/inventory/items/ItemPerk.java | 3 +- .../material/inventory/items/ItemPlug.java | 5 +- .../material/manifest/DestinyManifest.java | 19 ++--- .../material/social/SocialFriendsList.java | 3 +- .../material/user/BungieUser.java | 49 +++++------ .../material/user/DestinyCharacter.java | 43 +++++----- .../stats/activities/Activity.java | 17 ++-- .../activities/ActivityHistoryReview.java | 17 ++-- .../stats/activities/ActivityInfo.java | 7 +- .../stats/character/UserStats.java | 5 +- .../javadestinyapi/utils/BungieResponse.java | 81 ------------------- .../javadestinyapi/utils/HttpUtils.java | 48 ++++++----- .../javadestinyapi/utils/StringUtils.java | 6 +- .../utils/framework/ContentFramework.java | 7 +- .../utils/framework/ContentInterface.java | 4 +- .../utils/framework/OAuthFlow.java | 7 +- 26 files changed, 238 insertions(+), 271 deletions(-) create mode 100644 src/main/java/net/dec4234/javadestinyapi/exceptions/ConnectionException.java delete mode 100644 src/main/java/net/dec4234/javadestinyapi/utils/BungieResponse.java diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/APIException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/APIException.java index 02079d2..3f9e21a 100644 --- a/src/main/java/net/dec4234/javadestinyapi/exceptions/APIException.java +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/APIException.java @@ -13,4 +13,8 @@ public APIException() { public APIException(String errorMessage) { super(errorMessage); } + + public APIException(Exception e) { + super(e); + } } diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/ConnectionException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/ConnectionException.java new file mode 100644 index 0000000..2857f56 --- /dev/null +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/ConnectionException.java @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + +package net.dec4234.javadestinyapi.exceptions; + +public class ConnectionException extends APIException { + + public ConnectionException(Exception exception) { + super(exception); + } +} diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/JsonParsingError.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/JsonParsingError.java index bfb97d5..b2ecfa5 100644 --- a/src/main/java/net/dec4234/javadestinyapi/exceptions/JsonParsingError.java +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/JsonParsingError.java @@ -1,5 +1,7 @@ package net.dec4234.javadestinyapi.exceptions; +import com.google.gson.JsonSyntaxException; + /** * Malformed or non-json content found where JSON was expected. Usually at an API endpoint. */ @@ -8,4 +10,8 @@ public class JsonParsingError extends APIException { public JsonParsingError(String message) { super(message); } + + public JsonParsingError(JsonSyntaxException exception) { + super(exception); + } } diff --git a/src/main/java/net/dec4234/javadestinyapi/material/DestinyAPI.java b/src/main/java/net/dec4234/javadestinyapi/material/DestinyAPI.java index a0677d5..1b63857 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/DestinyAPI.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/DestinyAPI.java @@ -11,9 +11,9 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.clan.Clan; import net.dec4234.javadestinyapi.material.user.BungieUser; -import net.dec4234.javadestinyapi.material.user.DestinyPlatform; import net.dec4234.javadestinyapi.material.user.UserCredential; import net.dec4234.javadestinyapi.material.user.UserCredentialType; import net.dec4234.javadestinyapi.responses.user.SanitizedUsernamesResponse; @@ -132,7 +132,7 @@ public static BungieUser getUser(String id) { return new BungieUser(id); } - public static SanitizedUsernamesResponse getSanitizedUsernames(String id) { + public static SanitizedUsernamesResponse getSanitizedUsernames(String id) throws APIException { return new SanitizedUsernamesResponse(httpUtils.urlRequestGET(HttpUtils.URL_BASE + "/User/GetSanitizedPlatformDisplayNames/" + id + "/").getAsJsonObject("Response")); } @@ -140,7 +140,7 @@ public static SanitizedUsernamesResponse getSanitizedUsernames(String id) { * Get a BungieUser from a Steam ID * NOT the same IDs used by Bungie to identify individual users */ - public static BungieUser getMemberFromSteamID(String steamID) { + public static BungieUser getMemberFromSteamID(String steamID) throws APIException { return getMemberFromPlatformID("SteamId", steamID); } @@ -148,7 +148,7 @@ public static BungieUser getMemberFromSteamID(String steamID) { * Used to get a BungieUser from a specified platform ID * Currently only works with Steam IDs (see getMemberFromSteamID()) */ - private static BungieUser getMemberFromPlatformID(String platformName, String platformID) { + private static BungieUser getMemberFromPlatformID(String platformName, String platformID) throws APIException { JsonObject jsonObject = getHttpUtils().urlRequestGET("https://www.bungie.net/Platform/User/GetMembershipFromHardLinkedCredential/" + platformName + "/" + platformID + "/").getAsJsonObject("Response"); return new BungieUser(jsonObject.get("membershipId").getAsString()); @@ -162,7 +162,7 @@ private static BungieUser getMemberFromPlatformID(String platformName, String pl *

* Requires OAuth */ - public static UserCredential[] getUserCredentials(BungieUser bungieUser) { + public static UserCredential[] getUserCredentials(BungieUser bungieUser) throws APIException { List list = new LinkedList<>(); for (JsonElement je : getHttpUtils().urlRequestGETOauth("https://www.bungie.net/Platform/User/GetCredentialTypesForTargetAccount/" + bungieUser.getID() + "/").getAsJsonArray("Response")) { @@ -185,7 +185,7 @@ public static UserCredential[] getUserCredentials(BungieUser bungieUser) { /** * Get a "UserCredential" from a BungieUser */ - public static UserCredential getUserCredential(UserCredentialType type, BungieUser bungieUser) { + public static UserCredential getUserCredential(UserCredentialType type, BungieUser bungieUser) throws APIException { for (UserCredential userCredential : getUserCredentials(bungieUser)) { if (userCredential.getUserCredentialType() == type) { return userCredential; @@ -207,7 +207,7 @@ public static UserCredential getUserCredential(UserCredentialType type, BungieUs * @param nameAndDiscrim A full name and discriminator such as "dec4234#9904" * @return A user with the matching name and discriminator, null otherwise */ - public static BungieUser getUserWithName(String nameAndDiscrim) { + public static BungieUser getUserWithName(String nameAndDiscrim) throws APIException { try { String[] split = nameAndDiscrim.split("#"); JsonObject jsonObject = new JsonObject(); @@ -229,7 +229,7 @@ public static BungieUser getUserWithName(String nameAndDiscrim) { * BungieUser. While searching "Gladd" or "Datto" should return * multiple. */ - public static List searchUsers(String name) { + public static List searchUsers(String name) throws APIException { List users = new ArrayList<>(); JsonObject body = new JsonObject(); @@ -274,7 +274,7 @@ public static List searchUsers(String name) { * @param jsonArray * @return */ - private static BungieUser processListOfProfiles(JsonArray jsonArray) { + private static BungieUser processListOfProfiles(JsonArray jsonArray) throws APIException { for (JsonElement jsonElement : jsonArray) { JsonObject profile = jsonElement.getAsJsonObject(); @@ -325,7 +325,7 @@ private static BungieUser processListOfProfiles(JsonArray jsonArray) { * Use searchUsers() instead */ @Deprecated - public static List searchGlobalDisplayNames(String prefix) { + public static List searchGlobalDisplayNames(String prefix) throws APIException { prefix = StringUtils.httpEncode(prefix); List bungieUsers = new ArrayList<>(); diff --git a/src/main/java/net/dec4234/javadestinyapi/material/clan/Clan.java b/src/main/java/net/dec4234/javadestinyapi/material/clan/Clan.java index f492b0f..f1a09cd 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/clan/Clan.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/clan/Clan.java @@ -11,17 +11,19 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; -import net.dec4234.javadestinyapi.stats.activities.ActivityMode; import net.dec4234.javadestinyapi.material.user.BungieUser; -import net.dec4234.javadestinyapi.material.user.DestinyPlatform; +import net.dec4234.javadestinyapi.stats.activities.ActivityMode; import net.dec4234.javadestinyapi.utils.HttpUtils; import net.dec4234.javadestinyapi.utils.StringUtils; import net.dec4234.javadestinyapi.utils.framework.ContentFramework; -import java.util.*; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.LinkedList; +import java.util.List; public class Clan extends ContentFramework { @@ -62,46 +64,46 @@ public Clan(long clanId, String clanName) { this.clanName = clanName; } - public String getClanID() { + public String getClanID() throws APIException { if (clanId == -1) { clanId = getDetail().get("groupId").getAsLong(); } return clanId + ""; } - public String getClanName() { + public String getClanName() throws APIException { if (clanName == null) { clanName = getJO().getAsJsonObject("detail").get("name").getAsString(); } return clanName; } - public String getClanDescription() { + public String getClanDescription() throws APIException { if (clanDescription == null) { clanDescription = getDetail().get("about").getAsString(); } return clanDescription; } - public Date getCreationDate() { + public Date getCreationDate() throws APIException { if (creationDate == null) { creationDate = StringUtils.valueOfZTime(getDetail().get("creationDate").getAsString()); } return creationDate; } - public int getMemberCount() { + public int getMemberCount() throws APIException { if (memberCount == -1) { memberCount = getDetail().get("memberCount").getAsInt(); } return memberCount; } - public boolean isPublic() { + public boolean isPublic() throws APIException { return getDetail().get("isPublic").getAsBoolean(); } - public String getMotto() { + public String getMotto() throws APIException { if (motto == null) { motto = getDetail().get("motto").getAsString(); } @@ -111,14 +113,14 @@ public String getMotto() { /** * Get if this clan allows chat. I think this refers to the Bungie.net clan chat page */ - public boolean isAllowChat() { + public boolean isAllowChat() throws APIException { return getDetail().get("allowChat").getAsBoolean(); } /** * Get the founder of the clan */ - public BungieUser getFounder() { + public BungieUser getFounder() throws APIException { return new BungieUser(getJO().getAsJsonObject("founder").getAsJsonObject("destinyUserInfo").get("membershipId").getAsString()); } @@ -127,7 +129,7 @@ public BungieUser getFounder() { * The founder is always the first in this list? * Followed by the admins in the order they were promoted */ - public List getAdmins() { + public List getAdmins() throws APIException { if (admins != null) { return admins; } @@ -148,7 +150,7 @@ public List getAdmins() { * * Thanks to the ClanMember system, requires very little calls and should be pretty fast. */ - public double getAverageInactivityAmongMembers() { + public double getAverageInactivityAmongMembers() throws APIException { ArrayList averages = new ArrayList<>(); int a = 0; for (ClanMember clanMember : this.getMembers()) { @@ -163,7 +165,7 @@ public double getAverageInactivityAmongMembers() { /** * Get the most inactive members of a clan, using the getMembers() endpoint and the ClanMember class */ - public List getMostInactiveMembers(int numberOfResults, String... exclude) { + public List getMostInactiveMembers(int numberOfResults, String... exclude) throws APIException { List list = getMembers(); List excluded = Arrays.asList(exclude); List toReturn = new LinkedList<>(); @@ -190,7 +192,7 @@ public List getMostInactiveMembers(int numberOfResults, String... ex * * TO-DO: Maybe switch this to the search part of the /Members/ endpoint? */ - public List searchMembers(String name) { + public List searchMembers(String name) throws APIException { List list = new LinkedList<>(); for (BungieUser bungieUser : getMembers()) { @@ -208,7 +210,7 @@ public List searchMembers(String name) { * * @return A list of all online members of the clan */ - public List getOnlineMembers() { + public List getOnlineMembers() throws APIException { List toReturn = new ArrayList<>(); for(ClanMember clanMember : getMembers()) { @@ -225,7 +227,7 @@ public List getOnlineMembers() { * * @return The userIds belonging to the members of this clan */ - public List getMembersIDs() { + public List getMembersIDs() throws APIException { List toReturn = new ArrayList<>(); for (BungieUser bungieUser : getMembers()) { @@ -239,7 +241,7 @@ public List getMembersIDs() { * Get the members of this clan * @return A List of ClanMember */ - public List getMembers() { + public List getMembers() throws APIException { List clanMembers = new ArrayList<>(); JsonObject response = hu.urlRequestGET("https://www.bungie.net/Platform/GroupV2/" + getClanID() + "/Members/").get("Response").getAsJsonObject(); @@ -256,7 +258,7 @@ public List getMembers() { * @param amount The amount of members to return * @return A sorted list of the oldest members of this clan */ - public List getOldestMembers(int amount) { + public List getOldestMembers(int amount) throws APIException { List members = getMembers(); List sorted = new LinkedList<>(); @@ -285,14 +287,14 @@ public List getOldestMembers(int amount) { /** * Returns if this BungieUser is a member of the clan */ - public boolean isMember(BungieUser bungieUser) { + public boolean isMember(BungieUser bungieUser) throws APIException { return isMember(bungieUser.getID()); } /** * Checks if the member with the provided id is a member of the clan */ - public boolean isMember(String bungieID) { + public boolean isMember(String bungieID) throws APIException { for (BungieUser bungieUser : getMembers()) { if (bungieUser.getID().equals(bungieID)) { return true; @@ -306,7 +308,7 @@ public boolean isMember(String bungieID) { * Retrieve a JsonObject depicting the top stats of the clan * Unfortunately does not say who has those top stats */ - public JsonObject getClanStats(ActivityMode... filter) { + public JsonObject getClanStats(ActivityMode... filter) throws APIException { String queryString = "/?modes="; for (ActivityMode activityMode : filter) { queryString = queryString.concat(activityMode.getBungieValue() + ","); @@ -321,7 +323,7 @@ public JsonObject getClanStats(ActivityMode... filter) { * * @return The Date this user joined the clan or null if that user was not found */ - public Date getJoinDate(BungieUser member) { + public Date getJoinDate(BungieUser member) throws APIException { if (jj == null) { jj = hu.urlRequestGET("https://www.bungie.net/Platform/GroupV2/" + getClanID() + "/Members/").get("Response").getAsJsonObject(); } @@ -346,7 +348,7 @@ public ClanManagement getClanManagement() { return clanManagement; } - private JsonObject getDetail() { + private JsonObject getDetail() throws APIException { return getJO().getAsJsonObject("detail"); } } diff --git a/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanManagement.java b/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanManagement.java index 1518307..cbd520c 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanManagement.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanManagement.java @@ -11,6 +11,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.user.BungieUser; import net.dec4234.javadestinyapi.utils.HttpUtils; @@ -38,56 +39,56 @@ public ClanManagement(Clan clan) { /** * Kicks this user from the clan */ - public void kickPlayer(BungieUser bungieUser) { + public void kickPlayer(BungieUser bungieUser) throws APIException { hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/Kick/", ""); } /** * Bans the user from the clan */ - public void banUser(BungieUser bungieUser) { + public void banUser(BungieUser bungieUser) throws APIException { hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/Ban/", ""); } /** * Unbans this user from the clan, as long as they are banned, of course */ - public void unbanUser(BungieUser bungieUser) { + public void unbanUser(BungieUser bungieUser) throws APIException { hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/Unban/", ""); } /** * Invites the specified user to join the clan */ - public void inviteUser(BungieUser bungieUser) { + public void inviteUser(BungieUser bungieUser) throws APIException { hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/IndividualInvite/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/", ""); } /** * Cancels the invite for this user to join the clan */ - public void cancelInvite(BungieUser bungieUser) { + public void cancelInvite(BungieUser bungieUser) throws APIException { hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/IndividualInviteCancel/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/", ""); } /** * Approves this user's request to join the clan if and only if they have requested to join */ - public void approvePendingMember(BungieUser bungieUser) { + public void approvePendingMember(BungieUser bungieUser) throws APIException { hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Approve/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/", ""); } /** * Approves all requests to join the clan */ - public void approveAllPendingMembers() { + public void approveAllPendingMembers() throws APIException { hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/ApproveAll/", ""); } /** * Denies all pending requests to join the clan :) */ - public void denyAllPendingMembers() { + public void denyAllPendingMembers() throws APIException { hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/DenyAll/?components=200", ""); } @@ -96,7 +97,7 @@ public void denyAllPendingMembers() { * * @param bungieUser The user who will be the new founder (leader) of the clan */ - public void abdicateFoundership(BungieUser bungieUser) { + public void abdicateFoundership(BungieUser bungieUser) throws APIException { hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Admin/AbdicateFoundership/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/", ""); } @@ -106,7 +107,7 @@ public void abdicateFoundership(BungieUser bungieUser) { * @param chatName The name of the chat * @param clanChatSecuritySetting The security setting of the chat */ - public void addOptionalConversation(String chatName, ClanChatSecuritySetting clanChatSecuritySetting) { + public void addOptionalConversation(String chatName, ClanChatSecuritySetting clanChatSecuritySetting) throws APIException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("chatName", chatName); jsonObject.addProperty("chatSecurity", clanChatSecuritySetting.getSetting()); @@ -122,7 +123,7 @@ public void addOptionalConversation(String chatName, ClanChatSecuritySetting cla * @param chatName The name of the chat * @param clanChatSecuritySetting The security setting of the chat */ - public void editOptionalConversation(String conversationID, boolean chatEnabled, String chatName, ClanChatSecuritySetting clanChatSecuritySetting) { + public void editOptionalConversation(String conversationID, boolean chatEnabled, String chatName, ClanChatSecuritySetting clanChatSecuritySetting) throws APIException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("chatName", chatName); jsonObject.addProperty("chatSecurity", clanChatSecuritySetting.getSetting()); @@ -136,7 +137,7 @@ public void editOptionalConversation(String conversationID, boolean chatEnabled, * * @return The list of banned users */ - public List getBannedMembers() { + public List getBannedMembers() throws APIException { if (bannedMembers != null) { return bannedMembers; } List temp = new ArrayList<>(); @@ -151,7 +152,7 @@ public List getBannedMembers() { /** * Returns a list of pending members to the clan, Never cached: always makes a new request */ - public List getPendingMembers() { + public List getPendingMembers() throws APIException { List temp = new ArrayList<>(); JsonArray ja = hu.urlRequestGETOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Pending/?components=200").get("Response").getAsJsonObject().get("results").getAsJsonArray(); @@ -169,7 +170,7 @@ public List getPendingMembers() { * * @return The list of invited users */ - public List getInvitedMembers() { + public List getInvitedMembers() throws APIException { List temp = new ArrayList<>(); JsonArray ja = hu.urlRequestGETOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Invited/?components=200").getAsJsonObject("Response").getAsJsonArray("results"); @@ -184,7 +185,7 @@ public List getInvitedMembers() { /** * Check if a BungieUser is a pending applicant without the performance overhead of creating multiple BungieUsers */ - public boolean isPendingMember(BungieUser bungieUser) { + public boolean isPendingMember(BungieUser bungieUser) throws APIException { JsonArray ja = hu.urlRequestGETOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Pending/?components=200").get("Response").getAsJsonObject().get("results").getAsJsonArray(); for(JsonElement jsonElement : ja) { diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/CollectionsManager.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/CollectionsManager.java index b4786f4..ba56fd9 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/CollectionsManager.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/CollectionsManager.java @@ -8,6 +8,7 @@ package net.dec4234.javadestinyapi.material.inventory; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.inventory.items.DestinyItem; import net.dec4234.javadestinyapi.material.user.BungieUser; import net.dec4234.javadestinyapi.utils.framework.ContentFramework; @@ -16,14 +17,14 @@ public class CollectionsManager extends ContentFramework { private BungieUser bungieUser; - public CollectionsManager(BungieUser bungieUser) { + public CollectionsManager(BungieUser bungieUser) throws APIException { super("https://www.bungie.net/Platform/Destiny2/" + bungieUser.getMembershipType() + "/Profile/" + bungieUser.getID() + "/?components=800", source -> { return source.getAsJsonObject("Response"); }); this.bungieUser = bungieUser; } - public boolean hasCollectedItem(String collectibleHash) { + public boolean hasCollectedItem(String collectibleHash) throws APIException { try { return getJO().getAsJsonObject("profileCollectibles").getAsJsonObject("data").getAsJsonObject("collectibles").getAsJsonObject(collectibleHash).get("state").getAsInt() == 0; } catch (NullPointerException e) { @@ -31,7 +32,7 @@ public boolean hasCollectedItem(String collectibleHash) { } } - public boolean hasCollectedItem(DestinyItem destinyItem) { + public boolean hasCollectedItem(DestinyItem destinyItem) throws APIException { try { return getJO().getAsJsonObject("profileCollectibles").getAsJsonObject("data").getAsJsonObject("collectibles").getAsJsonObject(destinyItem.getCollectibleHash()).get("state").getAsInt() == 0; } catch (NullPointerException e) { diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/InventoryManager.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/InventoryManager.java index 9d48fcd..54e651f 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/InventoryManager.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/InventoryManager.java @@ -8,6 +8,7 @@ package net.dec4234.javadestinyapi.material.inventory; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.user.BungieUser; import net.dec4234.javadestinyapi.material.user.DestinyCharacter; @@ -25,7 +26,7 @@ public InventoryManager(BungieUser bungieUser) { this.bungieUser = bungieUser; } - public DestinyCharacter getCharacterOfType(DestinyCharacter.DestinyClass destinyClass) { + public DestinyCharacter getCharacterOfType(DestinyCharacter.DestinyClass destinyClass) throws APIException { return bungieUser.getCharacterOfType(destinyClass); } diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/DestinyItem.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/DestinyItem.java index 5aa7688..596a735 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/DestinyItem.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/DestinyItem.java @@ -10,10 +10,12 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.manifest.DestinyManifest; import net.dec4234.javadestinyapi.material.manifest.ManifestEntityTypes; import net.dec4234.javadestinyapi.utils.HttpUtils; +import net.dec4234.javadestinyapi.utils.StringUtils; import net.dec4234.javadestinyapi.utils.framework.ContentInterface; import java.util.ArrayList; @@ -46,7 +48,7 @@ public DestinyItem(String hashID, String name, String icon, boolean hasIcon) { this.hasIcon = hasIcon; } - public String getHashID() { + public String getHashID() throws APIException { if(hashID == null) { checkJO(); hashID = jo.get("hash").getAsString(); @@ -54,14 +56,14 @@ public String getHashID() { return hashID; } - public int getHashIDasInt() { + public int getHashIDasInt() throws APIException { return Integer.parseInt(getHashID()); } /** * Gets the name of the item */ - public String getName() { + public String getName() throws APIException { if(name == null) { checkDP(); name = dp.get("name").getAsString(); @@ -72,7 +74,7 @@ public String getName() { /** * Plug this after https://www.bungie.net/ in a browser */ - public String getIcon() { + public String getIcon() throws APIException { if(icon == null) { checkDP(); icon = dp.get("icon").getAsString(); @@ -83,7 +85,7 @@ public String getIcon() { /** * Gets the lore descriptions associated with this item */ - public String getDescription() { + public String getDescription() throws APIException { if(description == null) { checkDP(); description = dp.get("description").getAsString(); @@ -91,13 +93,13 @@ public String getDescription() { return description; } - public boolean hasIcon() { + public boolean hasIcon() throws APIException { checkDP(); hasIcon = dp.get("hasIcon").getAsBoolean(); return hasIcon; } - public String getCollectibleHash() { + public String getCollectibleHash() throws APIException { checkJO(); if(jo.has("collectibleHash")) { collectibleHash = jo.get("collectibleHash").getAsString(); @@ -106,7 +108,7 @@ public String getCollectibleHash() { return collectibleHash; } - public String getScreenshot() { + public String getScreenshot() throws APIException { checkJO(); if(jo.has("screenshot") && screenshot == null) { screenshot = jo.get("screenshot").getAsString(); @@ -115,14 +117,14 @@ public String getScreenshot() { return screenshot; } - public ItemTier getItemTier() { + public ItemTier getItemTier() throws APIException { if(itemTier == null) { itemTier = assessItemTier(); } return itemTier; } - private ItemTier assessItemTier() { + private ItemTier assessItemTier() throws APIException { checkJO(); switch(jo.getAsJsonObject("inventory").get("tierTypeName").getAsString()) { case "Common": @@ -140,14 +142,14 @@ private ItemTier assessItemTier() { } @Override - public void checkJO() { + public void checkJO() throws APIException { if(jo == null) { jo = new DestinyManifest().manifestGET(ManifestEntityTypes.INVENTORYITEM, hashID); // jo = hu.manifestGET(ManifestEntityTypes.INVENTORYITEM, hashID).getAsJsonObject("Response"); } } - public void checkDP() { + public void checkDP() throws APIException { if(dp == null) { checkJO(); dp = jo.getAsJsonObject("displayProperties"); @@ -165,10 +167,10 @@ public enum ItemTier { /** * Return a list of all items that contain or match the name provided */ - public static List searchForItems(String itemName) { + public static List searchForItems(String itemName) throws APIException { HttpUtils httpUtils = DestinyAPI.getHttpUtils(); List destinyItemList = new ArrayList<>(); - itemName = itemName.replace(" ", "%20"); + itemName = StringUtils.httpEncode(itemName); for(JsonElement jsonElement : httpUtils.urlRequestGET("https://www.bungie.net/Platform/Destiny2/Armory/Search/DestinyInventoryItemDefinition/" + itemName + "/").getAsJsonObject("Response").getAsJsonObject("results").getAsJsonArray("results")) { JsonObject jsonObject = jsonElement.getAsJsonObject(); diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryItem.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryItem.java index 5b797cb..dedb985 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryItem.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryItem.java @@ -10,8 +10,8 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; -import net.dec4234.javadestinyapi.material.inventory.items.DestinyItem; import net.dec4234.javadestinyapi.material.user.DestinyCharacter; import net.dec4234.javadestinyapi.utils.HttpUtils; @@ -31,7 +31,7 @@ public class InventoryItem extends DestinyItem { private int quantity, bindStatus, location, transferStatus, state, dismantlePermission; private boolean lockable = false, isWrapper; - public InventoryItem(String instanceId, DestinyCharacter characterOwner) { + public InventoryItem(String instanceId, DestinyCharacter characterOwner) throws APIException { this(httpUtils.urlRequestGET(HttpUtils.URL_BASE + "/Destiny2/" + characterOwner.getMembershipType() + "/Profile/" + characterOwner.getMembershipID() + "/Item/" + instanceId + "/?components=305").getAsJsonObject("Response").getAsJsonObject("item").getAsJsonObject("data")); this.characterOwner = characterOwner; @@ -99,7 +99,7 @@ private InventoryItem(JsonObject jsonObject) { * * @return Returns a list of ItemPlugs */ - public List getItemPlugs() { + public List getItemPlugs() throws APIException { JsonObject jsonObject = httpUtils.urlRequestGET(HttpUtils.URL_BASE + "/Destiny2/" + characterOwner.getMembershipType() + "/Profile/" + characterOwner.getMembershipID() + "/Item/" + instanceId + "/?components=305"); List itemPlugs = new ArrayList<>(); jsonObject = jsonObject.getAsJsonObject("Response").getAsJsonObject("sockets").getAsJsonObject("data"); @@ -117,7 +117,7 @@ public List getItemPlugs() { * * @return Returns true if the move was succesful */ - public boolean moveTo(DestinyCharacter destinyCharacter) { + public boolean moveTo(DestinyCharacter destinyCharacter) throws APIException { if(!isInVault()) { moveToVault(); } @@ -138,7 +138,7 @@ public boolean moveTo(DestinyCharacter destinyCharacter) { * * @return True if the move was reported as succesful */ - public boolean moveToVault() { + public boolean moveToVault() throws APIException { JsonObject jsonObject = httpUtils.urlRequestPOSTOauth(HttpUtils.URL_BASE + "/Destiny2/Actions/Items/TransferItem/", prepareJsonObject(getCharacterOwner(), true, isItemEquippable())); boolean wasSuccesful = wasTransferSuccesful(jsonObject); @@ -159,7 +159,7 @@ public boolean moveToVault() { * * @return Returns whether or not the action was succesful */ - public boolean equip() { + public boolean equip() throws APIException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("itemId", getInstanceIDAsLong()); jsonObject.addProperty("characterId", getCharacterOwner().getCharacterIDAsLong()); @@ -195,7 +195,7 @@ public boolean isItemEquippable() { * Lock or unlock an item * @param state The state of the lock the item should be set to */ - public void setLockState(boolean state) { + public void setLockState(boolean state) throws APIException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("state", state); jsonObject.addProperty("itemId", getInstanceId()); @@ -285,7 +285,7 @@ public boolean isWrapper() { /** * Prepares a POST body for item transferring */ - private JsonObject prepareJsonObject(DestinyCharacter destinyCharacter, boolean moveToVault, boolean isEquippable) { + private JsonObject prepareJsonObject(DestinyCharacter destinyCharacter, boolean moveToVault, boolean isEquippable) throws APIException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("itemReferenceHash", getHashIDasInt()); jsonObject.addProperty("stackSize", isEquippable ? 1 : getQuantity()); // If the item is equippable, set stack size as 1 diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPerk.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPerk.java index 43bf65a..6f34b9f 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPerk.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPerk.java @@ -1,6 +1,7 @@ package net.dec4234.javadestinyapi.material.inventory.items; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.manifest.DestinyManifest; import net.dec4234.javadestinyapi.material.manifest.ManifestEntityTypes; @@ -11,7 +12,7 @@ public class ItemPerk { private int perkVisibility; private boolean isActive, visible; - public ItemPerk(String perkHash) { + public ItemPerk(String perkHash) throws APIException { this(new DestinyManifest().manifestGET(ManifestEntityTypes.INVENTORYITEM, perkHash)); } diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPlug.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPlug.java index 42258fa..dddcc8d 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPlug.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPlug.java @@ -1,6 +1,7 @@ package net.dec4234.javadestinyapi.material.inventory.items; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.manifest.DestinyManifest; import net.dec4234.javadestinyapi.material.manifest.ManifestEntityTypes; import org.jetbrains.annotations.NotNull; @@ -31,11 +32,11 @@ public class ItemPlug { private boolean onActionRecreateSelf, isDummyPlug, applyStatsToSocketOwnerItem; private int plugStyle, plugAvailibility, alternatePlugStyle; - public ItemPlug(@NotNull String hash) { + public ItemPlug(@NotNull String hash) throws APIException { this(new DestinyManifest().manifestGET(ManifestEntityTypes.INVENTORYITEM, hash)); } - public ItemPlug(@NotNull String hash, boolean isEnabled, boolean isVisible) { + public ItemPlug(@NotNull String hash, boolean isEnabled, boolean isVisible) throws APIException { this(hash); this.isEnabled = isEnabled; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/manifest/DestinyManifest.java b/src/main/java/net/dec4234/javadestinyapi/material/manifest/DestinyManifest.java index b9a1edc..5576e7b 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/manifest/DestinyManifest.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/manifest/DestinyManifest.java @@ -9,6 +9,7 @@ package net.dec4234.javadestinyapi.material.manifest; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.utils.framework.ContentFramework; @@ -36,7 +37,7 @@ public DestinyManifest() { * * It'll download the entire definition library the first time and it'll cache it */ - public JsonObject manifestGET(ManifestEntityTypes manifestEntityTypes, String hash) { + public JsonObject manifestGET(ManifestEntityTypes manifestEntityTypes, String hash) throws APIException { JsonObject jsonObject = getDefinitionLibrary(manifestEntityTypes); if(jsonObject.has(hash)) { @@ -50,36 +51,36 @@ public JsonObject manifestGET(ManifestEntityTypes manifestEntityTypes, String ha * Get the current version of the manifest * Useful for checking for updates */ - public String getVersion() { + public String getVersion() throws APIException { return getJO().get("version").getAsString(); } - public String getMobileAssetContentPath() { + public String getMobileAssetContentPath() throws APIException { return getJO().get("mobileAssetContentPath").getAsString(); } - public String getMobileWorldContentPath(Language language) { + public String getMobileWorldContentPath(Language language) throws APIException { return getJO().getAsJsonObject("mobileWorldContentPaths").get(language.getCode()).getAsString(); } - public String getJsonWorldContentPath(Language language) { + public String getJsonWorldContentPath(Language language) throws APIException { return getJO().getAsJsonObject("jsonWorldContentPaths").get(language.getCode()).getAsString(); } - public JsonObject getWorldContent(Language language) { + public JsonObject getWorldContent(Language language) throws APIException { return DestinyAPI.getHttpUtils().urlRequestGET("https://www.bungie.net" + getJsonWorldContentPath(language)); } /** * Get the entirety of the specified definition library */ - public JsonObject getDefinitionLibrary(ManifestEntityTypes manifestEntityTypes) { + public JsonObject getDefinitionLibrary(ManifestEntityTypes manifestEntityTypes) throws APIException { Language language = Language.ENGLISH; return getDefinitionLibrary(language, manifestEntityTypes); } - public JsonObject getDefinitionLibrary(Language language, ManifestEntityTypes manifestEntityTypes) { + public JsonObject getDefinitionLibrary(Language language, ManifestEntityTypes manifestEntityTypes) throws APIException { if(!worldComponents.containsKey(manifestEntityTypes.getBungieEntityValue())) { worldComponents.put(manifestEntityTypes.getBungieEntityValue(), DestinyAPI.getHttpUtils().urlRequestGET("https://www.bungie.net" + getJO().getAsJsonObject("jsonWorldComponentContentPaths").getAsJsonObject(language.getCode()).get(manifestEntityTypes.getBungieEntityValue()).getAsString())); } @@ -87,7 +88,7 @@ public JsonObject getDefinitionLibrary(Language language, ManifestEntityTypes ma return worldComponents.get(manifestEntityTypes.getBungieEntityValue()); } - public String getMobileClanBannerDatabasePath() { + public String getMobileClanBannerDatabasePath() throws APIException { return getJO().get("mobileClanBannerDatabasePath").getAsString(); } diff --git a/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriendsList.java b/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriendsList.java index 77e9fda..805ce3f 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriendsList.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriendsList.java @@ -2,6 +2,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import java.util.ArrayList; @@ -11,7 +12,7 @@ public class SocialFriendsList { - public List getFriendsList() { + public List getFriendsList() throws APIException { List list = new ArrayList<>(); JsonObject jo = DestinyAPI.getHttpUtils().urlRequestGETOauth(URL_BASE + "/Social/Friends/"); diff --git a/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java b/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java index 789511f..a5a9256 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java @@ -11,6 +11,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.clan.Clan; import net.dec4234.javadestinyapi.material.inventory.CollectionsManager; @@ -127,7 +128,7 @@ public BungieUser(String bungieMembershipID, String displayName, String globalDi * Determines if the user has any profiles on their account * Useful to see if a user's account has any data on it */ - public boolean isValidUser() { + public boolean isValidUser() throws APIException { try { return getJO().getAsJsonArray("profiles").size() != 0; } catch (NullPointerException nullPointerException) { @@ -142,7 +143,7 @@ public boolean isValidUser() { * Deprecated in favor of getGlobalDisplayName() */ @Deprecated - public String getDisplayName() { + public String getDisplayName() throws APIException { getJE(); if (displayName == null) { displayName = getJE().get("displayName").getAsString(); @@ -156,7 +157,7 @@ public String getDisplayName() { * Please note, an empty string will be returned if a user has not logged in since the * start of Season of The Lost */ - public String getGlobalDisplayName() { + public String getGlobalDisplayName() throws APIException { if (globalDisplayName == null) { // LinkedProfiles is not populated with bungieGlobalDisplayName as of 8/29/2021: github issue #1511 @@ -171,7 +172,7 @@ public String getGlobalDisplayName() { * Returns the combined displayname and user discriminator as used in friend requests and user searches * E.g. dec4234#9904 */ - public String getSupplementalDisplayName() { + public String getSupplementalDisplayName() throws APIException { if (supplementalDisplayName == null) { supplementalDisplayName = getJO().getAsJsonObject("bnetMembership").get("supplementalDisplayName").getAsString(); } @@ -183,7 +184,7 @@ public String getSupplementalDisplayName() { * Get the discriminator of a user's name * E.g. "9904" of dec4234#9904 */ - public String getDiscriminator() { + public String getDiscriminator() throws APIException { if (discriminator == null) { discriminator = getSupplementalDisplayName().split("#")[1]; } @@ -194,7 +195,7 @@ public String getDiscriminator() { /** * Gets the last day this user was seen online */ - public Date getLastPlayed() { + public Date getLastPlayed() throws APIException { if (lastPlayed == null) { lastPlayed = StringUtils.valueOfZTime(getJE().get("dateLastPlayed").getAsString()); } @@ -205,27 +206,27 @@ public Date getLastPlayed() { /** * Gets a double representing the number of days since the user last played */ - public double getDaysSinceLastPlayed() { + public double getDaysSinceLastPlayed() throws APIException { DecimalFormat df = new DecimalFormat("0.##"); return Double.parseDouble(df.format((new Date().getTime() - getLastPlayed().getTime()) / 1000.0 / 60.0 / 60.0 / 24.0)); } - public boolean isOverridden() { + public boolean isOverridden() throws APIException { return !isOverridden ? isOverridden = getJE().get("isOverridden").getAsBoolean() : isOverridden; } - public boolean isCrossSavePrimary() { + public boolean isCrossSavePrimary() throws APIException { return !isCrossSavePrimary ? isCrossSavePrimary = getJE().get("isCrossSavePrimary").getAsBoolean() : isCrossSavePrimary; } - public int getCrossSaveOverride() { + public int getCrossSaveOverride() throws APIException { return crossSaveOverride == -1 ? crossSaveOverride = getJE().get("crossSaveOverride").getAsInt() : crossSaveOverride; } /** * Get the applicable membership types declared in the response */ - public ArrayList getApplicableMembershipTypes() { + public ArrayList getApplicableMembershipTypes() throws APIException { if (applicableMembershipTypes.isEmpty()) { for (JsonElement jj : getJE().get("applicableMembershipTypes").getAsJsonArray()) { applicableMembershipTypes.add(jj.getAsInt()); @@ -237,7 +238,7 @@ public ArrayList getApplicableMembershipTypes() { /** * Get all membership types declared under this account's profiles */ - public ArrayList getMembershipTypes() { + public ArrayList getMembershipTypes() throws APIException { ArrayList integers = new ArrayList<>(); for (JsonElement jsonElement : getJO().get("profiles").getAsJsonArray()) { @@ -247,14 +248,14 @@ public ArrayList getMembershipTypes() { return integers; } - public boolean isPublic() { + public boolean isPublic() throws APIException { return !isPublic ? isPublic = getJE().get("isPublic").getAsBoolean() : isPublic; } /** * Returns the membership type of the main profile */ - public int getMembershipType() { + public int getMembershipType() throws APIException { return membershipType == -1 ? membershipType = getJE().get("membershipType").getAsInt() : membershipType; } @@ -263,7 +264,7 @@ public int getMembershipType() { * * @return The list of characters associated with this account, or null if none are found */ - public List getCharacters() { + public List getCharacters() throws APIException { if (destinyCharacters != null) { return destinyCharacters; } destinyCharacters = new ArrayList<>(); JsonObject jsonObject = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + getMembershipType() + "/Profile/" + getID() + "/?components=Profiles,Characters").getAsJsonObject("Response"); @@ -290,7 +291,7 @@ public List getCharacters() { * @param destinyClass * @return The character if there is one, and is not a duplicate */ - public DestinyCharacter getCharacterOfType(DestinyCharacter.DestinyClass destinyClass) { + public DestinyCharacter getCharacterOfType(DestinyCharacter.DestinyClass destinyClass) throws APIException { DestinyCharacter toReturn = null; for (DestinyCharacter destinyCharacter : this.getCharacters()) { @@ -311,7 +312,7 @@ public DestinyCharacter getCharacterOfType(DestinyCharacter.DestinyClass destiny * * @return The time played of this user, in minutes */ - public int getTimePlayed() { + public int getTimePlayed() throws APIException { if (playTime != -1) { return playTime; } for (DestinyCharacter c : getCharacters()) { playTime += Integer.parseInt(c.getMinutesPlayedTotal()); @@ -322,7 +323,7 @@ public int getTimePlayed() { /** * Gets the clan that this user is a member of */ - public Clan getClan() { + public Clan getClan() throws APIException { if (clan != null) { return clan; } JsonObject jo2 = hu.urlRequestGET("https://www.bungie.net/Platform/GroupV2/User/" + getMembershipType() + "/" + getID() + "/0/1/?components=200").getAsJsonObject("Response"); @@ -335,7 +336,7 @@ public Clan getClan() { * If the user is currently in a clan * @return Returns true if the user is a member of a clan */ - public boolean isAMemberOfAClan() { + public boolean isAMemberOfAClan() throws APIException { return getClan() != null; } @@ -352,7 +353,7 @@ public void allowClanInvites(boolean allowInvites) { * Determines if the user is online * @return Returns true if the user is online */ - public boolean isOnline() { + public boolean isOnline() throws APIException { for(DestinyCharacter destinyCharacter : getCharacters()) { if(destinyCharacter.getLastPlayed().getTime() + ((long) destinyCharacter.getMinutesPlayedThisSession() * 60 * 1000) + (10 * 1000) > System.currentTimeMillis()) { return true; @@ -368,7 +369,7 @@ public boolean isOnline() { * * @return Null if no information about the current activity is found */ - public ActivityInfo getCurrentActivityInfo() { + public ActivityInfo getCurrentActivityInfo() throws APIException { JsonObject data = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + getMembershipType() + "/Profile/" + getID() + "/?components=204").getAsJsonObject("Response").getAsJsonObject("characterActivities").getAsJsonObject("data"); for (DestinyCharacter character : getCharacters()) { @@ -386,7 +387,7 @@ public ActivityInfo getCurrentActivityInfo() { /** * Request to join the specified clan */ - public void requestToJoinClan(Clan clan) { + public void requestToJoinClan(Clan clan) throws APIException { hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Apply/" + getMembershipType() + "/", ""); } @@ -395,7 +396,7 @@ public void requestToJoinClan(Clan clan) { * Uses the preferred platform profile if it has been declared or * it will select the first profile in the profiles array */ - public JsonObject getJE() { + public JsonObject getJE() throws APIException { if (je == null) { if (intendedPlatform != -2) { for (JsonElement jsonElement : getJO().getAsJsonArray("profiles")) { @@ -455,7 +456,7 @@ public InventoryManager getInventoryManager() { return inventoryManager; } - public CollectionsManager getCollectionsManager() { + public CollectionsManager getCollectionsManager() throws APIException { if (collectionsManager == null) { collectionsManager = new CollectionsManager(this); } diff --git a/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyCharacter.java b/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyCharacter.java index 0d20c4b..4c6b601 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyCharacter.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyCharacter.java @@ -11,6 +11,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.inventory.items.DestinyItem; import net.dec4234.javadestinyapi.material.inventory.items.InventoryItem; @@ -43,7 +44,7 @@ public class DestinyCharacter extends ContentFramework { HttpUtils hu = DestinyAPI.getHttpUtils(); - public DestinyCharacter(BungieUser bungieUser, String characterID) { + public DestinyCharacter(BungieUser bungieUser, String characterID) throws APIException { super("https://www.bungie.net/Platform/Destiny2/" + bungieUser.getMembershipType() + "/Profile/" + bungieUser.getID() + "/Character/" + characterID + "/?components=200", source -> source.getAsJsonObject("Response").getAsJsonObject("character").getAsJsonObject("data")); this.characterID = characterID; @@ -67,7 +68,7 @@ public String getMembershipID() { /** * Get the membershipType of the account that owns this character */ - public int getMembershipType() { + public int getMembershipType() throws APIException { return bungieUser.getMembershipType(); } @@ -89,7 +90,7 @@ public int getMembershipType() { /** * Get the Date that this character was last played */ - public Date getLastPlayed() { + public Date getLastPlayed() throws APIException { if (lastPlayed == null) { lastPlayed = StringUtils.valueOfZTime(getJO().get("dateLastPlayed").getAsString()); } @@ -100,7 +101,7 @@ public Date getLastPlayed() { * Get the total amount of time, in minutes, that this character has been played in this session * TO-DO: Define what a "session" is */ - public int getMinutesPlayedThisSession() { + public int getMinutesPlayedThisSession() throws APIException { if (minutesPlayedThisSession == -1) { minutesPlayedThisSession = getJO().get("minutesPlayedThisSession").getAsInt(); } @@ -110,7 +111,7 @@ public int getMinutesPlayedThisSession() { /** * Get the total amount of time, in minutes, that has been played on this character */ - public String getMinutesPlayedTotal() { + public String getMinutesPlayedTotal() throws APIException { if (minutesPlayedTotal == null) { minutesPlayedTotal = getJO().get("minutesPlayedTotal").getAsString(); } @@ -122,7 +123,7 @@ public String getMinutesPlayedTotal() { * * @return The light level of this character, as an integer */ - public int getLightLevel() { + public int getLightLevel() throws APIException { if (lightLevel == -1) { lightLevel = getJO().get("light").getAsInt(); } @@ -133,7 +134,7 @@ public int getLightLevel() { * Get the race of this character * Either Human, Exo or Awoken */ - public Race getRace() { + public Race getRace() throws APIException { if (race == null) { race = evaluateRace(getJO().get("raceHash").getAsString()); } @@ -145,7 +146,7 @@ public Race getRace() { * * @return Male or Female */ - public Gender getGender() { + public Gender getGender() throws APIException { if (gender == null) { gender = evaluateGender(getJO().get("genderHash").getAsString()); } @@ -156,7 +157,7 @@ public Gender getGender() { * Get the Class of this character * Either Warlock, Titan or Hunter */ - public DestinyClass getD2class() { + public DestinyClass getD2class() throws APIException { if (d2class == null) { d2class = evaluateClass(getJO().get("classHash").getAsString()); } @@ -169,7 +170,7 @@ public DestinyClass getD2class() { * * @return */ - public String getEmblemPath() { + public String getEmblemPath() throws APIException { if (emblemPath == null) { emblemPath = getJO().get("emblemPath").getAsString(); } @@ -180,7 +181,7 @@ public String getEmblemPath() { * Get the background of the currently equipped emblem * Add this path to the end of "https://bungie.net/" */ - public String getEmblemBackgroundPath() { + public String getEmblemBackgroundPath() throws APIException { if (emblemBackgroundPath == null) { emblemBackgroundPath = getJO().get("emblemBackgroundPath").getAsString(); } @@ -190,7 +191,7 @@ public String getEmblemBackgroundPath() { /** * Get the hash of the currently equipped emblem to be used in a manifest request */ - public String getEmblemHash() { + public String getEmblemHash() throws APIException { if (emblemHash == null) { emblemHash = getJO().get("emblemHash").getAsString(); } @@ -200,7 +201,7 @@ public String getEmblemHash() { /** * Get a list of the currently equipped items of this character */ - public List getEquippedItems() { + public List getEquippedItems() throws APIException { JsonArray jsonArray = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + getMembershipType() + "/Profile/" + bungieUser.getID() + "/Character/" + getCharacterID() + "/?components=205").getAsJsonObject("Response").getAsJsonObject("equipment").getAsJsonObject("data").getAsJsonArray("items"); @@ -221,7 +222,7 @@ public InventoryItem getItemInSlot(InventoryItem.ItemLocation itemLocation) { } */ - public List getAllItemsInInventory() { + public List getAllItemsInInventory() throws APIException { JsonArray jsonArray = hu.urlRequestGETOauth("https://www.bungie.net/Platform/Destiny2/" + getMembershipType() + "/Profile/" + bungieUser.getID() + "/Character/" + getCharacterID() + "/?components=201").getAsJsonObject("Response").getAsJsonObject("inventory").getAsJsonObject("data").getAsJsonArray("items"); @@ -249,7 +250,7 @@ public List getAllItemsInInventory() { return list; } - public List getLoadouts() { + public List getLoadouts() throws APIException { hu.urlRequestGETOauth(HttpUtils.URL_BASE + "/Destiny2/" + getMembershipType() + "/Profile/" + bungieUser.getID() + "/Character/" + getCharacterID() + "/?components=206,201"); List loadouts = new ArrayList<>(); @@ -264,7 +265,7 @@ public List getLoadouts() { * Needs work because not all activities return the same JSON info * = */ - public List getAllActivities() { + public List getAllActivities() throws APIException { if (allActivities != null) { return allActivities; } allActivities = new ArrayList<>(); JsonObject jj = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + getMembershipType() + "/Account/" + getMembershipID() + "/Character/" + getCharacterID() + "/Stats/AggregateActivityStats/"); @@ -275,7 +276,7 @@ public List getAllActivities() { } - private boolean hasPlayedInActivity(String pgcrId, List source) { + private boolean hasPlayedInActivity(String pgcrId, List source) throws APIException { for (Activity activity : source) { if (pgcrId.equals(activity.getInstanceId())) { return true; @@ -292,7 +293,7 @@ private boolean hasPlayedInActivity(String pgcrId, List source) { * * @return True or false depending on if the user played in it */ - public boolean hasPlayedInActivity(String pgcrId) { + public boolean hasPlayedInActivity(String pgcrId) throws APIException { List participantIds = new ArrayList<>(); new Activity(pgcrId).getParticipants().forEach(activityParticipant -> { @@ -302,7 +303,7 @@ public boolean hasPlayedInActivity(String pgcrId) { return participantIds.contains(getCharacterID()); } - private Gender evaluateGender(String genderHash) { + private Gender evaluateGender(String genderHash) throws APIException { JsonObject jj = hu.manifestGET(ManifestEntityTypes.GENDER, genderHash).getAsJsonObject("Response"); switch (jj.get("genderType").getAsString()) { case "0": @@ -313,7 +314,7 @@ private Gender evaluateGender(String genderHash) { return null; } - private DestinyClass evaluateClass(String classHash) { + private DestinyClass evaluateClass(String classHash) throws APIException { JsonObject jj = hu.manifestGET(ManifestEntityTypes.CLASS, classHash).getAsJsonObject("Response"); switch (jj.getAsJsonObject("displayProperties").get("name").getAsString()) { case "Warlock": @@ -326,7 +327,7 @@ private DestinyClass evaluateClass(String classHash) { return null; } - private Race evaluateRace(String raceHash) { + private Race evaluateRace(String raceHash) throws APIException { JsonObject jj = hu.manifestGET(ManifestEntityTypes.RACE, raceHash).getAsJsonObject("Response"); switch (jj.getAsJsonObject("displayProperties").get("name").getAsString()) { case "Exo": diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/activities/Activity.java b/src/main/java/net/dec4234/javadestinyapi/stats/activities/Activity.java index d35dd2c..70f73d6 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/activities/Activity.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/activities/Activity.java @@ -10,6 +10,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.utils.HttpUtils; import net.dec4234.javadestinyapi.utils.StringUtils; @@ -68,7 +69,7 @@ public Activity(String activityId, String referenceId, String directoryActivityH * * @return */ - public Date getDatePlayed() { + public Date getDatePlayed() throws APIException { checkJO(); return time == null ? time = StringUtils.valueOfZTime(getJO().get("period").getAsString()) : time; } @@ -78,7 +79,7 @@ public Date getDatePlayed() { * * @return */ - public String getReferenceId() { + public String getReferenceId() throws APIException { checkJO(); return referenceId == null ? referenceId = getJO().getAsJsonObject("activityDetails").get("referenceId").getAsString() : referenceId; } @@ -86,7 +87,7 @@ public String getReferenceId() { /** * Get the director activity hash (the type of activity played?) */ - public String getDirectoryActivityHash() { + public String getDirectoryActivityHash() throws APIException { checkJO(); return directoryActivityHash == null ? directoryActivityHash = getJO().getAsJsonObject("activityDetails").get("directorActivityHash").getAsString() : directoryActivityHash; } @@ -95,7 +96,7 @@ public String getDirectoryActivityHash() { * Gets the instance id, which happens to be the same as the activityId :) * = */ - public String getInstanceId() { + public String getInstanceId() throws APIException { checkJO(); return activityId == null ? activityId = getJO().get("instanceId").getAsString() : activityId; } @@ -103,7 +104,7 @@ public String getInstanceId() { /** * Get the mode number of the Activity */ - private int getModeNumber() { + private int getModeNumber() throws APIException { checkJO(); return mode == -1 ? mode = getJO().getAsJsonObject("activityDetails").get("mode").getAsInt() : mode; } @@ -113,7 +114,7 @@ private int getModeNumber() { * Mode list on this page * https://bungie-net.github.io/multi/schema_Destiny-Definitions-DestinyActivityDefinition.html */ - public ActivityMode getMode() { + public ActivityMode getMode() throws APIException { checkJO(); for (ActivityMode am : ActivityMode.values()) { if (am.getBungieValue() == getModeNumber()) { @@ -128,7 +129,7 @@ public ActivityMode getMode() { * * @return */ - public List getParticipants() { + public List getParticipants() throws APIException { List temp = new ArrayList<>(); try { @@ -145,7 +146,7 @@ public List getParticipants() { /** * If you need to get data not inside of this class */ - public JsonObject getJsonObject() { + public JsonObject getJsonObject() throws APIException { checkJO(); return getJO(); } diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityHistoryReview.java b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityHistoryReview.java index e966e9f..abad050 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityHistoryReview.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityHistoryReview.java @@ -11,6 +11,7 @@ import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.clan.Clan; import net.dec4234.javadestinyapi.material.clan.ClanMember; @@ -26,7 +27,7 @@ public class ActivityHistoryReview { private HttpUtils httpUtils = DestinyAPI.getHttpUtils(); - public LinkedHashMap getMostUnrecentAttempts(Clan clan, ActivityIdentifier activityIdentifier) { + public LinkedHashMap getMostUnrecentAttempts(Clan clan, ActivityIdentifier activityIdentifier) throws APIException { HashMap map = new HashMap<>(); HashMap doubleMap = new HashMap<>(); LinkedHashMap toReturn = new LinkedHashMap<>(); @@ -79,7 +80,7 @@ public int compare(Map.Entry o1, /** * Takes a very long time */ - public double getAverageCompletions(Clan clan, ActivityIdentifier activityIdentifier) { + public double getAverageCompletions(Clan clan, ActivityIdentifier activityIdentifier) throws APIException { List members = clan.getMembers(); double count = 0; @@ -90,7 +91,7 @@ public double getAverageCompletions(Clan clan, ActivityIdentifier activityIdenti return count / members.size(); } - public LinkedHashMap getTopClearers(Clan clan, ActivityIdentifier activityIdentifier) { + public LinkedHashMap getTopClearers(Clan clan, ActivityIdentifier activityIdentifier) throws APIException { HashMap map = new HashMap<>(); LinkedHashMap toReturn = new LinkedHashMap<>(); @@ -114,7 +115,7 @@ public int compare(Map.Entry o1, return toReturn; } - public int getCompletions(BungieUser bungieUser, ActivityIdentifier activityIdentifier) { + public int getCompletions(BungieUser bungieUser, ActivityIdentifier activityIdentifier) throws APIException { int count = 0; for (DestinyCharacter destinyCharacter : bungieUser.getCharacters()) { @@ -124,7 +125,7 @@ public int getCompletions(BungieUser bungieUser, ActivityIdentifier activityIden return count; } - public int getCompletions(ActivityIdentifier activityIdentifier, BungieUser bungieUser, DestinyCharacter destinyCharacter) { + public int getCompletions(ActivityIdentifier activityIdentifier, BungieUser bungieUser, DestinyCharacter destinyCharacter) throws APIException { int count = 0; for (JsonArray ja : getArrays(activityIdentifier, bungieUser, destinyCharacter)) { @@ -143,7 +144,7 @@ public int getCompletions(ActivityIdentifier activityIdentifier, BungieUser bung return count; } - public boolean hasPlayedInActivity(BungieUser bungieUser, String pgcrId) { + public boolean hasPlayedInActivity(BungieUser bungieUser, String pgcrId) throws APIException { Activity activity = new Activity(pgcrId); for (ActivityParticipant activityParticipant : activity.getParticipants()) { if (activityParticipant.getMembershipId().equals(bungieUser.getID())) { @@ -154,7 +155,7 @@ public boolean hasPlayedInActivity(BungieUser bungieUser, String pgcrId) { return false; } - public void getUndiscoveredActivityHashes(BungieUser bungieUser, ActivityIdentifier activityIdentifier) { + public void getUndiscoveredActivityHashes(BungieUser bungieUser, ActivityIdentifier activityIdentifier) throws APIException { for (DestinyCharacter destinyCharacter : bungieUser.getCharacters()) { for (int i = 0; i < 25; i++) { JsonObject jo = httpUtils.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + bungieUser.getMembershipType() + "/Account/" + bungieUser.getID() + "/Character/" + destinyCharacter.getCharacterID() + "/Stats/Activities/?page=" + i + "&count=250&mode=" + activityIdentifier.getMode().getBungieValue()); @@ -181,7 +182,7 @@ public void getUndiscoveredActivityHashes(BungieUser bungieUser, ActivityIdentif } } - private JsonArray[] getArrays(ActivityIdentifier activityIdentifier, BungieUser bungieUser, DestinyCharacter destinyCharacter) { + private JsonArray[] getArrays(ActivityIdentifier activityIdentifier, BungieUser bungieUser, DestinyCharacter destinyCharacter) throws APIException { List jsonArrays = new ArrayList<>(); for (int i = 0; i < Integer.MAX_VALUE; i++) { diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityInfo.java b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityInfo.java index 8e29b98..c77f44f 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityInfo.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityInfo.java @@ -9,6 +9,7 @@ package net.dec4234.javadestinyapi.stats.activities; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.manifest.ManifestEntityTypes; import net.dec4234.javadestinyapi.utils.framework.ContentFramework; @@ -19,7 +20,7 @@ public class ActivityInfo extends ContentFramework { private ActivityMode activityMode; private boolean hasIcon, isPlaylist, inheritFromFreeRoam, suppressOtherRewards, isMatchmade, requiresGuardianOath, isPvP; - public ActivityInfo(String hash) { + public ActivityInfo(String hash) throws APIException { super(ManifestEntityTypes.ACTIVITY, hash, source -> { return source.getAsJsonObject("Response"); }); @@ -72,11 +73,11 @@ public ActivityInfo(String hash) { this.requiresGuardianOath = getMatchmaking().get("requiresGuardianOath").getAsBoolean(); } - public JsonObject getDisplayProperties() { + public JsonObject getDisplayProperties() throws APIException { return getJO().getAsJsonObject("displayProperties"); } - public JsonObject getMatchmaking() { + public JsonObject getMatchmaking() throws APIException { return getJO().getAsJsonObject("matchmaking"); } diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/character/UserStats.java b/src/main/java/net/dec4234/javadestinyapi/stats/character/UserStats.java index e78b92b..0c7d8ed 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/character/UserStats.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/character/UserStats.java @@ -9,6 +9,7 @@ package net.dec4234.javadestinyapi.stats.character; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.user.BungieUser; import net.dec4234.javadestinyapi.material.user.DestinyCharacter; @@ -32,7 +33,7 @@ public class UserStats { /** * Gets stats for this user's entire account */ - public UserStats(BungieUser bungieUser) { + public UserStats(BungieUser bungieUser) throws APIException { this.bungieUser = bungieUser; jo = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + bungieUser.getMembershipType() + "/Account/" + bungieUser.getID() + "/Stats/").getAsJsonObject("Response").getAsJsonObject("mergedAllCharacters").getAsJsonObject("results"); allPve = jo.getAsJsonObject("allPvE").getAsJsonObject("allTime"); @@ -41,7 +42,7 @@ public UserStats(BungieUser bungieUser) { /** * Gets stats for this user's specific character */ - public UserStats(BungieUser bungieUser, DestinyCharacter destinyCharacter) { + public UserStats(BungieUser bungieUser, DestinyCharacter destinyCharacter) throws APIException { this.bungieUser = bungieUser; jo = hu.urlRequestGET("https://www.bungie.net/Platform/Destiny2/" + bungieUser.getMembershipType() + "/Account/" + bungieUser.getID() + "/Character/" + destinyCharacter.getCharacterID() + "/Stats/").getAsJsonObject("Response"); allPve = jo.getAsJsonObject("allPvE").getAsJsonObject("allTime"); diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/BungieResponse.java b/src/main/java/net/dec4234/javadestinyapi/utils/BungieResponse.java deleted file mode 100644 index b071ac6..0000000 --- a/src/main/java/net/dec4234/javadestinyapi/utils/BungieResponse.java +++ /dev/null @@ -1,81 +0,0 @@ -package net.dec4234.javadestinyapi.utils; - -import net.dec4234.javadestinyapi.exceptions.APIException; - -/** - * Describes a response received from any HTTP request to a Bungie endpoint. This should be used to properly pass - * errors to the place where calls are made, rather than upstream in {@link HttpUtils}. The goal is to reduce runtime - * exceptions by allowing users to properly handle error conditions in their code, or optionally (poor decision) to - * ignore them. - * @param The "parsed" object that is returned by the object. This could just be a JsonObject or it could be - * an api object like {@link net.dec4234.javadestinyapi.material.user.BungieUser} - */ -public class BungieResponse { - - private T parsedResponse; - private boolean isApiOnline = true; - private APIException apiException = null; - - public BungieResponse(T parsedResponse) { - this.parsedResponse = parsedResponse; - } - - public BungieResponse(boolean isApiOnline, APIException apiException) { - this.parsedResponse = null; - this.isApiOnline = isApiOnline; - this.apiException = apiException; - } - - /** - * Get the parsed object contained witihin, but only if {@link #isError} returns false - * @return The parsed object - */ - public T getParsedResponse() { - return parsedResponse; - } - - /** - * Is the API online? - * @return Returns true if the API is online. False if the bungie api returns an error that servers are offline - */ - public boolean isApiOnline() { - return isApiOnline; - } - - /** - * Was an error returned while trying to complete the request? - * @return True if an error was returned - */ - public boolean isError() { - return apiException != null; - } - - /** - * Get the error mentioned by {@link #isError()} - * @return An ApiException representing the error received while trying to complete the request - */ - public APIException getApiException() { - return apiException; - } - - /** - * "Inherit" the errors from a predecessor. Say when taking a BungieResponse and converting it to a - * BungieUser one, you want it to carry forward any error messages. - * @param other The previous BungieResponse that is being parsed and then repackaged - * @return The BungieResponse with inherited error conditions, if there are any - */ - public BungieResponse inherit(BungieResponse other) { - if(other == null) { - return null; - } - - this.update(other.getApiException(), other.isApiOnline); - - return this; - } - - private void update(APIException exception, boolean isApiOnline) { - this.apiException = exception; - this.isApiOnline = isApiOnline; - } -} diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java b/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java index d1ff8b6..327ee05 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java @@ -10,8 +10,12 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; +import com.google.gson.JsonSyntaxException; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.exceptions.APIOfflineException; import net.dec4234.javadestinyapi.exceptions.AccessTokenInvalidException; +import net.dec4234.javadestinyapi.exceptions.ConnectionException; +import net.dec4234.javadestinyapi.exceptions.JsonParsingError; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.manifest.ManifestEntityTypes; @@ -45,14 +49,14 @@ public void setApiKey(String apiKey) { /** * Send a GET url request to the url provided, returns a JsonObject of the response */ - public JsonObject urlRequestGET(String url) { + public JsonObject urlRequestGET(String url) throws APIException { return getJsonObject(getStringResponse(getRequest(true, url, starter -> { starter.GET(); return starter; }))); } - public JsonObject urlRequestGETOauth(String url) { + public JsonObject urlRequestGETOauth(String url) throws APIException { setTokenViaRefresh(); return getJsonObject(getStringResponse(getRequest(true, url, starter -> { starter.GET() @@ -61,11 +65,11 @@ public JsonObject urlRequestGETOauth(String url) { }))); } - public JsonObject urlRequestPOST(String url, JsonObject body) { + public JsonObject urlRequestPOST(String url, JsonObject body) throws APIException { return urlRequestPOST(url, body.toString()); } - public JsonObject urlRequestPOST(String url, String body) { + public JsonObject urlRequestPOST(String url, String body) throws APIException { if (body.isEmpty()) { body = "{\"message\": \"\",}"; } String finalBody = body; @@ -81,7 +85,7 @@ public JsonObject urlRequestPOST(String url, String body) { }))); } - public String urlRequestPOSTOauth(String url, String body) { + public String urlRequestPOSTOauth(String url, String body) throws APIException { setTokenViaRefresh(); if (body.isEmpty()) { body = "{\"message\": \"\",}"; } @@ -100,7 +104,7 @@ public String urlRequestPOSTOauth(String url, String body) { })); } - public JsonObject urlRequestPOSTOauth(String url, JsonObject body) { + public JsonObject urlRequestPOSTOauth(String url, JsonObject body) throws APIException { setTokenViaRefresh(); if (body.toString().isEmpty()) { body = new JsonObject(); @@ -128,7 +132,7 @@ public JsonObject urlRequestPOSTOauth(String url, JsonObject body) { * Deprecated in favor of DestinyManifest#manifestGET() */ @Deprecated - public JsonObject manifestGET(ManifestEntityTypes entityType, String hashIdentifier) { + public JsonObject manifestGET(ManifestEntityTypes entityType, String hashIdentifier) throws APIException { return urlRequestGET("https://www.bungie.net/Platform/Destiny2/Manifest/" + entityType.getBungieEntityValue() + "/" + hashIdentifier + "/"); } @@ -137,7 +141,7 @@ public JsonObject manifestGET(ManifestEntityTypes entityType, String hashIdentif * * @return Returns the new access token */ - public String setTokenViaRefresh() { + public String setTokenViaRefresh() throws APIException { String url = "https://www.bungie.net/Platform/App/OAuth/Token/"; String requestBody = "grant_type=refresh_token&refresh_token=" + DestinyAPI.getRefreshToken(); @@ -165,11 +169,11 @@ public String setTokenViaRefresh() { /** * Requries an OAuthCode to be manually set inside of the DestinyAPI.setOAuthCode() */ - public void setTokenViaAuth() { + public void setTokenViaAuth() throws APIException { setTokenViaAuth(DestinyAPI.getOauthCode()); } - public void setTokenViaAuth(String oAuthCode) { + public void setTokenViaAuth(String oAuthCode) throws APIException { String url = "https://www.bungie.net/Platform/App/OAuth/Token/"; String requestBody = "grant_type=authorization_code&code=" + oAuthCode; @@ -190,7 +194,7 @@ public void setTokenViaAuth(String oAuthCode) { HttpUtils.bearerToken = accessToken; } - public boolean checkFor401(String input) { + public boolean checkFor401(String input) throws APIException { if (input.contains("401 - Unauthorized")) { try { setTokenViaRefresh(); @@ -204,21 +208,23 @@ public boolean checkFor401(String input) { return false; } - private JsonObject getJsonObject(String stringResponse) { - JsonObject jsonObject = new JsonParser().parse(stringResponse).getAsJsonObject(); // TODO: JsonSyntaxException here + private JsonObject getJsonObject(String stringResponse) throws APIException { + JsonObject jsonObject; + + try { + jsonObject = new JsonParser().parse(stringResponse).getAsJsonObject(); + } catch (JsonSyntaxException e) { + throw new JsonParsingError(e); + } // API Offline Check if(jsonObject.has("ErrorCode") && jsonObject.get("ErrorCode").getAsInt() == 5) { - try { - throw new APIOfflineException(jsonObject.get("Message").getAsString()); - } catch (APIOfflineException exception) { - exception.printStackTrace(); - } + throw new APIOfflineException(jsonObject.get("Message").getAsString()); } return jsonObject; } - private String getStringResponse(HttpRequest httpRequest) { + private String getStringResponse(HttpRequest httpRequest) throws ConnectionException { HttpClient httpClient = HttpClient.newHttpClient(); try { String responseString = httpClient.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofString()).thenApplyAsync(HttpResponse::body).get(); @@ -229,10 +235,8 @@ private String getStringResponse(HttpRequest httpRequest) { } return responseString; } catch (InterruptedException | ExecutionException e) { - e.printStackTrace(); + throw new ConnectionException(e); } - - return null; } private HttpRequest getRequest(boolean standardRequest, String url, HttpRequestModifier httpRequestModifier) { diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/StringUtils.java b/src/main/java/net/dec4234/javadestinyapi/utils/StringUtils.java index cd4781e..3090ad6 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/StringUtils.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/StringUtils.java @@ -23,7 +23,6 @@ public class StringUtils { /** * @param zuluTimeInString The Zulu time, in the form of a String, you wish to convert * @return Returns a date object representing the Zulu time provided - * @throws ParseException */ public static Date valueOfZTime(String zuluTimeInString) { String temp = zuluTimeInString; @@ -35,10 +34,9 @@ public static Date valueOfZTime(String zuluTimeInString) { df.setTimeZone(TimeZone.getTimeZone("Zulu")); try { return df.parse(temp); - } catch (ParseException e) { - e.printStackTrace(); + } catch (ParseException e) { // TODO: log error here + return null; } - return null; } /** diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentFramework.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentFramework.java index 94956a5..6e8cfb1 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentFramework.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentFramework.java @@ -9,6 +9,7 @@ package net.dec4234.javadestinyapi.utils.framework; import com.google.gson.JsonObject; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.manifest.ManifestEntityTypes; @@ -39,7 +40,7 @@ public ContentFramework(ManifestEntityTypes manifestType, String url, JsonObject } @Override - public void checkJO() { + public void checkJO() throws APIException { if(jo == null) { if(manifestType == null) { jo = DestinyAPI.getHttpUtils().urlRequestGET(url); @@ -52,7 +53,7 @@ public void checkJO() { /** * Refresh the jsonobject to potentially account for new changes */ - public void refreshJO() { + public void refreshJO() throws APIException { if(manifestType == null) { jo = DestinyAPI.getHttpUtils().urlRequestGET(url); } else { @@ -60,7 +61,7 @@ public void refreshJO() { } } - public JsonObject getJO() { + public JsonObject getJO() throws APIException { checkJO(); return jsonObjectModifier.modify(jo); } diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentInterface.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentInterface.java index 901c98f..5b80dcc 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentInterface.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentInterface.java @@ -8,11 +8,13 @@ package net.dec4234.javadestinyapi.utils.framework; +import net.dec4234.javadestinyapi.exceptions.APIException; + public interface ContentInterface { /** * Used to verify if the raw JsonObject has been initialized * Initialize the JsonObject from here if it is not initialized */ - void checkJO(); + void checkJO() throws APIException; } diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java index 96c7036..8548724 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java @@ -9,6 +9,7 @@ package net.dec4234.javadestinyapi.utils.framework; import com.sun.net.httpserver.*; +import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.utils.StringUtils; @@ -39,7 +40,7 @@ public class OAuthFlow { * 4. Sets the tokens using that information * @param port The port to start the server on */ - public void initOAuthFlow(int port) { + public void initOAuthFlow(int port) throws APIException { setTokens(port); } @@ -47,13 +48,13 @@ public void initOAuthFlow(int port) { * Initiate the OAuth Flow only if an exisiting key cannot be found or if it has expired * @param port The port to start the server on */ - public void initOAuthFlowIfNeeded(int port) { + public void initOAuthFlowIfNeeded(int port) throws APIException { if(!DestinyAPI.hasOauthManager() || DestinyAPI.getAccessToken() == null || DestinyAPI.getHttpUtils().setTokenViaRefresh() == null) { initOAuthFlow(port); } } - private void setTokens(int serverPort) { + private void setTokens(int serverPort) throws APIException { openOAuthPage(); startSecureServer(serverPort); From 59171f06bd8c9da655275c71cf8c1100aca50248 Mon Sep 17 00:00:00 2001 From: dec4234 Date: Tue, 23 Apr 2024 22:09:16 -0400 Subject: [PATCH 3/5] #22 - Add more error catching --- .../exceptions/InvalidConditionException.java | 19 +++++++++++++++++ .../OAuthUnauthorizedException.java | 19 +++++++++++++++++ .../material/user/BungieUser.java | 2 ++ .../javadestinyapi/utils/HttpUtils.java | 21 ++++++------------- .../utils/framework/OAuthFlow.java | 7 ++++++- 5 files changed, 52 insertions(+), 16 deletions(-) create mode 100644 src/main/java/net/dec4234/javadestinyapi/exceptions/InvalidConditionException.java create mode 100644 src/main/java/net/dec4234/javadestinyapi/exceptions/OAuthUnauthorizedException.java diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/InvalidConditionException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/InvalidConditionException.java new file mode 100644 index 0000000..e9d5735 --- /dev/null +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/InvalidConditionException.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + +package net.dec4234.javadestinyapi.exceptions; + +/** + * When a token is missing or wrong, or some other pre-condition was not met that was needed to execute a request. + * This is a generic error, check the associated error message for more information. + */ +public class InvalidConditionException extends APIException { + + public InvalidConditionException(String message) { + super(message); + } +} diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/OAuthUnauthorizedException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/OAuthUnauthorizedException.java new file mode 100644 index 0000000..50e02c0 --- /dev/null +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/OAuthUnauthorizedException.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + +package net.dec4234.javadestinyapi.exceptions; + +/** + * You either have insufficient permission to attempt this OAuth action, or you forgot to authorize yourself. + * See {@link net.dec4234.javadestinyapi.utils.framework.OAuthFlow} + */ +public class OAuthUnauthorizedException extends APIException { + + public OAuthUnauthorizedException(String message) { + super(message); + } +} diff --git a/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java b/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java index a5a9256..ea2acc3 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java @@ -44,6 +44,7 @@ public class BungieUser extends ContentFramework { private List destinyCharacters = null; private int playTime = -1, crossSaveOverride = -1, membershipType = -1; private boolean isPublic, isCrossSavePrimary, isOverridden = false; + @Deprecated private int intendedPlatform = -2; private InventoryManager inventoryManager; private CollectionsManager collectionsManager; @@ -443,6 +444,7 @@ public JsonObject getJE() throws APIException { return je; } + @Deprecated public void setIntendedPlatform(DestinyPlatform destinyPlatform) { intendedPlatform = destinyPlatform.getPlatformCode(); je = null; diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java b/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java index 327ee05..4b64f5b 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java @@ -13,8 +13,8 @@ import com.google.gson.JsonSyntaxException; import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.exceptions.APIOfflineException; -import net.dec4234.javadestinyapi.exceptions.AccessTokenInvalidException; import net.dec4234.javadestinyapi.exceptions.ConnectionException; +import net.dec4234.javadestinyapi.exceptions.InvalidConditionException; import net.dec4234.javadestinyapi.exceptions.JsonParsingError; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.manifest.ManifestEntityTypes; @@ -154,6 +154,10 @@ public String setTokenViaRefresh() throws APIException { return starter; }))); + if(response.has("error_description") && response.get("error_description").getAsString().equals("ApplicationTokenKeyIdDoesNotExist")) { + throw new InvalidConditionException("The refresh token is invalid, you likely need to generate new tokens"); + } + if(!response.has("access_token")) { return null; } @@ -194,20 +198,6 @@ public void setTokenViaAuth(String oAuthCode) throws APIException { HttpUtils.bearerToken = accessToken; } - public boolean checkFor401(String input) throws APIException { - if (input.contains("401 - Unauthorized")) { - try { - setTokenViaRefresh(); - throw new AccessTokenInvalidException("The access token used in this OAuth request was not accepted by the server \nI've already taken the liberty of getting a new access token for you :D"); - } catch (AccessTokenInvalidException e) { - e.printStackTrace(); - return true; - } - } - - return false; - } - private JsonObject getJsonObject(String stringResponse) throws APIException { JsonObject jsonObject; @@ -221,6 +211,7 @@ private JsonObject getJsonObject(String stringResponse) throws APIException { if(jsonObject.has("ErrorCode") && jsonObject.get("ErrorCode").getAsInt() == 5) { throw new APIOfflineException(jsonObject.get("Message").getAsString()); } + return jsonObject; } diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java index 8548724..717e395 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java @@ -10,6 +10,7 @@ import com.sun.net.httpserver.*; import net.dec4234.javadestinyapi.exceptions.APIException; +import net.dec4234.javadestinyapi.exceptions.InvalidConditionException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.utils.StringUtils; @@ -49,7 +50,11 @@ public void initOAuthFlow(int port) throws APIException { * @param port The port to start the server on */ public void initOAuthFlowIfNeeded(int port) throws APIException { - if(!DestinyAPI.hasOauthManager() || DestinyAPI.getAccessToken() == null || DestinyAPI.getHttpUtils().setTokenViaRefresh() == null) { + try { + if(!DestinyAPI.hasOauthManager() || DestinyAPI.getAccessToken() == null || DestinyAPI.getHttpUtils().setTokenViaRefresh() == null) { + initOAuthFlow(port); + } + } catch (InvalidConditionException e) { initOAuthFlow(port); } } From e589ac1e1f299aedd8015f3a7326537845e7e30e Mon Sep 17 00:00:00 2001 From: dec4234 Date: Sun, 28 Apr 2024 16:27:41 -0400 Subject: [PATCH 4/5] #22 - Don't refresh every time, documentation --- .../AccessTokenExpiredException.java | 14 +++ .../AccessTokenInvalidException.java | 23 ---- .../OAuthUnauthorizedException.java | 1 + .../RefreshTokenExpiredException.java | 17 +++ .../material/clan/ClanManagement.java | 24 ++-- .../inventory/items/InventoryItem.java | 2 +- .../material/user/BungieUser.java | 2 +- .../javadestinyapi/utils/HttpUtils.java | 117 +++++++++++------- .../utils/framework/JDAOAuth.java | 6 + .../utils/framework/OAuthFlow.java | 23 ++++ .../utils/framework/OAuthManager.java | 7 ++ 11 files changed, 156 insertions(+), 80 deletions(-) create mode 100644 src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenExpiredException.java delete mode 100644 src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenInvalidException.java create mode 100644 src/main/java/net/dec4234/javadestinyapi/exceptions/RefreshTokenExpiredException.java diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenExpiredException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenExpiredException.java new file mode 100644 index 0000000..d7b74fc --- /dev/null +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenExpiredException.java @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + +package net.dec4234.javadestinyapi.exceptions; + +/** + * Self explanatory. The access token needs to be regenerated using the refresh token. + */ +public class AccessTokenExpiredException extends APIException{ +} diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenInvalidException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenInvalidException.java deleted file mode 100644 index cea5635..0000000 --- a/src/main/java/net/dec4234/javadestinyapi/exceptions/AccessTokenInvalidException.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. - * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI - */ - -package net.dec4234.javadestinyapi.exceptions; - -/** - * Thrown whenever a 401 error is detected in the HTTP response - * This error indicates that the OAuth access token used by the request was not accepted by the server - */ -public class AccessTokenInvalidException extends APIException { - - public AccessTokenInvalidException() { - } - - public AccessTokenInvalidException(String message) { - super(message); - } -} diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/OAuthUnauthorizedException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/OAuthUnauthorizedException.java index 50e02c0..1680709 100644 --- a/src/main/java/net/dec4234/javadestinyapi/exceptions/OAuthUnauthorizedException.java +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/OAuthUnauthorizedException.java @@ -9,6 +9,7 @@ /** * You either have insufficient permission to attempt this OAuth action, or you forgot to authorize yourself. + * Alternatively, the access and/or refresh token has expired * See {@link net.dec4234.javadestinyapi.utils.framework.OAuthFlow} */ public class OAuthUnauthorizedException extends APIException { diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/RefreshTokenExpiredException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/RefreshTokenExpiredException.java new file mode 100644 index 0000000..a9af245 --- /dev/null +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/RefreshTokenExpiredException.java @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + +package net.dec4234.javadestinyapi.exceptions; + +/** + * The name is self-expanatory. The refresh token normally used to generate a new access token has expired since it + * hasn't been refreshed in the past 90 days or it has been 1 year since the last oauth. + * See {@link net.dec4234.javadestinyapi.utils.framework.OAuthFlow} to generate a new one. + */ +public class RefreshTokenExpiredException extends APIException { + +} diff --git a/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanManagement.java b/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanManagement.java index cbd520c..3706d84 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanManagement.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanManagement.java @@ -40,56 +40,56 @@ public ClanManagement(Clan clan) { * Kicks this user from the clan */ public void kickPlayer(BungieUser bungieUser) throws APIException { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/Kick/", ""); + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/Kick/"); } /** * Bans the user from the clan */ public void banUser(BungieUser bungieUser) throws APIException { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/Ban/", ""); + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/Ban/"); } /** * Unbans this user from the clan, as long as they are banned, of course */ public void unbanUser(BungieUser bungieUser) throws APIException { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/Unban/", ""); + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/Unban/"); } /** * Invites the specified user to join the clan */ public void inviteUser(BungieUser bungieUser) throws APIException { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/IndividualInvite/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/", ""); + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/IndividualInvite/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/"); } /** * Cancels the invite for this user to join the clan */ public void cancelInvite(BungieUser bungieUser) throws APIException { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/IndividualInviteCancel/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/", ""); + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/IndividualInviteCancel/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/"); } /** * Approves this user's request to join the clan if and only if they have requested to join */ public void approvePendingMember(BungieUser bungieUser) throws APIException { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Approve/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/", ""); + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Approve/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/"); } /** * Approves all requests to join the clan */ public void approveAllPendingMembers() throws APIException { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/ApproveAll/", ""); + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/ApproveAll/"); } /** * Denies all pending requests to join the clan :) */ public void denyAllPendingMembers() throws APIException { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/DenyAll/?components=200", ""); + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/DenyAll/?components=200"); } /** @@ -98,7 +98,7 @@ public void denyAllPendingMembers() throws APIException { * @param bungieUser The user who will be the new founder (leader) of the clan */ public void abdicateFoundership(BungieUser bungieUser) throws APIException { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Admin/AbdicateFoundership/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/", ""); + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Admin/AbdicateFoundership/" + bungieUser.getMembershipType() + "/" + bungieUser.getID() + "/"); } /** @@ -112,7 +112,7 @@ public void addOptionalConversation(String chatName, ClanChatSecuritySetting cla jsonObject.addProperty("chatName", chatName); jsonObject.addProperty("chatSecurity", clanChatSecuritySetting.getSetting()); - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Admin/OptionalConversations/Add/", jsonObject.toString()); + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Admin/OptionalConversations/Add/", jsonObject); } /** @@ -129,7 +129,7 @@ public void editOptionalConversation(String conversationID, boolean chatEnabled, jsonObject.addProperty("chatSecurity", clanChatSecuritySetting.getSetting()); jsonObject.addProperty("chatEnabled", chatEnabled); - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Admin/OptionalConversations/" + conversationID + "/Edit/", jsonObject.toString()); + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Admin/OptionalConversations/" + conversationID + "/Edit/", jsonObject); } /** @@ -173,7 +173,7 @@ public List getPendingMembers() throws APIException { public List getInvitedMembers() throws APIException { List temp = new ArrayList<>(); - JsonArray ja = hu.urlRequestGETOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Invited/?components=200").getAsJsonObject("Response").getAsJsonArray("results"); + JsonArray ja = hu.urlRequestGETOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/InvitedIndividuals/?components=200").getAsJsonObject("Response").getAsJsonArray("results"); for(JsonElement je : ja) { temp.add(new BungieUser(je.getAsJsonObject().getAsJsonObject("destinyUserInfo").get("membershipId").getAsString())); diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryItem.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryItem.java index dedb985..3703049 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryItem.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryItem.java @@ -203,7 +203,7 @@ public void setLockState(boolean state) throws APIException { jsonObject.addProperty("membershipType", getCharacterOwner().getMembershipType()); - httpUtils.urlRequestPOSTOauth(HttpUtils.URL_BASE + "/Destiny2/Actions/Items/SetLockState/", jsonObject.toString()); + httpUtils.urlRequestPOSTOauth(HttpUtils.URL_BASE + "/Destiny2/Actions/Items/SetLockState/", jsonObject); } /** diff --git a/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java b/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java index ea2acc3..f67be21 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java @@ -389,7 +389,7 @@ public ActivityInfo getCurrentActivityInfo() throws APIException { * Request to join the specified clan */ public void requestToJoinClan(Clan clan) throws APIException { - hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Apply/" + getMembershipType() + "/", ""); + hu.urlRequestPOSTOauth("https://www.bungie.net/Platform/GroupV2/" + clan.getClanID() + "/Members/Apply/" + getMembershipType() + "/"); } /** diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java b/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java index 4b64f5b..073ee76 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java @@ -13,9 +13,12 @@ import com.google.gson.JsonSyntaxException; import net.dec4234.javadestinyapi.exceptions.APIException; import net.dec4234.javadestinyapi.exceptions.APIOfflineException; +import net.dec4234.javadestinyapi.exceptions.AccessTokenExpiredException; import net.dec4234.javadestinyapi.exceptions.ConnectionException; import net.dec4234.javadestinyapi.exceptions.InvalidConditionException; import net.dec4234.javadestinyapi.exceptions.JsonParsingError; +import net.dec4234.javadestinyapi.exceptions.OAuthUnauthorizedException; +import net.dec4234.javadestinyapi.exceptions.RefreshTokenExpiredException; import net.dec4234.javadestinyapi.material.DestinyAPI; import net.dec4234.javadestinyapi.material.manifest.ManifestEntityTypes; @@ -50,19 +53,28 @@ public void setApiKey(String apiKey) { * Send a GET url request to the url provided, returns a JsonObject of the response */ public JsonObject urlRequestGET(String url) throws APIException { - return getJsonObject(getStringResponse(getRequest(true, url, starter -> { + return getJsonObject(getRequest(true, url, starter -> { starter.GET(); return starter; - }))); + })); } public JsonObject urlRequestGETOauth(String url) throws APIException { - setTokenViaRefresh(); - return getJsonObject(getStringResponse(getRequest(true, url, starter -> { - starter.GET() - .setHeader("Authorization", "Bearer " + HttpUtils.bearerToken); - return starter; - }))); + try { + return getJsonObject(getRequest(true, url, starter -> { + starter.GET() + .setHeader("Authorization", "Bearer " + HttpUtils.bearerToken); + return starter; + })); + } catch (AccessTokenExpiredException e) { + setTokenViaRefresh(); + + return getJsonObject(getRequest(true, url, starter -> { + starter.GET() + .setHeader("Authorization", "Bearer " + HttpUtils.bearerToken); + return starter; + })); + } } public JsonObject urlRequestPOST(String url, JsonObject body) throws APIException { @@ -77,29 +89,10 @@ public JsonObject urlRequestPOST(String url, String body) throws APIException { System.out.println("Body: " + finalBody); } - return getJsonObject(getStringResponse(getRequest(true, url, starter -> { + return getJsonObject(getRequest(true, url, starter -> { starter.setHeader("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(finalBody)); - return starter; - }))); - } - - public String urlRequestPOSTOauth(String url, String body) throws APIException { - setTokenViaRefresh(); - if (body.isEmpty()) { body = "{\"message\": \"\",}"; } - - String finalBody = body; - - if(DestinyAPI.isDebugEnabled()) { - System.out.println("Body: " + finalBody); - } - - return getStringResponse(getRequest(true, url, starter -> { - starter.setHeader("Authorization", "Bearer " + HttpUtils.bearerToken) - .setHeader("Content-Type", "application/json") - .POST(HttpRequest.BodyPublishers.ofString(finalBody)); - return starter; })); } @@ -117,13 +110,28 @@ public JsonObject urlRequestPOSTOauth(String url, JsonObject body) throws APIExc System.out.println("Body: " + finalBody); } - return getJsonObject(getStringResponse(getRequest(true, url, starter -> { - starter.setHeader("Authorization", "Bearer " + HttpUtils.bearerToken) - .setHeader("Content-Type", "application/json") - .POST(HttpRequest.BodyPublishers.ofString(finalBody)); + try { + return getJsonObject(getRequest(true, url, starter -> { + starter.setHeader("Authorization", "Bearer " + HttpUtils.bearerToken) + .setHeader("Content-Type", "application/json") + .POST(HttpRequest.BodyPublishers.ofString(finalBody)); + + return starter; + })); + } catch (AccessTokenExpiredException e) { + setTokenViaRefresh(); + return getJsonObject(getRequest(true, url, starter -> { + starter.setHeader("Authorization", "Bearer " + HttpUtils.bearerToken) + .setHeader("Content-Type", "application/json") + .POST(HttpRequest.BodyPublishers.ofString(finalBody)); + + return starter; + })); + } + } - return starter; - }))); + public JsonObject urlRequestPOSTOauth(String url) throws APIException { + return urlRequestPOSTOauth(url, new JsonObject()); } /** @@ -146,13 +154,13 @@ public String setTokenViaRefresh() throws APIException { String requestBody = "grant_type=refresh_token&refresh_token=" + DestinyAPI.getRefreshToken(); - JsonObject response = getJsonObject(getStringResponse(getRequest(false, url, starter -> { + JsonObject response = getJsonObject(getRequest(false, url, starter -> { starter.setHeader("Content-Type", "application/x-www-form-urlencoded") .setHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString((DestinyAPI.getClientId() + ":" + DestinyAPI.getClientSecret()).getBytes())) .POST(HttpRequest.BodyPublishers.ofString(requestBody)); return starter; - }))); + })); if(response.has("error_description") && response.get("error_description").getAsString().equals("ApplicationTokenKeyIdDoesNotExist")) { throw new InvalidConditionException("The refresh token is invalid, you likely need to generate new tokens"); @@ -182,13 +190,13 @@ public void setTokenViaAuth(String oAuthCode) throws APIException { String requestBody = "grant_type=authorization_code&code=" + oAuthCode; - JsonObject jsonObject = getJsonObject(getStringResponse(getRequest(false, url, starter -> { + JsonObject jsonObject = getJsonObject(getRequest(false, url, starter -> { starter.setHeader("Authorization", "Basic " + Base64.getEncoder().encodeToString((DestinyAPI.getClientId() + ":" + DestinyAPI.getClientSecret()).getBytes())) .setHeader("Content-Type", "application/x-www-form-urlencoded") .POST(HttpRequest.BodyPublishers.ofString(requestBody)); return starter; - }))); + })); String accessToken = jsonObject.get("access_token").getAsString(); String refreshToken = jsonObject.get("refresh_token").getAsString(); @@ -198,18 +206,41 @@ public void setTokenViaAuth(String oAuthCode) throws APIException { HttpUtils.bearerToken = accessToken; } - private JsonObject getJsonObject(String stringResponse) throws APIException { + private JsonObject getJsonObject(HttpRequest httpRequest) throws APIException { + HttpClient httpClient = HttpClient.newHttpClient(); + String responseString; + + try { // TODO: are we even taking advantage of async? this seems pointless to just block right away + responseString = httpClient.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofString()).thenApplyAsync(HttpResponse::body).get(); + + if (DestinyAPI.isDebugEnabled()) { + System.out.println(httpRequest.method() + " " + httpRequest.uri().toString()); + System.out.println(responseString); + } + } catch (InterruptedException | ExecutionException e) { + throw new ConnectionException(e); + } + JsonObject jsonObject; try { - jsonObject = new JsonParser().parse(stringResponse).getAsJsonObject(); + jsonObject = new JsonParser().parse(responseString).getAsJsonObject(); } catch (JsonSyntaxException e) { throw new JsonParsingError(e); } - // API Offline Check - if(jsonObject.has("ErrorCode") && jsonObject.get("ErrorCode").getAsInt() == 5) { - throw new APIOfflineException(jsonObject.get("Message").getAsString()); + // Check for API errors - https://bungie-net.github.io/multi/schema_Exceptions-PlatformErrorCodes.html#schema_Exceptions-PlatformErrorCodes + if(jsonObject.has("ErrorCode")) { + switch (jsonObject.get("ErrorCode").getAsInt()) { //TODO: lots of errors we could catch here + case 5: // APIOffline + throw new APIOfflineException(jsonObject.get("Message").getAsString()); + case 99: // WebAuthRequired + throw new OAuthUnauthorizedException("OAuth - access denied. Try authenticating."); + case 2111 | 2115: // AccessTokenHasExpired, OAuthAccessTokenExpired + throw new AccessTokenExpiredException(); + case 2118: // RefreshTokenExpired -- need to reauth using oauth + throw new RefreshTokenExpiredException(); + } } return jsonObject; diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/JDAOAuth.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/JDAOAuth.java index 240eea4..9a63263 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/JDAOAuth.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/JDAOAuth.java @@ -8,6 +8,12 @@ package net.dec4234.javadestinyapi.utils.framework; +/** + * Contains all of the functions needed for the API to adequately store OAuth tokens. + *
+ * Note: OAuth could allow potenially dangerous actions such as full control over your clan (if you are an admin) as + * well as your inventory. Use at your own risk, and use good data management and protection practices. + */ public interface JDAOAuth { String getAccessToken(); diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java index 717e395..3ee4ba9 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java @@ -25,6 +25,29 @@ import java.security.KeyStore; import java.util.concurrent.Executors; +/** + * The OAuthFlow class allows a user to easily generate oauth tokens for a small project that is not distributed to + * external users. This class could be replicated by an experienced user to allow for handling multiple oauth tokens. + *

+ * Note: OAuth could allow potenially dangerous actions such as full control over your clan (if you are an admin) as + * well as your inventory. Use at your own risk, and use good data management and protection practices. + *

+ * Here is the process:
+ * 1. Go to your app on https://www.bungie.net/en/Application
+ * 2. Under "App authentication" set the client type to confidential and set the redirect to something like + * "https://localhost:8080". Note that is MUST be HTTPS not HTTP
+ * 3. Adjust the permissions for the app using the checkboxes right below it.
+ * 4. Use the following code to init your oauth tokens. + *

{@code
+ * OAuthFlow oAuthFlow = new OAuthFlow();
+ * oAuthFlow.initOAuthFlowIfNeeded(8080);
+ * }
+ * This will open the browser on your local machine where it will direct you to do oauth. It might say that the site is + * unsafe since it doesn't have a valid certificate. On chrome, click the "advanced" button and then "continue". You + * should now be able to perform OAuth requests and all the interesting things you can build with it.
+ * 5.(Optionally) When initializing the DestinyAPI you can use {@link DestinyAPI#setOauthManager(OAuthManager)} to save + * the tokens however you want, so you don't have to oauth frequently. + */ public class OAuthFlow { // keytool -genkey -dname "cn=dec 4234, ou=github/JavaDestinyAPI, o=ou=github/JavaDestinyAPI, c=US" -keyalg RSA -alias alias -keystore keystore.jks -storepass mypassword -keypass mypassword -validity 360 -keysize 2048 diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthManager.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthManager.java index cb91d64..61617db 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthManager.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthManager.java @@ -8,5 +8,12 @@ package net.dec4234.javadestinyapi.utils.framework; +/** + * Used to direct the storage of OAuth tokens using the user's own code. See {@link OAuthFlow} and {@link JDAOAuth} for + * more info. + *
+ * Note: OAuth could allow potenially dangerous actions such as full control over your clan (if you are an admin) as + * well as your inventory. Use at your own risk, and use good data management and protection practices. + */ public abstract class OAuthManager implements JDAOAuth { } From 0e8e017294ea33a4da715ccc2c536ca1a8980fcc Mon Sep 17 00:00:00 2001 From: dec4234 Date: Sun, 28 Apr 2024 18:42:53 -0400 Subject: [PATCH 5/5] #22 - Update copyright and dependencies --- pom.xml | 11 +++++------ .../exceptions/APIException.java | 7 +++++++ .../exceptions/APIOfflineException.java | 7 +++---- .../exceptions/JsonParsingError.java | 7 +++++++ .../jdaSrc/JavaDestinyAPIMain.java | 7 +++---- .../javadestinyapi/material/DestinyAPI.java | 7 +++---- .../javadestinyapi/material/clan/Clan.java | 9 ++++----- .../material/clan/ClanChatSecuritySetting.java | 7 +++++++ .../material/clan/ClanManagement.java | 7 +++---- .../material/clan/ClanMember.java | 7 +++++++ .../material/inventory/CollectionsManager.java | 7 +++---- .../material/inventory/InventoryManager.java | 7 +++---- .../material/inventory/items/Armor.java | 7 +++++++ .../material/inventory/items/DestinyItem.java | 7 +++---- .../inventory/items/InventoryBucket.java | 7 +++---- .../inventory/items/InventoryItem.java | 7 +++---- .../material/inventory/items/ItemPerk.java | 7 +++++++ .../material/inventory/items/ItemPlug.java | 7 +++++++ .../material/inventory/loadouts/Loadout.java | 7 +++++++ .../material/manifest/DestinyManifest.java | 7 +++---- .../material/manifest/ManifestEntityTypes.java | 7 +++---- .../material/social/SocialFriend.java | 7 +++++++ .../material/social/SocialFriendsList.java | 7 +++++++ .../material/user/BungieUser.java | 7 +++---- .../material/user/DestinyCharacter.java | 7 +++---- .../material/user/DestinyPlatform.java | 7 +++---- .../material/user/DestinyProfile.java | 7 +++++++ .../material/user/UserCredential.java | 7 +++---- .../material/user/UserCredentialType.java | 7 +++---- .../user/SanitizedUsernamesResponse.java | 7 +++++++ .../stats/activities/Activity.java | 7 +++---- .../activities/ActivityHistoryReview.java | 7 +++---- .../stats/activities/ActivityIdentifier.java | 7 +++---- .../stats/activities/ActivityInfo.java | 7 +++---- .../stats/activities/ActivityMode.java | 7 +++---- .../stats/activities/ActivityParticipant.java | 7 +++---- .../stats/character/UserStats.java | 7 +++---- .../utils/HttpRequestModifier.java | 7 +++---- .../javadestinyapi/utils/HttpUtils.java | 18 ++++++++++-------- .../javadestinyapi/utils/StringUtils.java | 7 +++---- .../javadestinyapi/utils/fast/ASyncPull.java | 7 +++---- .../javadestinyapi/utils/fast/ASyncPuller.java | 7 +++---- .../utils/framework/ContentFramework.java | 7 +++---- .../utils/framework/ContentInterface.java | 7 +++---- .../utils/framework/JDAOAuth.java | 7 +++---- .../utils/framework/JsonObjectModifier.java | 7 +++---- .../utils/framework/OAuthFlow.java | 7 +++---- .../utils/framework/OAuthManager.java | 7 +++---- 48 files changed, 202 insertions(+), 151 deletions(-) diff --git a/pom.xml b/pom.xml index 0df2307..0b1891b 100644 --- a/pom.xml +++ b/pom.xml @@ -1,10 +1,9 @@ com.google.code.gson gson - 2.8.6 + 2.8.9 org.jetbrains @@ -62,7 +61,7 @@ org.apache.maven.plugins maven-compiler-plugin - 3.8.1 + 3.11.0 diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/APIException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/APIException.java index 3f9e21a..d438167 100644 --- a/src/main/java/net/dec4234/javadestinyapi/exceptions/APIException.java +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/APIException.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.exceptions; /** diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/APIOfflineException.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/APIOfflineException.java index 16c0d68..2b4312c 100644 --- a/src/main/java/net/dec4234/javadestinyapi/exceptions/APIOfflineException.java +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/APIOfflineException.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.exceptions; diff --git a/src/main/java/net/dec4234/javadestinyapi/exceptions/JsonParsingError.java b/src/main/java/net/dec4234/javadestinyapi/exceptions/JsonParsingError.java index b2ecfa5..0973f62 100644 --- a/src/main/java/net/dec4234/javadestinyapi/exceptions/JsonParsingError.java +++ b/src/main/java/net/dec4234/javadestinyapi/exceptions/JsonParsingError.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.exceptions; import com.google.gson.JsonSyntaxException; diff --git a/src/main/java/net/dec4234/javadestinyapi/jdaSrc/JavaDestinyAPIMain.java b/src/main/java/net/dec4234/javadestinyapi/jdaSrc/JavaDestinyAPIMain.java index 3db4218..acc590f 100644 --- a/src/main/java/net/dec4234/javadestinyapi/jdaSrc/JavaDestinyAPIMain.java +++ b/src/main/java/net/dec4234/javadestinyapi/jdaSrc/JavaDestinyAPIMain.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.jdaSrc; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/DestinyAPI.java b/src/main/java/net/dec4234/javadestinyapi/material/DestinyAPI.java index 1b63857..972eec8 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/DestinyAPI.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/DestinyAPI.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/clan/Clan.java b/src/main/java/net/dec4234/javadestinyapi/material/clan/Clan.java index f1a09cd..1cd6b90 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/clan/Clan.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/clan/Clan.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.clan; @@ -39,7 +38,7 @@ public class Clan extends ContentFramework { private int memberCount = -1; private List admins, members; - private net.dec4234.javadestinyapi.material.clan.ClanManagement clanManagement; + private ClanManagement clanManagement; private JsonObject jj; public Clan(long clanId) { diff --git a/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanChatSecuritySetting.java b/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanChatSecuritySetting.java index 4378c14..d42f390 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanChatSecuritySetting.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanChatSecuritySetting.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.clan; public enum ClanChatSecuritySetting { diff --git a/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanManagement.java b/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanManagement.java index 3706d84..57ec675 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanManagement.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanManagement.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.clan; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanMember.java b/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanMember.java index b7cea7f..2e08785 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanMember.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/clan/ClanMember.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.clan; import com.google.gson.JsonObject; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/CollectionsManager.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/CollectionsManager.java index ba56fd9..5641af9 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/CollectionsManager.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/CollectionsManager.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.inventory; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/InventoryManager.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/InventoryManager.java index 54e651f..dfbd8ea 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/InventoryManager.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/InventoryManager.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.inventory; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/Armor.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/Armor.java index f405a1f..d2463db 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/Armor.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/Armor.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.inventory.items; import net.dec4234.javadestinyapi.material.user.DestinyCharacter; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/DestinyItem.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/DestinyItem.java index 596a735..03912ab 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/DestinyItem.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/DestinyItem.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.inventory.items; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryBucket.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryBucket.java index 2063785..966d421 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryBucket.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryBucket.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.inventory.items; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryItem.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryItem.java index 3703049..36e9f2c 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryItem.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/InventoryItem.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.inventory.items; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPerk.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPerk.java index 6f34b9f..97b7152 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPerk.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPerk.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.inventory.items; import com.google.gson.JsonObject; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPlug.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPlug.java index dddcc8d..b2b38ce 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPlug.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/items/ItemPlug.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.inventory.items; import com.google.gson.JsonObject; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/inventory/loadouts/Loadout.java b/src/main/java/net/dec4234/javadestinyapi/material/inventory/loadouts/Loadout.java index 759ca3b..fd89ed2 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/inventory/loadouts/Loadout.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/inventory/loadouts/Loadout.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.inventory.loadouts; import com.google.gson.JsonObject; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/manifest/DestinyManifest.java b/src/main/java/net/dec4234/javadestinyapi/material/manifest/DestinyManifest.java index 5576e7b..aecee3b 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/manifest/DestinyManifest.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/manifest/DestinyManifest.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.manifest; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/manifest/ManifestEntityTypes.java b/src/main/java/net/dec4234/javadestinyapi/material/manifest/ManifestEntityTypes.java index 09f2ec3..4da0d30 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/manifest/ManifestEntityTypes.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/manifest/ManifestEntityTypes.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.manifest; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriend.java b/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriend.java index ca5911a..c2e929c 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriend.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriend.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.social; import com.google.gson.JsonObject; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriendsList.java b/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriendsList.java index 805ce3f..b382ec1 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriendsList.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/social/SocialFriendsList.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.social; import com.google.gson.JsonElement; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java b/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java index f67be21..d5280db 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/user/BungieUser.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.user; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyCharacter.java b/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyCharacter.java index 4c6b601..ad06555 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyCharacter.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyCharacter.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.user; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyPlatform.java b/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyPlatform.java index 149ce0f..2b732e3 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyPlatform.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyPlatform.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.user; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyProfile.java b/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyProfile.java index 6b78b22..bf24131 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyProfile.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/user/DestinyProfile.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.material.user; import com.google.gson.JsonElement; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/user/UserCredential.java b/src/main/java/net/dec4234/javadestinyapi/material/user/UserCredential.java index 225c915..9c50f1e 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/user/UserCredential.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/user/UserCredential.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.user; diff --git a/src/main/java/net/dec4234/javadestinyapi/material/user/UserCredentialType.java b/src/main/java/net/dec4234/javadestinyapi/material/user/UserCredentialType.java index f2d8cfa..513512a 100644 --- a/src/main/java/net/dec4234/javadestinyapi/material/user/UserCredentialType.java +++ b/src/main/java/net/dec4234/javadestinyapi/material/user/UserCredentialType.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.material.user; diff --git a/src/main/java/net/dec4234/javadestinyapi/responses/user/SanitizedUsernamesResponse.java b/src/main/java/net/dec4234/javadestinyapi/responses/user/SanitizedUsernamesResponse.java index 6eb223b..23365d7 100644 --- a/src/main/java/net/dec4234/javadestinyapi/responses/user/SanitizedUsernamesResponse.java +++ b/src/main/java/net/dec4234/javadestinyapi/responses/user/SanitizedUsernamesResponse.java @@ -1,3 +1,10 @@ +/* + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. + * + * Github -> https://github.com/dec4234/JavaDestinyAPI + */ + package net.dec4234.javadestinyapi.responses.user; import com.google.gson.JsonObject; diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/activities/Activity.java b/src/main/java/net/dec4234/javadestinyapi/stats/activities/Activity.java index 70f73d6..646cccc 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/activities/Activity.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/activities/Activity.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.stats.activities; diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityHistoryReview.java b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityHistoryReview.java index abad050..d10d167 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityHistoryReview.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityHistoryReview.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.stats.activities; diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityIdentifier.java b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityIdentifier.java index 5ebfe80..c8ea8e3 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityIdentifier.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityIdentifier.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.stats.activities; diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityInfo.java b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityInfo.java index c77f44f..9319387 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityInfo.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityInfo.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.stats.activities; diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityMode.java b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityMode.java index 22eff29..26a6c84 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityMode.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityMode.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.stats.activities; diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityParticipant.java b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityParticipant.java index bcc0c33..1532f7c 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityParticipant.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/activities/ActivityParticipant.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.stats.activities; diff --git a/src/main/java/net/dec4234/javadestinyapi/stats/character/UserStats.java b/src/main/java/net/dec4234/javadestinyapi/stats/character/UserStats.java index 0c7d8ed..973d42d 100644 --- a/src/main/java/net/dec4234/javadestinyapi/stats/character/UserStats.java +++ b/src/main/java/net/dec4234/javadestinyapi/stats/character/UserStats.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.stats.character; diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/HttpRequestModifier.java b/src/main/java/net/dec4234/javadestinyapi/utils/HttpRequestModifier.java index 2cab98b..30574cb 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/HttpRequestModifier.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/HttpRequestModifier.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils; diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java b/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java index 073ee76..0c32e1e 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/HttpUtils.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils; @@ -15,7 +14,6 @@ import net.dec4234.javadestinyapi.exceptions.APIOfflineException; import net.dec4234.javadestinyapi.exceptions.AccessTokenExpiredException; import net.dec4234.javadestinyapi.exceptions.ConnectionException; -import net.dec4234.javadestinyapi.exceptions.InvalidConditionException; import net.dec4234.javadestinyapi.exceptions.JsonParsingError; import net.dec4234.javadestinyapi.exceptions.OAuthUnauthorizedException; import net.dec4234.javadestinyapi.exceptions.RefreshTokenExpiredException; @@ -163,7 +161,7 @@ public String setTokenViaRefresh() throws APIException { })); if(response.has("error_description") && response.get("error_description").getAsString().equals("ApplicationTokenKeyIdDoesNotExist")) { - throw new InvalidConditionException("The refresh token is invalid, you likely need to generate new tokens"); + throw new RefreshTokenExpiredException(); } if(!response.has("access_token")) { @@ -175,6 +173,10 @@ public String setTokenViaRefresh() throws APIException { bearerToken = at; new DestinyAPI().setAccessToken(at).setRefreshToken(rt); + if(DestinyAPI.isDebugEnabled()) { + System.out.println("TOKENS REFRESHED"); + } + return at; } @@ -224,7 +226,7 @@ private JsonObject getJsonObject(HttpRequest httpRequest) throws APIException { JsonObject jsonObject; try { - jsonObject = new JsonParser().parse(responseString).getAsJsonObject(); + jsonObject = JsonParser.parseString(responseString).getAsJsonObject(); } catch (JsonSyntaxException e) { throw new JsonParsingError(e); } @@ -253,7 +255,7 @@ private String getStringResponse(HttpRequest httpRequest) throws ConnectionExcep if (DestinyAPI.isDebugEnabled()) { System.out.println(httpRequest.method() + " " + httpRequest.uri().toString()); - System.out.println(responseString); + System.out.println("Response: " + responseString); } return responseString; } catch (InterruptedException | ExecutionException e) { diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/StringUtils.java b/src/main/java/net/dec4234/javadestinyapi/utils/StringUtils.java index 3090ad6..24b1e4d 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/StringUtils.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/StringUtils.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils; diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/fast/ASyncPull.java b/src/main/java/net/dec4234/javadestinyapi/utils/fast/ASyncPull.java index 1902fb3..8135626 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/fast/ASyncPull.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/fast/ASyncPull.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils.fast; diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/fast/ASyncPuller.java b/src/main/java/net/dec4234/javadestinyapi/utils/fast/ASyncPuller.java index 9081bde..344697d 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/fast/ASyncPuller.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/fast/ASyncPuller.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils.fast; diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentFramework.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentFramework.java index 6e8cfb1..a7ee892 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentFramework.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentFramework.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils.framework; diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentInterface.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentInterface.java index 5b80dcc..88626fd 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentInterface.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/ContentInterface.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils.framework; diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/JDAOAuth.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/JDAOAuth.java index 9a63263..d58f2b4 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/JDAOAuth.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/JDAOAuth.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils.framework; diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/JsonObjectModifier.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/JsonObjectModifier.java index 50bc091..d65661d 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/JsonObjectModifier.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/JsonObjectModifier.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils.framework; diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java index 3ee4ba9..9379e35 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthFlow.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils.framework; diff --git a/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthManager.java b/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthManager.java index 61617db..468ca0e 100644 --- a/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthManager.java +++ b/src/main/java/net/dec4234/javadestinyapi/utils/framework/OAuthManager.java @@ -1,9 +1,8 @@ /* - * Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarantees of - * any kind, to all wishing to use this software for their benefit. No one may specifically claim credit, or - * ownership of this software without the explicit permission of the author. + * Copyright (c) 2024. dec4234 + * A standard open MIT license applies. Modififcation and usage permitted with credit. No warranties or express guarentees are given in any way. * - * GitHub -> https://github.com/dec4234/JavaDestinyAPI + * Github -> https://github.com/dec4234/JavaDestinyAPI */ package net.dec4234.javadestinyapi.utils.framework;