Skip to content

Added doc for impl class #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "jdk",
"request": "launch",
"name": "Launch Java App"
}
]
}
60 changes: 57 additions & 3 deletions src/main/java/spotify/api/impl/AlbumApiRetrofit.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package spotify.api.impl;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import retrofit2.Call;
import retrofit2.Response;
import spotify.api.enums.HttpStatusCode;
Expand All @@ -17,24 +22,47 @@
import spotify.utils.ResponseChecker;
import spotify.utils.ValidatorUtil;

import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* Implementation of the {@link AlbumApi} interface using Retrofit to interact with the Spotify API.
* This class provides methods to fetch album details, multiple albums, and album tracks from Spotify.
*/

public class AlbumApiRetrofit implements AlbumApi {
private final Logger logger = LoggerFactory.getLogger(AlbumApiRetrofit.class);
private final String accessToken;
private final AlbumService albumService;

/**
* constructs an instance of {@link AlbumApiRetrofit} with the specified access token.
*
* @param accessToken the access token to be used for authorization
*/

public AlbumApiRetrofit(final String accessToken) {
this(accessToken, RetrofitHttpServiceFactory.getAlbumService());
}

/**
* constructs an instance of {@link AlbumApiRetrofit} with the specified access token and album service.
*
* @param accessToken the access token to be used for authorization
* @param albumService the album service to be used for making HTTP calls
*/

public AlbumApiRetrofit(final String accessToken, final AlbumService albumService) {
this.accessToken = accessToken;
this.albumService = albumService;
}

/**
* fetches the details of a single album from Spotify.
*
* @param albumId the ID of the album to fetch
* @param options additional options for the request
* @return the full details of the album
* @throws HttpRequestFailedException if the HTTP request fails
*/

@Override
public AlbumFull getAlbum(String albumId, Map<String, String> options) {
options = ValidatorUtil.optionsValueCheck(options);
Expand All @@ -58,6 +86,15 @@ public AlbumFull getAlbum(String albumId, Map<String, String> options) {
}
}

/**
* fetches the details of multiple albums from Spotify.
*
* @param listOfAlbumIds the list of album IDs to fetch
* @param options additional options for the request
* @return the full details of the albums
* @throws HttpRequestFailedException if the HTTP request fails
*/

@Override
public AlbumFullCollection getAlbums(List<String> listOfAlbumIds, Map<String, String> options) {
validateAlbumListSizeAndThrowIfExceeded(listOfAlbumIds, 20);
Expand Down Expand Up @@ -85,6 +122,15 @@ public AlbumFullCollection getAlbums(List<String> listOfAlbumIds, Map<String, St
}
}

/**
* fetches the tracks of a specific album from Spotify.
*
* @param albumId the ID of the album whose tracks are to be fetched
* @param options additional options for the request
* @return a paging object containing the album's tracks
* @throws HttpRequestFailedException if the HTTP request fails
*/

@Override
public Paging<TrackSimplified> getAlbumTracks(String albumId, Map<String, String> options) {
options = ValidatorUtil.optionsValueCheck(options);
Expand All @@ -108,6 +154,14 @@ public Paging<TrackSimplified> getAlbumTracks(String albumId, Map<String, String
}
}

/**
* Validates the size of the album list and throws an exception if the size exceeds the maximum allowed limit.
*
* @param listOfAlbumIds the list of album IDs to validate
* @param maximumAmountOfAlbumIdsAllowed the maximum allowed number of album IDs
* @throws IllegalArgumentException if the list size exceeds the maximum allowed limit
*/

private void validateAlbumListSizeAndThrowIfExceeded(List<String> listOfAlbumIds, int maximumAmountOfAlbumIdsAllowed) {
final int listSize = listOfAlbumIds.size();

Expand Down
Loading