From c5d7349ec2880b575221aebdb35558fe757ea797 Mon Sep 17 00:00:00 2001 From: CappielloAntonio Date: Sat, 24 Jul 2021 14:48:33 +0200 Subject: [PATCH] Implemented getters for url and params --- .../play/subsonic/Subsonic.java | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/Subsonic.java b/app/src/main/java/com/cappielloantonio/play/subsonic/Subsonic.java index 46b3d03c..a1286c10 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/Subsonic.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/Subsonic.java @@ -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> 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 getParams() { + Map 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; } }