Skip to content

Commit

Permalink
Add character pictures (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
Katsute authored May 26, 2023
1 parent 3d5ce75 commit 0426283
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 6 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 3.3.0

### New Features

* Add character pictures [#391](https://github.com/KatsuteDev/Mal4J/pull/391) ([@Katsute](https://github.com/Katsute))

This is an undocumented feature, you must use `MyAnimeList.enableExperimentalFeature(ExperimentalFeature.CHARACTERS)` to enable it.

**Full Changelog**: [`3.2.0...3.3.0`](https://github.com/KatsuteDev/Mal4J/compare/3.2.0...3.3.0)

## 3.2.0

### New Features
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.katsute</groupId>
<artifactId>mal4j</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>

<profiles>
<profile>
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/dev/katsute/mal4j/Fields.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* The fields class holds all possible fields for a request. Usable in any methods that ask for fields.
*
* @since 1.1.0
* @version 3.2.0
* @version 3.3.0
* @author Katsute
*/
public abstract class Fields {
Expand Down Expand Up @@ -560,7 +560,7 @@ public static String serialization(final String... fields){
*
* @see #character
* @since 3.1.0
* @version 3.1.0
* @version 3.3.0
* @author Katsute
*/
public static class Character {
Expand All @@ -576,6 +576,7 @@ private Character(){}
public static final String alternative_name = "alternative_name";

public static final String main_picture = "main_picture";
public static final String pictures = "pictures";

public static final String biography = "biography";

Expand All @@ -596,6 +597,7 @@ private Character(){}
Character.last_name,
Character.alternative_name,
Character.main_picture,
Character.pictures,
Character.biography,
Character.animeography
);
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/dev/katsute/mal4j/MyAnimeListSchema_Character.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static Character asCharacter(final MyAnimeList mal, final JsonObject schema){
private String lastName;
private String alternativeNames;
private Picture mainPicture;
private Picture[] pictures;
private String biography;
private Animeography[] animeography;

Expand All @@ -59,6 +60,7 @@ private void populate(final JsonObject schema){
lastName = schema.getString("last_name");
alternativeNames = schema.getString("alternative_name");
mainPicture = MyAnimeListSchema_Common.asPicture(mal, schema.getJsonObject("main_picture"));
pictures = adaptList(schema.getJsonArray("pictures"), s -> MyAnimeListSchema_Common.asPicture(mal, s), Picture.class);
biography = schema.getString("biography");

animeography = adaptList(schema.getJsonArray("animeography"), s -> asAnimeography(mal, s), Animeography.class);
Expand Down Expand Up @@ -99,6 +101,13 @@ public final Picture getMainPicture(){
return mainPicture;
}

@Override
public final Picture[] getPictures(){
if(pictures == null && draft)
populate();
return pictures != null ? Arrays.copyOf(pictures, pictures.length) : null;
}

@Override
public final String getBiography(){
if(biography == null && draft)
Expand All @@ -122,9 +131,10 @@ public final String toString(){
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", alternativeNames='" + alternativeNames + '\'' +
", mainPicture=" + mainPicture + '\'' +
", mainPicture=" + mainPicture +
", pictures=" + Arrays.toString(pictures) +
", biography='" + biography + '\'' +
", animeography'" + Arrays.toString(animeography) + '\'' +
", animeography=" + Arrays.toString(animeography) +
'}';
}

Expand Down
14 changes: 13 additions & 1 deletion src/main/java/dev/katsute/mal4j/character/Character.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* @see dev.katsute.mal4j.MyAnimeList#getCharacter(long)
* @see dev.katsute.mal4j.MyAnimeList#getCharacter(long, String...)
* @since 3.1.0
* @version 3.1.0
* @version 3.3.0
* @author Katsute
*/
public abstract class Character implements ID {
Expand Down Expand Up @@ -72,10 +72,22 @@ public abstract class Character implements ID {
* @return main picture
*
* @see Picture
* @see #getPictures()
* @since 3.1.0
*/
public abstract Picture getMainPicture();

/**
* Returns the pictures for the character.
*
* @return pictures
*
* @see Picture
* @see #getMainPicture()
* @since 3.3.0
*/
public abstract Picture[] getPictures();

/**
* Returns the biography.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ private static Stream<Arguments> characterProvider(){
.add("MainPicture", Character::getMainPicture)
.add("MainPicture#MediumURL", character -> character.getMainPicture().getMediumURL())
// .add("MainPicture#LargeURL", character -> character.getMainPicture().getLargeURL())
.add("Pictures", Character::getPictures)
.add("Pictures[0]", character -> character.getPictures()[0])
.add("Pictures#MediumURL", character -> character.getPictures()[0].getMediumURL())
// .add("Pictures#LargeURL", character -> character.getPictures()[0].getLargeURL())
.add("Biography", Character::getBiography)
.add("Animeography", Character::getAnimeography)
.add("Animeography[0]", character -> character.getAnimeography()[0])
Expand Down

0 comments on commit 0426283

Please sign in to comment.