de.sonallux.spotify.api.authorization.AuthorizationUrlBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spotify-web-api-java Show documentation
Show all versions of spotify-web-api-java Show documentation
A Java wrapper for Spotify's Web API
The newest version!
package de.sonallux.spotify.api.authorization;
import okhttp3.HttpUrl;
import java.util.Arrays;
import java.util.stream.Collectors;
public class AuthorizationUrlBuilder {
protected final HttpUrl.Builder builder;
public AuthorizationUrlBuilder(String clientId, String redirectUri, String responseType) {
builder = new HttpUrl.Builder()
.scheme("https")
.host("accounts.spotify.com")
.addPathSegment("authorize")
.addQueryParameter("client_id", clientId)
.addQueryParameter("response_type", responseType)
.addQueryParameter("redirect_uri", redirectUri);
}
public AuthorizationUrlBuilder state(String state) {
builder.addQueryParameter("state", state);
return this;
}
public AuthorizationUrlBuilder scopes(Scope... scopes) {
if (scopes.length == 0) {
return this;
}
var scopeString = Arrays.stream(scopes)
.map(Scope::getName)
.collect(Collectors.joining(" "));
builder.addQueryParameter("scope", scopeString);
return this;
}
public AuthorizationUrlBuilder showDialog(boolean showDialog) {
builder.addQueryParameter("show_dialog", String.valueOf(showDialog));
return this;
}
public HttpUrl build() {
return builder.build();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy