mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-05-09 03:51:06 +03:00
Merge pull request #44 from ultrasonic/add-update-playlist
Add update playlist
This commit is contained in:
commit
4b1d6e9827
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
@ -99,4 +99,13 @@ interface SubsonicAPIDefinition {
|
||||
|
||||
@GET("deletePlaylist.view")
|
||||
fun deletePlaylist(@Query("id") id: Long): Call<SubsonicResponse>
|
||||
|
||||
@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<Long>? = null,
|
||||
@Query("songIndexToRemove") songIndexesToRemove: List<Int>? = null) : Call<SubsonicResponse>
|
||||
}
|
||||
|
@ -606,18 +606,16 @@ public class RESTMusicService implements MusicService
|
||||
}
|
||||
|
||||
@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.<Object>asList(id, name, comment, pub));
|
||||
try
|
||||
{
|
||||
new ErrorParser(context).parse(reader);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Util.close(reader);
|
||||
}
|
||||
public void updatePlaylist(String id,
|
||||
String name,
|
||||
String comment,
|
||||
boolean pub,
|
||||
Context context,
|
||||
ProgressListener progressListener) throws Exception {
|
||||
updateProgressListener(progressListener, R.string.parser_reading);
|
||||
Response<SubsonicResponse> response = subsonicAPIClient.getApi()
|
||||
.updatePlaylist(Long.valueOf(id), name, comment, pub, null, null).execute();
|
||||
checkResponseSuccessful(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user