com.lajospolya.spotifyapiwrapper.request.GetMePlayerRecentlyPlayed Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spotify-api-wrapper Show documentation
Show all versions of spotify-api-wrapper Show documentation
This project wraps the Spotify public API in order to allow users to intuitively use it
package com.lajospolya.spotifyapiwrapper.request;
import com.lajospolya.spotifyapiwrapper.response.PagingCursor;
import com.lajospolya.spotifyapiwrapper.response.PlayHistory;
import java.net.http.HttpRequest;
/**
* @author Lajos Polya
*
* Represents the endpoint at GET https://api.spotify.com/v1/me/player/recently-played as descrbibed at
* https://developer.spotify.com/documentation/web-api/reference-beta/
*/
public class GetMePlayerRecentlyPlayed extends AbstractSpotifyRequest>
{
private static final String REQUEST_URI_STRING = SPOTIFY_V1_API_URI + "me/player/recently-played";
private GetMePlayerRecentlyPlayed(HttpRequest.Builder requestBuilder)
{
super(requestBuilder);
}
public static class Builder extends AbstractBuilder
{
private Integer limit;
private Long after;
private Long before;
public Builder() { }
@Override
public GetMePlayerRecentlyPlayed build()
{
SpotifyRequestBuilder spotifyRequestBuilder = new SpotifyRequestBuilder(REQUEST_URI_STRING);
addOptionalQueryParams(spotifyRequestBuilder);
return new GetMePlayerRecentlyPlayed(spotifyRequestBuilder.createGetRequests());
}
private void addOptionalQueryParams(SpotifyRequestBuilder requestUriBuilder)
{
if(limit != null)
{
requestUriBuilder.queryParam(LIMIT_QUERY_PARAM, limit);
}
if(after != null)
{
requestUriBuilder.queryParam(AFTER_QUERY_PARAM, after);
}
if(before != null)
{
requestUriBuilder.queryParam(BEFORE_QUERY_PARAM, before);
}
}
public Builder limit(Integer limit)
{
spotifyRequestParamValidationService.validateLimit50(limit);
this.limit = limit;
return this;
}
public Builder after(Long after)
{
if(after != null && before != null)
{
throw new IllegalArgumentException("after and before cannot both be set.");
}
this.after = after;
return this;
}
public Builder before(Long before)
{
if(before != null && after != null)
{
throw new IllegalArgumentException("after and before cannot both be set.");
}
this.before = before;
return this;
}
}
}