com.lajospolya.spotifyapiwrapper.request.GetUsersTop 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.enumeration.TimeRange;
import com.lajospolya.spotifyapiwrapper.enumeration.UsersTopType;
abstract class GetUsersTop extends AbstractSpotifyRequest
{
private static final String REQUEST_URI_STRING = SPOTIFY_V1_API_URI + "me/top/{type}";
GetUsersTop(SpotifyRequestBuilder requestBuilder)
{
super(requestBuilder);
}
abstract static class Builder extends AbstractBuilder
{
private Integer limit;
private Integer offset;
private TimeRange timeRange;
Builder() { }
SpotifyRequestBuilder build(UsersTopType type)
{
SpotifyRequestBuilder spotifyRequestBuilder = new SpotifyRequestBuilder(REQUEST_URI_STRING, type.getName());
addOptionalQueryParams(spotifyRequestBuilder);
return spotifyRequestBuilder.GET();
}
private void addOptionalQueryParams(SpotifyRequestBuilder requestUriBuilder)
{
if(limit != null)
{
requestUriBuilder.queryParam(LIMIT_QUERY_PARAM, limit);
}
if(offset != null)
{
requestUriBuilder.queryParam(OFFSET_QUERY_PARAM, offset);
}
if(timeRange != null)
{
requestUriBuilder.queryParam(TIME_RANGE_QUERY_PARAM, timeRange.getName());
}
}
Builder limit(Integer limit)
{
spotifyRequestParamValidationService.validateLimit50(limit);
this.limit = limit;
return this;
}
Builder offset(Integer offset)
{
spotifyRequestParamValidationService.validateOffset(offset);
this.offset = offset;
return this;
}
Builder timeRange(TimeRange timeRange)
{
this.timeRange = timeRange;
return this;
}
}
}