All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lajospolya.spotifyapiwrapper.request.GetUsersTop Maven / Gradle / Ivy

Go to download

This project wraps the Spotify public API in order to allow users to intuitively use it

There is a newer version: 3.0.RELEASE
Show newest version
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;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy