Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) dec4234 2021. Access is granted, without any express warranties or guarentees 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
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
Expand All @@ -18,7 +17,7 @@
<packaging>jar</packaging>

<name>JavaDestinyAPI</name>
<description>A Java wrapper for bungie.net platform api, allowing users to get data about the video games Destiny and Destiny 2</description>
<description>A Java wrapper for bungie.net platform API, allowing users to get data about the video games Destiny and Destiny 2</description>
<url>https://github.com/dec4234/JavaDestinyAPI</url>

<licenses>
Expand Down Expand Up @@ -51,7 +50,7 @@
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
<version>2.8.9</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
Expand All @@ -62,7 +61,7 @@
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.11.0</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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;

/**
* 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);
}

public APIException(Exception e) {
super(e);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/*
* 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;

/**
* 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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{
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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;

/**
* 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);
}

public JsonParsingError(JsonSyntaxException exception) {
super(exception);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
* Alternatively, the access and/or refresh token has expired
* See {@link net.dec4234.javadestinyapi.utils.framework.OAuthFlow}
*/
public class OAuthUnauthorizedException extends APIException {

public OAuthUnauthorizedException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -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 {

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
27 changes: 13 additions & 14 deletions src/main/java/net/dec4234/javadestinyapi/material/DestinyAPI.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
/*
* 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;

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;
Expand Down Expand Up @@ -132,23 +131,23 @@ 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"));
}

/**
* 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);
}

/**
* 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());
Expand All @@ -162,7 +161,7 @@ private static BungieUser getMemberFromPlatformID(String platformName, String pl
* <p>
* Requires OAuth
*/
public static UserCredential[] getUserCredentials(BungieUser bungieUser) {
public static UserCredential[] getUserCredentials(BungieUser bungieUser) throws APIException {
List<UserCredential> list = new LinkedList<>();

for (JsonElement je : getHttpUtils().urlRequestGETOauth("https://www.bungie.net/Platform/User/GetCredentialTypesForTargetAccount/" + bungieUser.getID() + "/").getAsJsonArray("Response")) {
Expand All @@ -185,7 +184,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;
Expand All @@ -207,7 +206,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();
Expand All @@ -229,7 +228,7 @@ public static BungieUser getUserWithName(String nameAndDiscrim) {
* BungieUser. While searching "Gladd" or "Datto" should return
* multiple.
*/
public static List<BungieUser> searchUsers(String name) {
public static List<BungieUser> searchUsers(String name) throws APIException {
List<BungieUser> users = new ArrayList<>();

JsonObject body = new JsonObject();
Expand Down Expand Up @@ -274,7 +273,7 @@ public static List<BungieUser> 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();

Expand Down Expand Up @@ -325,7 +324,7 @@ private static BungieUser processListOfProfiles(JsonArray jsonArray) {
* Use searchUsers() instead
*/
@Deprecated
public static List<BungieUser> searchGlobalDisplayNames(String prefix) {
public static List<BungieUser> searchGlobalDisplayNames(String prefix) throws APIException {
prefix = StringUtils.httpEncode(prefix);

List<BungieUser> bungieUsers = new ArrayList<>();
Expand Down
Loading