Implemented getters for url and params

This commit is contained in:
CappielloAntonio 2021-07-24 14:48:33 +02:00
parent 27cc3b8570
commit c5d7349ec2

View file

@ -1,18 +1,20 @@
package com.cappielloantonio.play.subsonic;
import com.cappielloantonio.play.subsonic.api.system.SystemClient;
import com.cappielloantonio.play.subsonic.base.Version;
import java.util.List;
import java.util.HashMap;
import java.util.Map;
public class Subsonic {
private final SubsonicPreferences preferences;
private static final Version API_MIN_VERSION = Version.of("1.13.0");
private static final Version API_MAX_VERSION = Version.of("1.15.0");
private Version apiVersion = API_MAX_VERSION;
private SystemClient systemClient;
public Subsonic(SubsonicPreferences preferences) {
this.preferences = preferences;
}
@ -21,31 +23,30 @@ public class Subsonic {
return preferences;
}
public static Version getApiMinVersion() {
return API_MIN_VERSION;
}
public static Version getApiMaxVersion() {
return API_MAX_VERSION;
}
public Version getApiVersion() {
return apiVersion;
}
public String createUrl(String path, Map<String, List<String>> params) {
final StringBuilder sb = new StringBuilder(preferences.getServerUrl());
public SystemClient getSystemClient() {
if (systemClient == null) {
systemClient = new SystemClient(this);
}
return systemClient;
}
sb.append("/rest/").append(path);
sb.append("?u=").append(preferences.getUsername());
sb.append("&s=").append(preferences.getAuthentication().getSalt());
sb.append("&t=").append(preferences.getAuthentication().getToken());
sb.append("&v=").append(getApiVersion().getVersionString());
sb.append("&c=").append(preferences.getClientName());
sb.append("&f=").append("xml");
public String getUrl() {
return preferences.getServerUrl() + "/rest/";
}
params.keySet().forEach(k -> params.get(k).forEach(v -> sb.append("&").append(k).append("=").append(v)));
public Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("u", preferences.getUsername());
params.put("s", preferences.getAuthentication().getSalt());
params.put("t", preferences.getAuthentication().getToken());
params.put("v", getApiVersion().getVersionString());
params.put("c", preferences.getClientName());
params.put("f", "json");
return sb.toString().replace("//rest", "/rest");
return params;
}
}