Skip to content
Closed
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
362 changes: 15 additions & 347 deletions src/main/java/se/michaelthelin/spotify/SpotifyApi.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.neovisionaries.i18n.CountryCode;
import se.michaelthelin.spotify.enums.AlbumType;
import se.michaelthelin.spotify.enums.ModelObjectType;
import se.michaelthelin.spotify.enums.ReleaseDatePrecision;
Expand All @@ -22,12 +21,8 @@ public class Album extends AbstractModelObject {
private final AlbumType albumType;
/** The artists who performed the album. */
private final ArtistSimplified[] artists;
/** The markets in which the album is available. */
private final CountryCode[] availableMarkets;
/** The copyright statements of the album. */
private final Copyright[] copyrights;
/** Known external IDs for the album. */
private final ExternalId externalIds;
/** Known external URLs for this album. */
private final ExternalUrl externalUrls;
/** A list of the genres the album is associated with. */
Expand All @@ -38,12 +33,8 @@ public class Album extends AbstractModelObject {
private final String id;
/** The cover art for the album in various sizes. */
private final Image[] images;
/** The label for the album. */
private final String label;
/** The name of the album. */
private final String name;
/** The popularity of the album (0-100). */
private final Integer popularity;
/** The date the album was first released. */
private final String releaseDate;
/** The precision with which release_date value is known. */
Expand All @@ -60,17 +51,13 @@ private Album(final Builder builder) {

this.albumType = builder.albumType;
this.artists = builder.artists;
this.availableMarkets = builder.availableMarkets;
this.copyrights = builder.copyrights;
this.externalIds = builder.externalIds;
this.externalUrls = builder.externalUrls;
this.genres = builder.genres;
this.href = builder.href;
this.id = builder.id;
this.images = builder.images;
this.label = builder.label;
this.name = builder.name;
this.popularity = builder.popularity;
this.releaseDate = builder.releaseDate;
this.releaseDatePrecision = builder.releaseDatePrecision;
this.tracks = builder.tracks;
Expand All @@ -96,16 +83,6 @@ public ArtistSimplified[] getArtists() {
return artists;
}

/**
* Get the country codes of all countries, in which the album is available.
*
* @return An array of <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">ISO 3166-1 alpha-2 country
* codes</a>.
*/
public CountryCode[] getAvailableMarkets() {
return availableMarkets;
}

/**
* Get all copyright texts of the album.
*
Expand All @@ -115,16 +92,6 @@ public Copyright[] getCopyrights() {
return copyrights;
}

/**
* Get the external IDs of the album. <br>
* Example: upc -&gt; "Universal Product Code".
*
* @return An array of {@link ExternalId} objects.
*/
public ExternalId getExternalIds() {
return externalIds;
}

/**
* Get the external URLs of the album. <br>
* Example: <a href="https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids">Spotify-URL</a>
Expand Down Expand Up @@ -172,15 +139,6 @@ public Image[] getImages() {
return images;
}

/**
* Get the label for the album.
*
* @return The label for the album.
*/
public String getLabel() {
return label;
}

/**
* Get the name of the album.
*
Expand All @@ -190,16 +148,6 @@ public String getName() {
return name;
}

/**
* Get the popularity of the album in a range between 0 and 100. (higher = more popular) <br>
* The popularity of the album is based on the popularity of its individual tracks.
*
* @return The popularity of the album.
*/
public Integer getPopularity() {
return popularity;
}

/**
* Get the release date of the album with the highest precision available.
*
Expand Down Expand Up @@ -248,10 +196,10 @@ public String getUri() {
@Override
public String toString() {
return "Album(artists=" + Arrays.toString(artists) + ", name=" + name + ", albumType=" + albumType
+ ", availableMarkets=" + Arrays.toString(availableMarkets) + ", copyrights=" + Arrays.toString(copyrights)
+ ", externalIds=" + externalIds + ", externalUrls=" + externalUrls + ", genres=" + Arrays.toString(genres)
+ ", href=" + href + ", id=" + id + ", images=" + Arrays.toString(images) + ", label=" + label + ", popularity="
+ popularity + ", releaseDate=" + releaseDate + ", releaseDatePrecision=" + releaseDatePrecision + ", tracks="
+ ", copyrights=" + Arrays.toString(copyrights)
+ ", externalUrls=" + externalUrls + ", genres=" + Arrays.toString(genres)
+ ", href=" + href + ", id=" + id + ", images=" + Arrays.toString(images)
+ ", releaseDate=" + releaseDate + ", releaseDatePrecision=" + releaseDatePrecision + ", tracks="
+ tracks + ", type=" + type + ", uri=" + uri + ")";
}

Expand All @@ -266,17 +214,13 @@ public Builder builder() {
public static final class Builder extends AbstractModelObject.Builder {
private AlbumType albumType;
private ArtistSimplified[] artists;
private CountryCode[] availableMarkets;
private Copyright[] copyrights;
private ExternalId externalIds;
private ExternalUrl externalUrls;
private String[] genres;
private String href;
private String id;
private Image[] images;
private String label;
private String name;
private Integer popularity;
private String releaseDate;
private ReleaseDatePrecision releaseDatePrecision;
private Paging<TrackSimplified> tracks;
Expand Down Expand Up @@ -312,18 +256,6 @@ public Builder setArtists(ArtistSimplified... artists) {
return this;
}

/**
* Set the available markets of the album to be built.
*
* @param availableMarkets <a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2">
* ISO 3166-1 alpha-2 country codes</a>.
* @return A {@link Album.Builder}.
*/
public Builder setAvailableMarkets(CountryCode... availableMarkets) {
this.availableMarkets = availableMarkets;
return this;
}

/**
* Set the copyrights of the album to be built.
*
Expand All @@ -335,17 +267,6 @@ public Builder setCopyrights(Copyright... copyrights) {
return this;
}

/**
* Set the external IDs of the album to be built.
*
* @param externalIds {@link ExternalId} object.
* @return A {@link Album.Builder}.
*/
public Builder setExternalIds(ExternalId externalIds) {
this.externalIds = externalIds;
return this;
}

/**
* Set external URLs of the album to be built.
*
Expand Down Expand Up @@ -401,17 +322,6 @@ public Builder setImages(Image... images) {
return this;
}

/**
* Set the label of the album to be built.
*
* @param label The album label.
* @return A {@link Album.Builder}.
*/
public Builder setLabel(String label) {
this.label = label;
return this;
}

/**
* Set the name of the album to be built.
*
Expand All @@ -423,17 +333,6 @@ public Builder setName(String name) {
return this;
}

/**
* Set the popularity of the album to be built.
*
* @param popularity The popularity of the album between 0 and 100.
* @return A {@link Album.Builder}.
*/
public Builder setPopularity(Integer popularity) {
this.popularity = popularity;
return this;
}

/**
* Set the release date of the album to be built.
*
Expand Down Expand Up @@ -524,21 +423,11 @@ public Album createModelObject(JsonObject jsonObject) {
? new ArtistSimplified.JsonUtil().createModelObjectArray(
jsonObject.getAsJsonArray("artists"))
: null)
.setAvailableMarkets(
hasAndNotNull(jsonObject, "available_markets")
? new Gson().fromJson(
jsonObject.getAsJsonArray("available_markets"), CountryCode[].class)
: null)
.setCopyrights(
hasAndNotNull(jsonObject, "copyrights")
? new Copyright.JsonUtil().createModelObjectArray(
jsonObject.getAsJsonArray("copyrights"))
: null)
.setExternalIds(
hasAndNotNull(jsonObject, "external_ids")
? new ExternalId.JsonUtil().createModelObject(
jsonObject.getAsJsonObject("external_ids"))
: null)
.setExternalUrls(
hasAndNotNull(jsonObject, "external_urls")
? new ExternalUrl.JsonUtil().createModelObject(
Expand All @@ -562,18 +451,10 @@ public Album createModelObject(JsonObject jsonObject) {
? new Image.JsonUtil().createModelObjectArray(
jsonObject.getAsJsonArray("images"))
: null)
.setLabel(
hasAndNotNull(jsonObject, "label")
? jsonObject.get("label").getAsString()
: null)
.setName(
hasAndNotNull(jsonObject, "name")
? jsonObject.get("name").getAsString()
: null)
.setPopularity(
hasAndNotNull(jsonObject, "popularity")
? jsonObject.get("popularity").getAsInt()
: null)
.setReleaseDate(
hasAndNotNull(jsonObject, "release_date")
? jsonObject.get("release_date").getAsString()
Expand Down Expand Up @@ -610,12 +491,12 @@ public boolean equals(Object o) {
return false;
}
Album album = (Album) o;
return Objects.equals(id, album.id) && Objects.equals(label, album.label) && Objects.equals(name, album.name) &&
return Objects.equals(id, album.id) && Objects.equals(name, album.name) &&
Objects.equals(releaseDate, album.releaseDate) && Objects.equals(uri, album.uri);
}

@Override
public int hashCode() {
return Objects.hash(id, label, name, releaseDate, uri);
return Objects.hash(id, name, releaseDate, uri);
}
}
Loading
Loading