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; package com.cappielloantonio.play.subsonic;
import com.cappielloantonio.play.subsonic.api.system.SystemClient;
import com.cappielloantonio.play.subsonic.base.Version; import com.cappielloantonio.play.subsonic.base.Version;
import java.util.List; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class Subsonic { public class Subsonic {
private final SubsonicPreferences preferences; 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 static final Version API_MAX_VERSION = Version.of("1.15.0");
private Version apiVersion = API_MAX_VERSION; private Version apiVersion = API_MAX_VERSION;
private SystemClient systemClient;
public Subsonic(SubsonicPreferences preferences) { public Subsonic(SubsonicPreferences preferences) {
this.preferences = preferences; this.preferences = preferences;
} }
@ -21,31 +23,30 @@ public class Subsonic {
return preferences; return preferences;
} }
public static Version getApiMinVersion() {
return API_MIN_VERSION;
}
public static Version getApiMaxVersion() {
return API_MAX_VERSION;
}
public Version getApiVersion() { public Version getApiVersion() {
return apiVersion; return apiVersion;
} }
public String createUrl(String path, Map<String, List<String>> params) { public SystemClient getSystemClient() {
final StringBuilder sb = new StringBuilder(preferences.getServerUrl()); if (systemClient == null) {
systemClient = new SystemClient(this);
}
return systemClient;
}
sb.append("/rest/").append(path); public String getUrl() {
sb.append("?u=").append(preferences.getUsername()); return preferences.getServerUrl() + "/rest/";
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");
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;
} }
} }