diff --git a/src/io/github/sammers/pla/blizzard/BlizzardAPI.java b/src/io/github/sammers/pla/blizzard/BlizzardAPI.java index 987c195e..f5b292c1 100644 --- a/src/io/github/sammers/pla/blizzard/BlizzardAPI.java +++ b/src/io/github/sammers/pla/blizzard/BlizzardAPI.java @@ -119,7 +119,7 @@ public Maybe character(String region, String realm, String name ).toList() ).toList(); Maybe achievementsRx = maybeResponse(realNamespace, absoluteURI + "/achievements"); - Maybe mediaRx = maybeResponse(realNamespace, absoluteURI + "/character-media"); + Maybe mediaRx = maybeResponse(realNamespace, absoluteURI + "/character-media").onErrorReturnItem(new JsonObject()); Maybe petsRx = maybeResponse(realNamespace, absoluteURI + "/collections/pets"); Maybe specsRx = maybeResponse(realNamespace, absoluteURI + "/specializations"); return Single.zip( diff --git a/src/io/github/sammers/pla/blizzard/WowAPICharacter.java b/src/io/github/sammers/pla/blizzard/WowAPICharacter.java index 7d88e12f..dca0c0f4 100644 --- a/src/io/github/sammers/pla/blizzard/WowAPICharacter.java +++ b/src/io/github/sammers/pla/blizzard/WowAPICharacter.java @@ -165,17 +165,17 @@ public record WowAPICharacter(long id, } public static WowAPICharacter parse( - Optional previous, - Refs refs, - Optional cutoffs, - JsonObject entries, - JsonObject pvpSummary, - List brackets, - JsonObject achievements, - JsonObject characterMedia, - JsonObject specs, - JsonObject pets, - String region) { + Optional previous, + Refs refs, + Optional cutoffs, + JsonObject entries, + JsonObject pvpSummary, + List brackets, + JsonObject achievements, + JsonObject characterMedia, + JsonObject specs, + JsonObject pets, + String region) { String activeSpec = Optional.of(entries.getJsonObject("active_spec")).map(obj -> obj.getString("name")).orElse(""); String talents = specs.getJsonArray("specializations").stream() .map(s -> (JsonObject) s) @@ -218,7 +218,9 @@ public static WowAPICharacter parse( } return PvpBracket.parse(wowApiBracket, prevBracket, rank, Optional.of(cutoffByBracketType).orElse(-1L), thisSsnData); }).toList(); - CharacterMedia media = CharacterMedia.parse(characterMedia); + CharacterMedia media = characterMedia.getMap().size() == 0 ? + previous.map(WowAPICharacter::media).orElse(CharacterMedia.parse(characterMedia)) + : CharacterMedia.parse(characterMedia); Long lastUpdatedUTCms = Instant.now().toEpochMilli(); Achievements parsedAchievements = Achievements.parse(achievements); return new WowAPICharacter( @@ -291,8 +293,8 @@ public WowAPICharacter updatePvpBracketData(CharAndDiff diff, BracketType bracke PvpBracket res; if (BracketType.fromType(pvpBracket.bracketType()).equals(bracket) && (bracket.equals(BracketType.TWO_V_TWO) - || bracket.equals(BracketType.THREE_V_THREE) - || bracket.equals(BracketType.RBG))) { + || bracket.equals(BracketType.THREE_V_THREE) + || bracket.equals(BracketType.RBG))) { log.debug("Updating bracket " + pvpBracket.bracketType() + " with diff " + diff); res = new PvpBracket( pvpBracket.bracketType(), @@ -354,24 +356,24 @@ public int hashCode() { @Override public JsonObject toJson() { return new JsonObject() - .put("id", id) - .put("hidden", hidden) - .put("name", name) - .put("realm", realm) - .put("gender", gender) - .put("fraction", fraction) - .put("race", race) - .put("activeSpec", activeSpec) - .put("level", level) - .put("class", clazz) - .put("itemLevel", itemLevel) - .put("region", region) - .put("lastUpdatedUTCms", lastUpdatedUTCms) - .put("brackets", new JsonArray(brackets.stream().map(PvpBracket::toJson).toList())) - .put("achievements", achievements.toJson()) - .put("petHash", petHash) - .put("media", media.toJson()) - .put("talents", talents); + .put("id", id) + .put("hidden", hidden) + .put("name", name) + .put("realm", realm) + .put("gender", gender) + .put("fraction", fraction) + .put("race", race) + .put("activeSpec", activeSpec) + .put("level", level) + .put("class", clazz) + .put("itemLevel", itemLevel) + .put("region", region) + .put("lastUpdatedUTCms", lastUpdatedUTCms) + .put("brackets", new JsonArray(brackets.stream().map(PvpBracket::toJson).toList())) + .put("achievements", achievements.toJson()) + .put("petHash", petHash) + .put("media", media.toJson()) + .put("talents", talents); } }