From 8bf9399e488eb5814a8945e36e7a4df06004e7df Mon Sep 17 00:00:00 2001 From: Yahor Berdnikau Date: Sun, 3 Sep 2017 10:25:36 +0200 Subject: [PATCH 1/2] Add updatePlaylist() call. Signed-off-by: Yahor Berdnikau --- .../subsonic/SubsonicApiUpdatePlaylistTest.kt | 85 +++++++++++++++++++ .../api/subsonic/SubsonicAPIDefinition.kt | 9 ++ 2 files changed, 94 insertions(+) create mode 100644 subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiUpdatePlaylistTest.kt diff --git a/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiUpdatePlaylistTest.kt b/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiUpdatePlaylistTest.kt new file mode 100644 index 00000000..19369665 --- /dev/null +++ b/subsonic-api/src/integrationTest/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicApiUpdatePlaylistTest.kt @@ -0,0 +1,85 @@ +package org.moire.ultrasonic.api.subsonic + +import org.junit.Test + +/** + * Integration test for [SubsonicAPIClient] for updatePlaylist call. + */ +class SubsonicApiUpdatePlaylistTest : SubsonicAPIClientTest() { + @Test + fun `Should handle error response`() { + checkErrorCallParsed(mockWebServerRule) { + client.api.updatePlaylist(10).execute() + } + } + + @Test + fun `Should handle ok response`() { + mockWebServerRule.enqueueResponse("ping_ok.json") + + val response = client.api.updatePlaylist(15).execute() + + assertResponseSuccessful(response) + } + + @Test + fun `Should pass playlist id param in request`() { + val id = 5453L + + mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json", + expectedParam = "playlistId=$id") { + client.api.updatePlaylist(id = id).execute() + } + } + + @Test + fun `Should pass name param in request`() { + val name = "some-name" + + mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json", + expectedParam = "name=$name") { + client.api.updatePlaylist(22, name = name).execute() + } + } + + @Test + fun `Should pass comment param in request`() { + val comment = "some-unusual-comment" + + mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json", + expectedParam = "comment=$comment") { + client.api.updatePlaylist(42, comment = comment).execute() + } + } + + @Test + fun `Should pass public param in request`() { + val public = true + + mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json", + expectedParam = "public=$public") { + client.api.updatePlaylist(53, public = public).execute() + } + } + + @Test + fun `Should pass song ids to update in request`() { + val songIds = listOf(45L, 81L) + + mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json", + expectedParam = "songIdToAdd=${songIds[0]}&songIdToAdd=${songIds[1]}") { + client.api.updatePlaylist(25, songIdsToAdd = songIds).execute() + } + } + + @Test + fun `Should pass song indexes to remove in request`() { + val songIndexesToRemove = listOf(129, 1) + + mockWebServerRule.assertRequestParam(responseResourceName = "ping_ok.json", + expectedParam = "songIndexToRemove=${songIndexesToRemove[0]}&" + + "songIndexToRemove=${songIndexesToRemove[1]}") { + client.api.updatePlaylist(49, songIndexesToRemove = songIndexesToRemove).execute() + } + } +} diff --git a/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIDefinition.kt b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIDefinition.kt index 8bcba487..322e0a3f 100644 --- a/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIDefinition.kt +++ b/subsonic-api/src/main/kotlin/org/moire/ultrasonic/api/subsonic/SubsonicAPIDefinition.kt @@ -99,4 +99,13 @@ interface SubsonicAPIDefinition { @GET("deletePlaylist.view") fun deletePlaylist(@Query("id") id: Long): Call + + @GET("updatePlaylist.view") + fun updatePlaylist( + @Query("playlistId") id: Long, + @Query("name") name: String? = null, + @Query("comment") comment: String? = null, + @Query("public") public: Boolean? = null, + @Query("songIdToAdd") songIdsToAdd: List? = null, + @Query("songIndexToRemove") songIndexesToRemove: List? = null) : Call } From 0e8c853dbf6fc5e407a76a2698a9f455fd5f049a Mon Sep 17 00:00:00 2001 From: Yahor Berdnikau Date: Sun, 3 Sep 2017 10:35:04 +0200 Subject: [PATCH 2/2] Use new subsonic api updatePlaylist call. Signed-off-by: Yahor Berdnikau --- .../ultrasonic/service/RESTMusicService.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/ultrasonic/src/main/java/org/moire/ultrasonic/service/RESTMusicService.java b/ultrasonic/src/main/java/org/moire/ultrasonic/service/RESTMusicService.java index 823e588e..8265695e 100644 --- a/ultrasonic/src/main/java/org/moire/ultrasonic/service/RESTMusicService.java +++ b/ultrasonic/src/main/java/org/moire/ultrasonic/service/RESTMusicService.java @@ -605,20 +605,18 @@ public class RESTMusicService implements MusicService checkResponseSuccessful(response); } - @Override - public void updatePlaylist(String id, String name, String comment, boolean pub, Context context, ProgressListener progressListener) throws Exception - { - checkServerVersion(context, "1.8", "Updating playlists is not supported."); - Reader reader = getReader(context, progressListener, "updatePlaylist", null, asList("playlistId", "name", "comment", "public"), Arrays.asList(id, name, comment, pub)); - try - { - new ErrorParser(context).parse(reader); - } - finally - { - Util.close(reader); - } - } + @Override + public void updatePlaylist(String id, + String name, + String comment, + boolean pub, + Context context, + ProgressListener progressListener) throws Exception { + updateProgressListener(progressListener, R.string.parser_reading); + Response response = subsonicAPIClient.getApi() + .updatePlaylist(Long.valueOf(id), name, comment, pub, null, null).execute(); + checkResponseSuccessful(response); + } @Override public Lyrics getLyrics(String artist, String title, Context context, ProgressListener progressListener) throws Exception