diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..9edf167 --- /dev/null +++ b/build.gradle @@ -0,0 +1,10 @@ +apply plugin: 'signing' + +task deploy(type: Copy, dependsOn: 'compile') { + //from() +} + +task compile(type:Exec) { + workingDir'./' + commandLine 'cmd', '/c','mvn', 'clean', 'install' +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..5eb96d2 --- /dev/null +++ b/gradle.properties @@ -0,0 +1 @@ +signing.keyId=77C00894 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..b5166da Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..6aaa157 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri Sep 04 16:26:44 CEST 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-bin.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..91a7e26 --- /dev/null +++ b/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..8a0b282 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..b74fc8e --- /dev/null +++ b/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'gw2api' diff --git a/src/main/java/me/nithanim/gw2api/v2/GuildWars2Api.java b/src/main/java/me/nithanim/gw2api/v2/GuildWars2Api.java index 85e26a0..25658aa 100644 --- a/src/main/java/me/nithanim/gw2api/v2/GuildWars2Api.java +++ b/src/main/java/me/nithanim/gw2api/v2/GuildWars2Api.java @@ -24,6 +24,10 @@ import me.nithanim.gw2api.v2.api.currencies.CurrenciesResourceImpl; import me.nithanim.gw2api.v2.api.files.FilesResource; import me.nithanim.gw2api.v2.api.files.FilesResourceImpl; +import me.nithanim.gw2api.v2.api.items.Details; +import me.nithanim.gw2api.v2.api.items.ItemInfo; +import me.nithanim.gw2api.v2.api.items.ItemsResource; +import me.nithanim.gw2api.v2.api.items.ItemsResourceImpl; import me.nithanim.gw2api.v2.api.maps.MapsResource; import me.nithanim.gw2api.v2.api.maps.MapsResourceImpl; import me.nithanim.gw2api.v2.api.pvp.PvpResource; @@ -42,6 +46,7 @@ import me.nithanim.gw2api.v2.util.gson.EnumTypeAdapterFactory; import me.nithanim.gw2api.v2.util.gson.facts.FactJsonDeserializer; import me.nithanim.gw2api.v2.util.gson.facts.TraitedFactJsonDeserializer; +import me.nithanim.gw2api.v2.util.gson.items.ItemInfoJsonDeserializer; import me.nithanim.gw2api.v2.util.time.DateTimeAdapter; public class GuildWars2Api { @@ -56,6 +61,7 @@ public class GuildWars2Api { ) .registerTypeAdapter(Fact.class, new FactJsonDeserializer()) .registerTypeAdapter(TraitedFact.class, new TraitedFactJsonDeserializer()) + .registerTypeAdapter(ItemInfo.class, new ItemInfoJsonDeserializer()) .create(); private final Client client; @@ -67,6 +73,7 @@ public class GuildWars2Api { private final ContinentsResource continentsResource; private final CurrenciesResource currenciesResource; private final FilesResource filesResource; + private final ItemsResource itemsResource; private final MapsResource mapsResource; private final PvpResource pvpResource; private final RecipesResource recipesResource; @@ -92,6 +99,7 @@ public GuildWars2Api(GuildWars2ApiConfig config) { continentsResource = new ContinentsResourceImpl(baseWebResource); currenciesResource = new CurrenciesResourceImpl(baseWebResource); filesResource = new FilesResourceImpl(baseWebResource); + itemsResource = new ItemsResourceImpl(baseWebResource); mapsResource = new MapsResourceImpl(baseWebResource); pvpResource = new PvpResource(baseWebResource); recipesResource = new RecipesResourceImpl(baseWebResource); @@ -205,6 +213,19 @@ public FilesResource files() { return filesResource; } + /** + * This resource returns information about items that were discovered by + * players in the game. + * + * @return + * + * @see + * GW2Wiki + */ + public ItemsResource items() { + return itemsResource; + } + /** * This resource returns details about maps in the game, including details * about floor and translation data on how to translate between world @@ -218,7 +239,7 @@ public FilesResource files() { public MapsResource maps() { return mapsResource; } - + public PvpResource pvp() { return pvpResource; } diff --git a/src/main/java/me/nithanim/gw2api/v2/Main.java b/src/main/java/me/nithanim/gw2api/v2/Main.java new file mode 100644 index 0000000..39a2def --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/Main.java @@ -0,0 +1,82 @@ +package me.nithanim.gw2api.v2; + +import java.util.Arrays; +import me.nithanim.gw2api.v2.api.commerce.exchange.Transaction; +import me.nithanim.gw2api.v2.api.characters.Character; +import me.nithanim.gw2api.v2.api.characters.SpecializationType; +import me.nithanim.gw2api.v2.api.commerce.listings.Listing; +import me.nithanim.gw2api.v2.common.Item; + +public class Main { + + public static void main(String[] args) { + //String apikey = "F735A191-002A-1341-862C-AFB2CC0299C9D97D20C1-4C17-4626-ADD9-65C557B7027A"; + String apikey = "49E407D3-4682-7646-AFDF-4F249B09F67451FCEF55-48F2-467E-922D-9AA0B38A30D0"; + + GuildWars2Api gw2api = new GuildWars2Api(); + //System.out.println(Arrays.toString(gw2api.account().bank(apikey))); + //System.out.println(Arrays.toString(gw2api.account().dyes(apikey))); + //System.out.println(Arrays.toString(gw2api.account().materials(apikey))); + //System.out.println(Arrays.toString(gw2api.account().skins(apikey))); + //System.out.println(Arrays.toString(gw2api.account().wallet(apikey))); + //System.out.println(Arrays.toString(gw2api.colors().get())); + //System.out.println(gw2api.colors().get(1)); + //System.out.println(gw2api.commerce().exchange().coinsPerGem(100)); + //System.out.println(Arrays.toString(gw2api.commerce().listings().get())); + //System.out.println(gw2api.commerce().listings().get(100)); + //System.out.println(Arrays.toString(gw2api.commerce().listings().get(new int[] {100, 50}))); + //System.out.println(Arrays.toString(gw2api.currencies().getOverview())); + //System.out.println(gw2api.currencies().get(1)); + //System.out.println(Arrays.toString(gw2api.currencies().get(new int[] {2, 3}, "de"))); + //int[] allListingsAvailable = gw2api.commerce().listings().getOverview(); + //Listing listing = gw2api.commerce().listings().get(allListingsAvailable[0]); + //System.out.println(listing.toString()); + /*Transaction[] transactions = gw2api + .commerce() + .transactions() + .historyBuys(apikey);*/ + //System.out.println(gw2api.account().get(apikey).getName()); + //System.out.println(Arrays.toString(gw2api.account().bank().get(apikey))); + //System.out.println(Arrays.toString(gw2api.account().materials().get(apikey))); + //System.out.println("Build: " + gw2api.build().get().getId()); + //Character c = gw2api.character().get("Nindari", apikey); + //System.out.println(Arrays.toString(c.getBags())); + + //System.out.println(Arrays.toString(gw2api.commerce().prices().getOverview())); + //System.out.println(gw2api.commerce().prices().get(24)); + //System.out.println(Arrays.toString(gw2api.commerce().prices().get(new int[] {24, 68}))); + + //System.out.println(Arrays.toString(gw2api.recipes().getOverview())); + //System.out.println(gw2api.recipes().get(7319)); + //System.out.println(Arrays.toString(gw2api.recipes().get(new int[] {7319, 50}))); + + //System.out.println(Arrays.toString(gw2api.recipes().searchByInput(46731))); + //System.out.println(Arrays.toString(gw2api.recipes().searchByOutput(50065))); + + //System.out.println(Arrays.toString(gw2api.characters().get("Nindari", "49E407D3-4682-7646-AFDF-4F249B09F67451FCEF55-48F2-467E-922D-9AA0B38A30D0").getSpecializations().get(SpecializationType.PVE))); + + //System.out.println(gw2api.skins().get(10, "fr")); + + //System.out.println(gw2api.traits().get(214)); + + //System.out.println(Arrays.toString(gw2api.files().getAll())); + //System.out.println(Arrays.toString(gw2api.maps().get(new int[] {15, 17}, "fr"))); + + + //System.out.println(gw2api.continents().floors(1).regions(regionId)); + //System.out.println(gw2api.continents().floors(1).get(5)); + + //System.out.println(Arrays.toString(gw2api.pvp().games().getOverview(apikey))); + + System.out.println(gw2api.items().get(12452)); + + /*System.out.println(Arrays.toString(gw2api.worlds().getOverview())); + System.out.println(gw2api.worlds().get(2206)); + System.out.println(gw2api.worlds().get(2206).isEurope()); + System.out.println(gw2api.worlds().get(2206).isNorthAmerica()); + System.out.println(gw2api.worlds().get(2206).isGerman()); + System.out.println(gw2api.worlds().get(2102).isFrench());*/ + //System.out.println(gw2api.worlds().get(2206, "sp")); + //System.out.println(Arrays.toString(gw2api.worlds().get(new int[] {1001, 2206}))); + } +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/account/AccountResource.java b/src/main/java/me/nithanim/gw2api/v2/api/account/AccountResource.java index add794c..4345556 100644 --- a/src/main/java/me/nithanim/gw2api/v2/api/account/AccountResource.java +++ b/src/main/java/me/nithanim/gw2api/v2/api/account/AccountResource.java @@ -3,7 +3,7 @@ import com.sun.jersey.api.client.WebResource; import me.nithanim.gw2api.v2.ApiEndpoint; import me.nithanim.gw2api.v2.ApiMidpoint; -import me.nithanim.gw2api.v2.api.items.Item; +import me.nithanim.gw2api.v2.common.Item; import me.nithanim.gw2api.v2.util.rest.RequestHelper; /** diff --git a/src/main/java/me/nithanim/gw2api/v2/api/characters/Bag.java b/src/main/java/me/nithanim/gw2api/v2/api/characters/Bag.java index 94fecbf0..06b36bb 100644 --- a/src/main/java/me/nithanim/gw2api/v2/api/characters/Bag.java +++ b/src/main/java/me/nithanim/gw2api/v2/api/characters/Bag.java @@ -1,6 +1,6 @@ package me.nithanim.gw2api.v2.api.characters; -import me.nithanim.gw2api.v2.api.items.Item; +import me.nithanim.gw2api.v2.common.Item; import org.apache.commons.lang.builder.ToStringBuilder; public class Bag { diff --git a/src/main/java/me/nithanim/gw2api/v2/api/characters/WornItem.java b/src/main/java/me/nithanim/gw2api/v2/api/characters/WornItem.java index d7c5cb0..070d45c 100644 --- a/src/main/java/me/nithanim/gw2api/v2/api/characters/WornItem.java +++ b/src/main/java/me/nithanim/gw2api/v2/api/characters/WornItem.java @@ -1,7 +1,7 @@ package me.nithanim.gw2api.v2.api.characters; import java.util.Objects; -import me.nithanim.gw2api.v2.api.items.Item; +import me.nithanim.gw2api.v2.common.Item; public class WornItem extends Item { private Slot slot; diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/Details.java b/src/main/java/me/nithanim/gw2api/v2/api/items/Details.java new file mode 100644 index 0000000..435bfae --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/Details.java @@ -0,0 +1,5 @@ +package me.nithanim.gw2api.v2.api.items; + +public interface Details { + +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/GameType.java b/src/main/java/me/nithanim/gw2api/v2/api/items/GameType.java new file mode 100644 index 0000000..6e5c659 --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/GameType.java @@ -0,0 +1,5 @@ +package me.nithanim.gw2api.v2.api.items; + +public enum GameType { + ACTIVITY, DUNGEON, PVE, PVP, PVP_LOBBY, WVW; +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/ItemInfo.java b/src/main/java/me/nithanim/gw2api/v2/api/items/ItemInfo.java new file mode 100644 index 0000000..09c2433 --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/ItemInfo.java @@ -0,0 +1,111 @@ +package me.nithanim.gw2api.v2.api.items; + +import java.util.Arrays; +import java.util.Objects; +import me.nithanim.gw2api.v2.common.BasicItem; +import org.apache.commons.lang.builder.ToStringBuilder; + +public class ItemInfo extends BasicItem { + private String name; + private String icon; + private String description; + private ItemType type; + private ItemRarity rarity; + private int level; + private int vendorValue; + private int defaultSkin = -1; + private String[] flags; + private String[] restrictions; + private Details details; + + public String getName() { + return name; + } + + public String getIcon() { + return icon; + } + + public String getDescription() { + return description; + } + + public ItemType getType() { + return type; + } + + public ItemRarity getRarity() { + return rarity; + } + + public int getLevel() { + return level; + } + + public int getVendorValue() { + return vendorValue; + } + + public int getDefaultSkin() { + return defaultSkin; + } + + public String[] getFlags() { + return flags; + } + + public String[] getRestrictions() { + return restrictions; + } + + public Details getDetails() { + return details; + } + + void setDetails(Details details) { + this.details = details; + } + + @Override + public int hashCode() { + int hash = super.hashCode(); + hash = 67 * hash + Objects.hashCode(this.name); + hash = 67 * hash + Objects.hashCode(this.icon); + hash = 67 * hash + Objects.hashCode(this.description); + hash = 67 * hash + Objects.hashCode(this.type); + hash = 67 * hash + Objects.hashCode(this.rarity); + hash = 67 * hash + this.level; + hash = 67 * hash + this.vendorValue; + hash = 67 * hash + this.defaultSkin; + hash = 67 * hash + Arrays.deepHashCode(this.flags); + hash = 67 * hash + Arrays.deepHashCode(this.restrictions); + hash = 67 * hash + Objects.hashCode(this.details); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ItemInfo)) { + return false; + } else if (this == obj) { + return true; + } + final ItemInfo other = (ItemInfo) obj; + return Objects.equals(this.name, other.name) + && Objects.equals(this.icon, other.icon) + && Objects.equals(this.description, other.description) + && this.type == other.type + && this.rarity == other.rarity + && this.level == other.level + && this.vendorValue == other.vendorValue + && this.defaultSkin == other.defaultSkin + && Arrays.deepEquals(this.flags, other.flags) + && Arrays.deepEquals(this.restrictions, other.restrictions) + && Objects.equals(this.details, other.details); + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/ItemRarity.java b/src/main/java/me/nithanim/gw2api/v2/api/items/ItemRarity.java new file mode 100644 index 0000000..01fd1fd --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/ItemRarity.java @@ -0,0 +1,5 @@ +package me.nithanim.gw2api.v2.api.items; + +public enum ItemRarity { + JUNK, BASIC, FINE, MASTERWORK, RARE, EXOTIC, ASCENDED, LEGENDARY; +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/ItemType.java b/src/main/java/me/nithanim/gw2api/v2/api/items/ItemType.java new file mode 100644 index 0000000..aad764c --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/ItemType.java @@ -0,0 +1,27 @@ +package me.nithanim.gw2api.v2.api.items; + +import me.nithanim.gw2api.v2.api.items.details.*; + +public enum ItemType { + ARMOR(ArmorDetails.class), BACK(BackDetails.class), BAG(BackDetails.class), + CONSUMABLE(ConsumeableDetails.class), CONTAINER(ContainerDetails.class), + CRAFTING_MATERIAL, GATHERING(GatheringToolsDetails.class), + GIZMO(GizmoDetails.class), MINI_PET, TOOL(SalvageKitDetails.class), + TRAIT, TRINKET(TrinketDetails.class), TROPHY, + UPGRADE_COMPONENT(UpgradeComponentDetails.class), + WEAPON(WeaponDetails.class); + + private final Class detailsClass; + + private ItemType() { + this(null); + } + + private ItemType(Class detailsClass) { + this.detailsClass = detailsClass; + } + + public Class getDetailsClass() { + return detailsClass; + } +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/ItemsResource.java b/src/main/java/me/nithanim/gw2api/v2/api/items/ItemsResource.java new file mode 100644 index 0000000..64ad3fa --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/ItemsResource.java @@ -0,0 +1,13 @@ +package me.nithanim.gw2api.v2.api.items; + +public interface ItemsResource { + int[] getOverview(); + + ItemInfo get(int id); + + ItemInfo get(int id, String language); + + ItemInfo[] get(int[] ids); + + ItemInfo[] get(int[] ids, String language); +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/ItemsResourceImpl.java b/src/main/java/me/nithanim/gw2api/v2/api/items/ItemsResourceImpl.java new file mode 100644 index 0000000..41dc780 --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/ItemsResourceImpl.java @@ -0,0 +1,12 @@ +package me.nithanim.gw2api.v2.api.items; + +import com.sun.jersey.api.client.WebResource; +import me.nithanim.gw2api.v2.util.rest.IdsResourceBase; + +public class ItemsResourceImpl extends IdsResourceBase implements ItemsResource { + + public ItemsResourceImpl(WebResource webResource) { + super(webResource.path("items"), ItemInfo.class, int[].class); + } + +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/details/ArmorDetails.java b/src/main/java/me/nithanim/gw2api/v2/api/items/details/ArmorDetails.java new file mode 100644 index 0000000..ea46683 --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/details/ArmorDetails.java @@ -0,0 +1,82 @@ +package me.nithanim.gw2api.v2.api.items.details; + +import java.util.Arrays; +import java.util.Objects; +import me.nithanim.gw2api.v2.api.items.Details; +import me.nithanim.gw2api.v2.common.WeightClass; +import org.apache.commons.lang.builder.ToStringBuilder; + +public class ArmorDetails implements Details { + private ArmorSlotType type; + private WeightClass weightClass; + private int defence; + private InfusionSlot[] infusionSlots; + private InfixUpgrade infixUpgrade; + private int suffixItemId = -1; + private String secondarySuffixItemId; + + public ArmorSlotType getType() { + return type; + } + + public WeightClass getWeightClass() { + return weightClass; + } + + public int getDefence() { + return defence; + } + + public InfusionSlot[] getInfusionSlots() { + return infusionSlots; + } + + public InfixUpgrade getInfixUpgrade() { + return infixUpgrade; + } + + public int getSuffixItemId() { + return suffixItemId; + } + + public String getSecondarySuffixItemId() { + return secondarySuffixItemId; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 43 * hash + Objects.hashCode(this.type); + hash = 43 * hash + Objects.hashCode(this.weightClass); + hash = 43 * hash + this.defence; + hash = 43 * hash + Arrays.deepHashCode(this.infusionSlots); + hash = 43 * hash + Objects.hashCode(this.infixUpgrade); + hash = 43 * hash + this.suffixItemId; + hash = 43 * hash + Objects.hashCode(this.secondarySuffixItemId); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final ArmorDetails other = (ArmorDetails) obj; + return this.type == other.type + && this.weightClass == other.weightClass + && this.defence == other.defence + && Arrays.deepEquals(this.infusionSlots, other.infusionSlots) + && Objects.equals(this.infixUpgrade, other.infixUpgrade) + && this.suffixItemId == other.suffixItemId + && Objects.equals(this.secondarySuffixItemId, other.secondarySuffixItemId); + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(type); + } + + public static enum ArmorSlotType { + BOOTS, COAT, GLOVES, HELM, HELM_AQUATIC, LEGGINGS, SHOULDERS; + } +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/details/BackDetails.java b/src/main/java/me/nithanim/gw2api/v2/api/items/details/BackDetails.java new file mode 100644 index 0000000..81329d6 --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/details/BackDetails.java @@ -0,0 +1,56 @@ +package me.nithanim.gw2api.v2.api.items.details; + +import java.util.Arrays; +import java.util.Objects; +import me.nithanim.gw2api.v2.api.items.Details; +import org.apache.commons.lang.builder.ToStringBuilder; + +public class BackDetails implements Details { + private InfusionSlot[] infusionSlots; + private InfixUpgrade infixUpgrade; + private int suffixItemId = -1; + private String secondarySuffixItemId; + + public InfusionSlot[] getInfusionSlots() { + return infusionSlots; + } + + public InfixUpgrade getInfixUpgrade() { + return infixUpgrade; + } + + public int getSuffixItemId() { + return suffixItemId; + } + + public String getSecondarySuffixItemId() { + return secondarySuffixItemId; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 17 * hash + Arrays.deepHashCode(this.infusionSlots); + hash = 17 * hash + Objects.hashCode(this.infixUpgrade); + hash = 17 * hash + this.suffixItemId; + hash = 17 * hash + Objects.hashCode(this.secondarySuffixItemId); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final BackDetails other = (BackDetails) obj; + return Arrays.deepEquals(this.infusionSlots, other.infusionSlots) + && Objects.equals(this.infixUpgrade, other.infixUpgrade) + && this.suffixItemId == other.suffixItemId + && Objects.equals(this.secondarySuffixItemId, other.secondarySuffixItemId); + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/details/BagDetails.java b/src/main/java/me/nithanim/gw2api/v2/api/items/details/BagDetails.java new file mode 100644 index 0000000..0d45e24 --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/details/BagDetails.java @@ -0,0 +1,40 @@ +package me.nithanim.gw2api.v2.api.items.details; + +import me.nithanim.gw2api.v2.api.items.Details; +import org.apache.commons.lang.builder.ToStringBuilder; + +public class BagDetails implements Details { + private int size; + private boolean noSellOrSort; + + public int getSize() { + return size; + } + + public boolean isNoSellOrSort() { + return noSellOrSort; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 53 * hash + this.size; + hash = 53 * hash + (this.noSellOrSort ? 1 : 0); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final BagDetails other = (BagDetails) obj; + return this.size == other.size + && this.noSellOrSort == other.noSellOrSort; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/details/ConsumeableDetails.java b/src/main/java/me/nithanim/gw2api/v2/api/items/details/ConsumeableDetails.java new file mode 100644 index 0000000..effcc1e --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/details/ConsumeableDetails.java @@ -0,0 +1,74 @@ +package me.nithanim.gw2api.v2.api.items.details; + +import java.util.Objects; +import me.nithanim.gw2api.v2.api.items.Details; +import org.apache.commons.lang.builder.ToStringBuilder; + +public class ConsumeableDetails implements Details { + private ConsumeableType type; + private String description; + private int durationMs = -1; + private String unlockType; + private int colorId = -1; + private int recipeId = -1; + + public ConsumeableType getType() { + return type; + } + + public String getDescription() { + return description; + } + + public int getDurationMs() { + return durationMs; + } + + public String getUnlockType() { + return unlockType; + } + + public int getColorId() { + return colorId; + } + + public int getRecipeId() { + return recipeId; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 43 * hash + Objects.hashCode(this.type); + hash = 43 * hash + Objects.hashCode(this.description); + hash = 43 * hash + this.durationMs; + hash = 43 * hash + Objects.hashCode(this.unlockType); + hash = 43 * hash + this.colorId; + hash = 43 * hash + this.recipeId; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final ConsumeableDetails other = (ConsumeableDetails) obj; + return this.type == other.type + && Objects.equals(this.description, other.description) + && this.durationMs == other.durationMs + && Objects.equals(this.unlockType, other.unlockType) + && this.colorId == other.colorId + && this.recipeId == other.recipeId; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + public static enum ConsumeableType { + APPEARANCE_CHANGE, BOOZE, CONTRACT_NPC, FOOD, GENERIC, HALLOWEEN, + IMMEDIATE, TRANSMUTATION, UNLOCK, UPGRADE_REMOVAL, UTILITY; + } +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/details/ContainerDetails.java b/src/main/java/me/nithanim/gw2api/v2/api/items/details/ContainerDetails.java new file mode 100644 index 0000000..7c541dd --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/details/ContainerDetails.java @@ -0,0 +1,38 @@ +package me.nithanim.gw2api.v2.api.items.details; + +import java.util.Objects; +import me.nithanim.gw2api.v2.api.items.Details; +import org.apache.commons.lang.builder.ToStringBuilder; + +public class ContainerDetails implements Details { + private ContainerType type; + + public ContainerType getType() { + return type; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 97 * hash + Objects.hashCode(this.type); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final ContainerDetails other = (ContainerDetails) obj; + return this.type == other.type; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + public static enum ContainerType { + DEFAULT, GIFT_BOX, OPEN_UI; + } +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/details/GatheringToolsDetails.java b/src/main/java/me/nithanim/gw2api/v2/api/items/details/GatheringToolsDetails.java new file mode 100644 index 0000000..8856ee9 --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/details/GatheringToolsDetails.java @@ -0,0 +1,38 @@ +package me.nithanim.gw2api.v2.api.items.details; + +import java.util.Objects; +import me.nithanim.gw2api.v2.api.items.Details; +import org.apache.commons.lang.builder.ToStringBuilder; + +public class GatheringToolsDetails implements Details { + private GatheringToolsType type; + + public GatheringToolsType getType() { + return type; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 97 * hash + Objects.hashCode(this.type); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final GatheringToolsDetails other = (GatheringToolsDetails) obj; + return this.type == other.type; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + public static enum GatheringToolsType { + FORAGING, LOGGING, MINING; + } +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/details/GizmoDetails.java b/src/main/java/me/nithanim/gw2api/v2/api/items/details/GizmoDetails.java new file mode 100644 index 0000000..de86d46 --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/details/GizmoDetails.java @@ -0,0 +1,38 @@ +package me.nithanim.gw2api.v2.api.items.details; + +import java.util.Objects; +import me.nithanim.gw2api.v2.api.items.Details; +import org.apache.commons.lang.builder.ToStringBuilder; + +public class GizmoDetails implements Details { + private GizmoType type; + + public GizmoType getType() { + return type; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 97 * hash + Objects.hashCode(this.type); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final GizmoDetails other = (GizmoDetails) obj; + return this.type == other.type; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + public static enum GizmoType { + DEFAULT, CONTAINER_KEY, RENTABLE_CONTRACT_NPC, UNLIMITED_CONSUMEABLE; + } +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/details/InfixUpgrade.java b/src/main/java/me/nithanim/gw2api/v2/api/items/details/InfixUpgrade.java new file mode 100644 index 0000000..4c09591 --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/details/InfixUpgrade.java @@ -0,0 +1,113 @@ +package me.nithanim.gw2api.v2.api.items.details; + +import java.util.Arrays; +import java.util.Objects; +import org.apache.commons.lang.builder.ToStringBuilder; + +public class InfixUpgrade { + private Attribute[] attributes; + private Buff buff; + + public Attribute[] getAttributes() { + return attributes; + } + + public Buff getBuff() { + return buff; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 89 * hash + Arrays.deepHashCode(this.attributes); + hash = 89 * hash + Objects.hashCode(this.buff); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final InfixUpgrade other = (InfixUpgrade) obj; + return Arrays.deepEquals(this.attributes, other.attributes) + && Objects.equals(this.buff, other.buff); + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + public static class Attribute { + private AttributeType attribute; + private int modifier; + + public AttributeType getAttribute() { + return attribute; + } + + public int getModifier() { + return modifier; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 37 * hash + Objects.hashCode(this.attribute); + hash = 37 * hash + this.modifier; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final Attribute other = (Attribute) obj; + return this.attribute == other.attribute + && this.modifier == other.modifier; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + public static enum AttributeType { + CONDITION_DAMAGE, CRIT_DAMAGE, HEALING, POWER, PRECISION, TOUGHNESS, + VITALITY; + } + } + + public static class Buff { + private int skillId; + private String description; + + @Override + public int hashCode() { + int hash = 5; + hash = 97 * hash + this.skillId; + hash = 97 * hash + Objects.hashCode(this.description); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final Buff other = (Buff) obj; + return this.skillId == other.skillId + && Objects.equals(this.description, other.description); + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + } +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/details/InfusionSlot.java b/src/main/java/me/nithanim/gw2api/v2/api/items/details/InfusionSlot.java new file mode 100644 index 0000000..86ee648 --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/details/InfusionSlot.java @@ -0,0 +1,42 @@ +package me.nithanim.gw2api.v2.api.items.details; + +import me.nithanim.gw2api.v2.common.InfusionType; +import java.util.Arrays; +import org.apache.commons.lang.builder.ToStringBuilder; + +public class InfusionSlot { + private InfusionType[] flags; + private int itemId; + + public InfusionType[] getFlags() { + return flags; + } + + public int getItemId() { + return itemId; + } + + @Override + public int hashCode() { + int hash = 3; + hash = 47 * hash + Arrays.deepHashCode(this.flags); + hash = 47 * hash + this.itemId; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final InfusionSlot other = (InfusionSlot) obj; + return Arrays.deepEquals(this.flags, other.flags) + && this.itemId == other.itemId; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/details/SalvageKitDetails.java b/src/main/java/me/nithanim/gw2api/v2/api/items/details/SalvageKitDetails.java new file mode 100644 index 0000000..f076df3 --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/details/SalvageKitDetails.java @@ -0,0 +1,45 @@ +package me.nithanim.gw2api.v2.api.items.details; + +import java.util.Objects; +import me.nithanim.gw2api.v2.api.items.Details; +import org.apache.commons.lang.builder.ToStringBuilder; + +public class SalvageKitDetails implements Details { + private SalvageKitType type; + private int charges; + + public SalvageKitType getType() { + return type; + } + + public int getCharges() { + return charges; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 17 * hash + Objects.hashCode(this.type); + hash = 17 * hash + this.charges; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final SalvageKitDetails other = (SalvageKitDetails) obj; + return this.type == other.type + && this.charges == other.charges; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + public static enum SalvageKitType { + SALVAGE; + } +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/details/TrinketDetails.java b/src/main/java/me/nithanim/gw2api/v2/api/items/details/TrinketDetails.java new file mode 100644 index 0000000..c0c2725 --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/details/TrinketDetails.java @@ -0,0 +1,67 @@ +package me.nithanim.gw2api.v2.api.items.details; + +import java.util.Arrays; +import java.util.Objects; +import me.nithanim.gw2api.v2.api.items.Details; +import org.apache.commons.lang.builder.ToStringBuilder; + +public class TrinketDetails implements Details { + private TrinketType type; + private InfusionSlot[] infusionSlots; + private InfixUpgrade infixUpgrade; + private int suffixItemId = -1; + private String secondarySuffixItemId; + + public TrinketType getType() { + return type; + } + + public InfusionSlot[] getInfusionSlots() { + return infusionSlots; + } + + public InfixUpgrade getInfixUpgrade() { + return infixUpgrade; + } + + public int getSuffixItemId() { + return suffixItemId; + } + + public String getSecondarySuffixItemId() { + return secondarySuffixItemId; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 79 * hash + Objects.hashCode(this.type); + hash = 79 * hash + Arrays.deepHashCode(this.infusionSlots); + hash = 79 * hash + Objects.hashCode(this.infixUpgrade); + hash = 79 * hash + this.suffixItemId; + hash = 79 * hash + Objects.hashCode(this.secondarySuffixItemId); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final TrinketDetails other = (TrinketDetails) obj; + return this.type != other.type + && Arrays.deepEquals(this.infusionSlots, other.infusionSlots) + && Objects.equals(this.infixUpgrade, other.infixUpgrade) + && this.suffixItemId == other.suffixItemId + && Objects.equals(this.secondarySuffixItemId, other.secondarySuffixItemId); + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + public static enum TrinketType { + ACCESSORY, AMULET, RING; + } +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/details/UpgradeComponentDetails.java b/src/main/java/me/nithanim/gw2api/v2/api/items/details/UpgradeComponentDetails.java new file mode 100644 index 0000000..79a6ff3 --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/details/UpgradeComponentDetails.java @@ -0,0 +1,75 @@ +package me.nithanim.gw2api.v2.api.items.details; + +import java.util.Arrays; +import java.util.Objects; +import me.nithanim.gw2api.v2.api.items.Details; +import me.nithanim.gw2api.v2.common.InfusionType; +import org.apache.commons.lang.builder.ToStringBuilder; + +public class UpgradeComponentDetails implements Details { + private UpgradeComponentType type; + private String flags; + private InfusionType[] infusionUpgradeFlags; + private String suffix; + private InfixUpgrade infixUpgrade; + private String[] bonuses; + + public UpgradeComponentType getType() { + return type; + } + + public String getFlags() { + return flags; + } + + public InfusionType[] getInfusionUpgradeFlags() { + return infusionUpgradeFlags; + } + + public String getSuffix() { + return suffix; + } + + public InfixUpgrade getInfixUpgrade() { + return infixUpgrade; + } + + public String[] getBonuses() { + return bonuses; + } + + @Override + public int hashCode() { + int hash = 7; + hash = 31 * hash + Objects.hashCode(this.type); + hash = 31 * hash + Objects.hashCode(this.flags); + hash = 31 * hash + Arrays.deepHashCode(this.infusionUpgradeFlags); + hash = 31 * hash + Objects.hashCode(this.suffix); + hash = 31 * hash + Objects.hashCode(this.infixUpgrade); + hash = 31 * hash + Arrays.deepHashCode(this.bonuses); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final UpgradeComponentDetails other = (UpgradeComponentDetails) obj; + return this.type == other.type + && Objects.equals(this.flags, other.flags) + && Arrays.deepEquals(this.infusionUpgradeFlags, other.infusionUpgradeFlags) + && Objects.equals(this.suffix, other.suffix) + && Objects.equals(this.infixUpgrade, other.infixUpgrade) + && Arrays.deepEquals(this.bonuses, other.bonuses); + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + public static enum UpgradeComponentType { + DEFAULT, GEM, RUNE, SIGIL; + } +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/details/WeaponDetails.java b/src/main/java/me/nithanim/gw2api/v2/api/items/details/WeaponDetails.java new file mode 100644 index 0000000..e6b06e8 --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/api/items/details/WeaponDetails.java @@ -0,0 +1,101 @@ +package me.nithanim.gw2api.v2.api.items.details; + +import java.util.Arrays; +import java.util.Objects; +import me.nithanim.gw2api.v2.api.items.Details; +import org.apache.commons.lang.builder.ToStringBuilder; + +public class WeaponDetails implements Details { + private WeaponType type; + private DamageType damageType; + private int minPower; + private int maxPower; + private int defense; + private InfusionSlot[] infusionSlots; + private InfixUpgrade infixUpgrade; + private int suffixItemId; + private String secondarySuffixItemId; + + public WeaponType getType() { + return type; + } + + public DamageType getDamageType() { + return damageType; + } + + public int getMinPower() { + return minPower; + } + + public int getMaxPower() { + return maxPower; + } + + public int getDefense() { + return defense; + } + + public InfusionSlot[] getInfusionSlots() { + return infusionSlots; + } + + public InfixUpgrade getInfixUpgrade() { + return infixUpgrade; + } + + public int getSuffixItemId() { + return suffixItemId; + } + + public String getSecondarySuffixItemId() { + return secondarySuffixItemId; + } + + @Override + public int hashCode() { + int hash = 5; + hash = 29 * hash + Objects.hashCode(this.type); + hash = 29 * hash + Objects.hashCode(this.damageType); + hash = 29 * hash + this.minPower; + hash = 29 * hash + this.maxPower; + hash = 29 * hash + this.defense; + hash = 29 * hash + Arrays.deepHashCode(this.infusionSlots); + hash = 29 * hash + Objects.hashCode(this.infixUpgrade); + hash = 29 * hash + this.suffixItemId; + hash = 29 * hash + Objects.hashCode(this.secondarySuffixItemId); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null || getClass() != obj.getClass()) { + return false; + } + final WeaponDetails other = (WeaponDetails) obj; + return this.type == other.type + && this.damageType == other.damageType + && this.minPower == other.minPower + && this.maxPower == other.maxPower + && this.defense == other.defense + && Arrays.deepEquals(this.infusionSlots, other.infusionSlots) + && Objects.equals(this.infixUpgrade, other.infixUpgrade) + && this.suffixItemId != other.suffixItemId + && Objects.equals(this.secondarySuffixItemId, other.secondarySuffixItemId); + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this); + } + + public static enum WeaponType { + AXE, DAGGER, MACE, PISTOL, SCEPTER, SWORD, FOCUS, SHIELD, TORCH, + WARHORN, GREATSWORD, HAMMER, LONG_BOW, RIFLE, SHORT_BOW, STAFF, HARPOON, + SPEARGUN, TRIDENT, LARGE_BUNDLE, SMALL_BUNDLE, TOY, TWO_HANDED_TOY; + } + + public static enum DamageType { + FIRE, ICE, LIGHTNING, PHYSICAL, CHOKING; + } +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/recipes/Recipe.java b/src/main/java/me/nithanim/gw2api/v2/api/recipes/Recipe.java index 889ab43..ffb7b68 100644 --- a/src/main/java/me/nithanim/gw2api/v2/api/recipes/Recipe.java +++ b/src/main/java/me/nithanim/gw2api/v2/api/recipes/Recipe.java @@ -3,7 +3,7 @@ import java.util.Arrays; import java.util.Objects; import me.nithanim.gw2api.v2.api.characters.CraftingDiscipline; -import me.nithanim.gw2api.v2.api.items.BasicItem; +import me.nithanim.gw2api.v2.common.BasicItem; import org.apache.commons.lang.builder.ToStringBuilder; public class Recipe { diff --git a/src/main/java/me/nithanim/gw2api/v2/api/skins/SkinDetails.java b/src/main/java/me/nithanim/gw2api/v2/api/skins/SkinDetails.java index 1e721f6..e10433e 100644 --- a/src/main/java/me/nithanim/gw2api/v2/api/skins/SkinDetails.java +++ b/src/main/java/me/nithanim/gw2api/v2/api/skins/SkinDetails.java @@ -1,18 +1,19 @@ package me.nithanim.gw2api.v2.api.skins; import java.util.Objects; +import me.nithanim.gw2api.v2.common.WeightClass; import org.apache.commons.lang.builder.ToStringBuilder; public class SkinDetails { private String type; - private String weightClass; + private WeightClass weightClass; private String damageType; public String getType() { return type; } - public String getWeightClass() { + public WeightClass getWeightClass() { return weightClass; } diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/BasicItem.java b/src/main/java/me/nithanim/gw2api/v2/common/BasicItem.java similarity index 91% rename from src/main/java/me/nithanim/gw2api/v2/api/items/BasicItem.java rename to src/main/java/me/nithanim/gw2api/v2/common/BasicItem.java index f44022a..365afb2 100644 --- a/src/main/java/me/nithanim/gw2api/v2/api/items/BasicItem.java +++ b/src/main/java/me/nithanim/gw2api/v2/common/BasicItem.java @@ -1,8 +1,8 @@ -package me.nithanim.gw2api.v2.api.items; +package me.nithanim.gw2api.v2.common; public class BasicItem { private int id; - private int count; + private int count = 1; public int getId() { return id; diff --git a/src/main/java/me/nithanim/gw2api/v2/common/InfusionType.java b/src/main/java/me/nithanim/gw2api/v2/common/InfusionType.java new file mode 100644 index 0000000..e8e3a3d --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/common/InfusionType.java @@ -0,0 +1,5 @@ +package me.nithanim.gw2api.v2.common; + +public enum InfusionType { + DEFENSE, OFFENSE, UTILITY; +} diff --git a/src/main/java/me/nithanim/gw2api/v2/api/items/Item.java b/src/main/java/me/nithanim/gw2api/v2/common/Item.java similarity index 96% rename from src/main/java/me/nithanim/gw2api/v2/api/items/Item.java rename to src/main/java/me/nithanim/gw2api/v2/common/Item.java index 81b973d..09d9fe2 100644 --- a/src/main/java/me/nithanim/gw2api/v2/api/items/Item.java +++ b/src/main/java/me/nithanim/gw2api/v2/common/Item.java @@ -1,4 +1,4 @@ -package me.nithanim.gw2api.v2.api.items; +package me.nithanim.gw2api.v2.common; import java.util.Arrays; diff --git a/src/main/java/me/nithanim/gw2api/v2/common/WeightClass.java b/src/main/java/me/nithanim/gw2api/v2/common/WeightClass.java new file mode 100644 index 0000000..7806bb1 --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/common/WeightClass.java @@ -0,0 +1,5 @@ +package me.nithanim.gw2api.v2.common; + +public enum WeightClass { + HEAVY, MEDIUM, LIGHT, CLOTHING; +} diff --git a/src/main/java/me/nithanim/gw2api/v2/util/gson/items/ItemInfoJsonDeserializer.java b/src/main/java/me/nithanim/gw2api/v2/util/gson/items/ItemInfoJsonDeserializer.java new file mode 100644 index 0000000..e1b6b71 --- /dev/null +++ b/src/main/java/me/nithanim/gw2api/v2/util/gson/items/ItemInfoJsonDeserializer.java @@ -0,0 +1,73 @@ +package me.nithanim.gw2api.v2.util.gson.items; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import java.lang.reflect.Field; +import java.lang.reflect.Type; +import java.util.HashMap; +import java.util.Map; +import me.nithanim.gw2api.v2.api.items.Details; +import me.nithanim.gw2api.v2.api.items.ItemInfo; +import me.nithanim.gw2api.v2.api.items.ItemType; + +public class ItemInfoJsonDeserializer implements JsonDeserializer { + private static final Map fields = new HashMap<>(); + + static { + Field[] fs = ItemInfo.class.getDeclaredFields(); + for(Field f : fs) { + f.setAccessible(true); + String name = toJsonName(f.getName()); + fields.put(name, f); + } + } + + private static String toJsonName(String name) { + StringBuilder sb = new StringBuilder(); + sb.append(name); + for(int i = 0; i < sb.length(); i++) { + char c = sb.charAt(i); + if(Character.isUpperCase(c)) { + sb.setCharAt(i, '_'); + sb.insert(i+1, Character.toLowerCase(c)); + } + } + return sb.toString(); + } + + + @Override + public ItemInfo deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + JsonObject root = json.getAsJsonObject(); + ItemInfo ii = new ItemInfo(); + for(Map.Entry t : root.entrySet()) { + if(!t.getKey().equals("details")) { + Field field = fields.get(t.getKey()); + if(field != null) { + Object value = context.deserialize(t.getValue(), field.getType()); + try { + field.set(ii, value); + } catch (IllegalAccessException ex) { + throw new RuntimeException("Unexpected difficulties while deserializing ItemInfo!", ex); + } + } + } + } + + ItemType type = ii.getType(); + Class detailClass = type.getDetailsClass(); + if(detailClass != null) { + Object details = context.deserialize(root.get("details"), detailClass); + try { + Field field = fields.get("details"); + field.set(ii, details); + } catch (IllegalAccessException ex) { + throw new RuntimeException("Unable to set Details in ItemInfo while deserializing!", ex); + } + } + return ii; + } +} diff --git a/src/test/java/me/nithanim/gw2api/v2/MockHelper.java b/src/test/java/me/nithanim/gw2api/v2/MockHelper.java new file mode 100644 index 0000000..ed0114f --- /dev/null +++ b/src/test/java/me/nithanim/gw2api/v2/MockHelper.java @@ -0,0 +1,27 @@ +package me.nithanim.gw2api.v2; + +import com.sun.jersey.api.client.WebResource; +import javax.ws.rs.core.MediaType; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +public class MockHelper { + public static WebResource getMockedWebResourceWithSubpath(String subpath, String jsonresult) { + WebResource superWr = mock(WebResource.class); + WebResource subWr = mock(WebResource.class); + doReturn(subWr).when(superWr).path(subpath); + + + //return builder when methods are called on WR and on the builder too (which has the same result) + //makes the order of calling accept and header insensitive + WebResource.Builder wrb = mock(WebResource.Builder.class); + doReturn(wrb).when(subWr).header(anyString(), any()); + doReturn(wrb).when(subWr).accept((MediaType) any()); + doReturn(wrb).when(wrb).header(anyString(), any()); + doReturn(wrb).when(wrb).accept((MediaType) any()); + doReturn(jsonresult).when(wrb).get(String.class); + return superWr; + } +} diff --git a/src/test/java/me/nithanim/gw2api/v2/api/account/AccountResourceTest.java b/src/test/java/me/nithanim/gw2api/v2/api/account/AccountResourceTest.java new file mode 100644 index 0000000..501e652 --- /dev/null +++ b/src/test/java/me/nithanim/gw2api/v2/api/account/AccountResourceTest.java @@ -0,0 +1,52 @@ +package me.nithanim.gw2api.v2.api.account; + +import com.sun.jersey.api.client.WebResource; +import javax.ws.rs.core.MediaType; +import me.nithanim.gw2api.v2.GuildWars2Api; +import me.nithanim.gw2api.v2.MockHelper; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; + +public class AccountResourceTest { + + private static final String API_KEY = "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAAAAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA"; + + public AccountResourceTest() { + } + + @BeforeClass + public static void setUpClass() { + } + + @AfterClass + public static void tearDownClass() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + @Test + public void testAccount() { + String apiResult = "{\"id\":\"C25B6B91-7FF2-E111-809D-78E7D1936EF0\",\"name\":\"Nithanim.5243\",\"world\":2206,\"guilds\":[\"2D811245-A33B-4169-AF9F-A69B4EB7F0FD\",\"E1A1D4B0-6710-4DC3-9D5C-0F119BC3D2F8\"],\"created\":\"2012-08-30T08:47:00Z\"}"; + WebResource wr = MockHelper.getMockedWebResourceWithSubpath("account", apiResult); + + + Account expected = GuildWars2Api.GSON.fromJson(apiResult, Account.class); + + AccountResource ar = new AccountResource(wr); + Account actual = ar.get(API_KEY); + + verify(wr.path("account").accept(MediaType.APPLICATION_JSON_TYPE)).header("Authorization", "Bearer " + API_KEY); + assertEquals(expected, actual); + } +}