mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 09:33:33 +00:00
Implemented getters for url and params
This commit is contained in:
parent
27cc3b8570
commit
c5d7349ec2
1 changed files with 22 additions and 21 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue